1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can I auto fill pages? New to PHP :S

Discussion in 'PHP' started by busman3000, Jul 9, 2008.

  1. #1
    Hi.
    Im new to PHP and know very little, and all I want to know if it is possible to do the following (an example).

    I have a list of computer screens names only.
    I want to place the names of the screens in the exact same places ( 4 places in total ) on one page each.

    Is this possible?
     
    busman3000, Jul 9, 2008 IP
  2. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Lets see.. possible if you store it on a database then query the server yea it is

    Although the explanation is still vague =/ elaborate more please
     
    Mozzart, Jul 9, 2008 IP
    busman3000 likes this.
  3. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Eh, I know very little about databases. Ill try to elaborate.

    Im creating a website where I need to have the same phrase in a page multiple times. I have a list of theses phrases.
     
    busman3000, Jul 9, 2008 IP
  4. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, you can always go with arrays and do a foreach and echo them.

    example:

    
    $myphrase = array("I'm so cool",
    "Dunkin Botex",
    "Yay, pizza");
    
    foreach ($myphrase as $k => $v) {
    echo $v."<br />";
    }
    
    PHP:
    That should work
     
    Mozzart, Jul 9, 2008 IP
  5. o_rly

    o_rly Guest

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you know how to get it from the db (there are different ways, depending on how you are set up), put it in a variable, like $phrase

    then, in your html, just put
    <?php echo $phrase?>
    Code (markup):
    wherever you want it to appear. This is assuming you want the same exact phrase in different places on the page.
     
    o_rly, Jul 9, 2008 IP
  6. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks!
    Can you show me what I would put in the actual page? :) I need an example, all I know how to do in PHP is includes :D
     
    busman3000, Jul 9, 2008 IP
  7. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    So Would the part "$phrase?" be different for each page?
     
    busman3000, Jul 9, 2008 IP
  8. o_rly

    o_rly Guest

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    no, it would be the same. If you want different ones, look at the example above mine.
     
    o_rly, Jul 9, 2008 IP
    busman3000 likes this.
  9. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That depends on how much you know in using php. if you do the array all you have to do is

    echo $myphrase[0];
    echo $myphrase[1];

    (p.s you can make it random too)
     
    Mozzart, Jul 9, 2008 IP
  10. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I want to create multiple pages each with different content(names are the only difference ), so would this work fine for me?
     
    busman3000, Jul 9, 2008 IP
  11. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    You know you should just post an example of a site that matches what you want because I'm having a little trouble defining what you want exactly =/
     
    Mozzart, Jul 9, 2008 IP
  12. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Ok.
    The computer screens was an example. The website is www.myhighschool.co.uk.
    I want to auto fill the school names.
     
    busman3000, Jul 9, 2008 IP
  13. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    You mean http://www.myhighschool.co.uk/high-school.php ?

    Listing the schools?
     
    Mozzart, Jul 9, 2008 IP
  14. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    busman3000, Jul 9, 2008 IP
  15. o_rly

    o_rly Guest

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #15
    You will want to make a query to get the whole record from the db - School name, address, comments, etc. and store the record in an array (or object) the example link you gave would have already done something like this, so if you have access to it, look at the code.

    if an array, your data would be like :

    $record[0] //school id
    $record[1] //school name
    $record[2] //comments

    each element would be a different field for that record in the db.

    so then , all you would need to do would be to echo $record[1] wherever you want the school name to appear in the html.
     
    o_rly, Jul 9, 2008 IP
  16. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #16
    So If i only wanted to include the name, would i do it like this?

    $record[0] //Abraham Moss High School
    $record[1] //Burnage High School
    $record[2] //Cedar Mount High School

    And then echo $record[0] on the Abraham Moss High School page.
    And then echo $record[1] on the Burnage high school page?
    or did I just over complicate it
     
    busman3000, Jul 9, 2008 IP
  17. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I think you are over complicating it, it's fairly easy, read a bit more, if you still don't understand it take a break and when you are ready get back on it :)
     
    Mozzart, Jul 9, 2008 IP
  18. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Just to let you know, I know next to nothing about php :D
     
    busman3000, Jul 9, 2008 IP
  19. o_rly

    o_rly Guest

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #19
    The html is just the template; each html page would contain

    $record[0] //school id
    $record[1] //school name
    $record[2] //comments, etc.

    if you think of the data as a spreadsheet, it would be more like:

    $record[0] //school id   $record[1] //school name        $record[2] //comments
    1                               Abraham Lincoln HS                good school
    2                               Burnage HS                           old school
    Code (markup):

    everything in the row is a part of $record (which will only hold one row at a time) that's why you have to reference each part (db field) in the square brackets[]
     
    o_rly, Jul 9, 2008 IP
  20. busman3000

    busman3000 Peon

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Do you think it would be faster to just copy and paste plain html like I am already doing?
     
    busman3000, Jul 9, 2008 IP