SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 51
  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small help on few things

    Hi,
    I have just begun rereading the book "Build your own database driven website using PHP and MySQL", after giving up first time round due to being so confused. I am a 17 year old student wishing to redesign my current website on the subject of a themepark in the UK to make it compete more in the group of sites on the same subject. I am understanding parts of the book and not others. Could you please answer some of the following questions in extremely simple and step by step format:

    What does $_SERVER['PHP_SELF'] do and mean?

    What does $_POST do and mean?

    What does $_GET do and mean?

    and what is "isset"?


    I will anticipate your replies!


    Thanks

    Neil

  2. #2
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i variable PHP_SELF is name of the running PHP script

    In arrays _POST and _GET are stored data sent to the PHP script from another page (usually form)

    And isset is function, which tells you if the variable is initialized. It returns false if the var dos not exist and true if it exists

  3. #3
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    few more quick questions. is the php self variable basically the name of the page s if the page was downloads.php then php_self would equal downloads.php?

    Thanks for your extremeley quick reply. I will continue reading and carry this topic on if more help is needed!

    Thanks

    Neil
    Last edited by rctneil; Apr 5, 2006 at 12:32. Reason: More Questions

  4. #4
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is. Look at this link. Near the top is some info about PHP_SELF.

    http://uk.php.net/reserved.variables
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  5. #5
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou.

    Can someone what this does and how it does it. I understnad that it takes the rows from the db and displays theme in paragraphs, but how does it work?:

    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }

    Thanks

    Neil

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    www.php.net/manual

    All the explanations you could need can be found therein.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone help me with the following situation:

    Currently i have a drop down menu box on the parkguide page of my existing website. In this box is a link to each of the themeparks rides (a page about each) If i make a table with id, ridename, and whatever else, culd i have a variable which is passed to a template page in the link in the menu box which brings up the template ride page and fills in the data using the data from the table in the database depending on what id was passed in the variable?

    Thanks

    Neil

  8. #8
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can someone what this does and how it does it. I understnad that it takes the rows from the db and displays theme in paragraphs, but how does it work?:

    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }
    OK, I don't know how much PHP you understand already so I will explain it as clearly as I can.

    The while is a loop. We will come back to that part after I go through the rest of it.

    Basically we assign a new variable, $row, to an array of data from the database which has been put into the conditions of the while loop.

    Now that $row has been made into a variable that contains an array of data we add ['joketext'] onto the end of it. However this could have been a different field that we wanted to display as there are different fields being stored in the array $row. So we could have had ['author'] or whatever the other fields were. That would display the authors in the database.

    We then close the loop with the curly brace }.

    The while loop basically goes through the data in the database while there is data there. So if there was just 1 record in a database, the while loop would see that for the first record the conditions were true however when it looks for the next record the conditions are false and so the while loop stops. If there were 5 records in the database it would see that the conditions were true for the first 5 loops but then false when it reached the sixth loop.

    I hope that clears things up rather than confuse you.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  9. #9
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, understanding now! Any idea for my last question?

    Thanks

    Neil

  10. #10
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just looking into that...give me some time.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  11. #11
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers!

  12. #12
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I may have missed something out here but this is what I've got so far. Remember to go through and change the field names etc. Make sure you change the right ones and read the comments so that you understand whats going on.

    themepark.php - the main page with the select menu.
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Theme Park - Select Menu page</title>
    </head>
    <body>
    </body>
    </html>
    <?php
    // connect to mysql
    $dbcnx mysql_connect("localhost""root""password"
           or die(
    mysql_error()); 

    // select db
    $db mysql_select_db("themepark"
          or die(
    mysql_error());

    // do query to get id to pass to address bar
    $result mysql_query("SELECT id,ridename FROM rides") or die('Error, query failed');
    ?>
    <form method="get" action="parkride.php">
    <select name="rideid">
    <option selected="selected" value="">--Select a Ride--</option>
    <?php
    // go through the database and while there are different rides add them to the list dynamically
    while ($row mysql_fetch_array($result)) {
    // $rideid is the variable that the parkride.php page will look for and then use that id to display the right data
    $rideid=$row['id'];
    echo 
    '<option value=/"'.$rideid.'/">'.$row['ridename'].'</option>';
    }
    ?>
    </select>
    <input type="submit" value="Go to Ride" />
    </form>
    parkride.php - the page which finds the $rideid value in the addressbar and then displays the relevant data
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Park Ride</title>
    </head>
    <body>
    </body>
    </html>
    <?php
    // connect to mysql
    $dbcnx mysql_connect("localhost""root""password"
           or die(
    mysql_error()); 

    // select db
    $db mysql_select_db("themepark"
          or die(
    mysql_error());

    // check to see if the ride id has been passed through the address bar
    // if it has then assign the variable $rideid to that value from the $_GET array
    if (isset($_GET['rideid'])) {
    $rideid=$_GET['rideid'];

    // get info from database so that it can be displayed on the page later
    // remember the id has been passed through the address bar so now the query just uses that id's record of data
    $sql=@mysql_query("SELECT*FROM rides WHERE id='$rideid'");
    // mysql_fetch_array is an array which holds all the records field values, assign $getdata variable to this array
    $getridedata=@mysql_fetch_array($sql);

    // Start displaying data by using $getridedata array and change the field names to whatever your fields are
    echo '<b>Ride Name</b>: '.$getridedata['ridename'].'<br />';
    echo 
    '<b>Ride Description</b>: '.$getridedata['description'].'<br />';
    echo 
    '<b>Ride Duration</b>: '.$getridedata['rideduration'].'<p></p>';
    echo 
    '<b>Whatever field you want here</b>: '.$getridedata['blablabla'].'<p></p>';
    }

    ?>
    I really hope it works
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  13. #13
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way. An update.

    I've changed the select element's name from parkrides to rideid in themepark.php.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  14. #14
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, let me try that now.

  15. #15
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in parkrides.php whats the "users" part:

    // get info from database so that it can be displayed on the page later
    // remember the id has been passed through the address bar so now the query just uses that id's record of data
    $sql=@mysql_query("SELECT*FROM users WHERE id='$rideid'"); ?

    do i need a table called users? if so what needs to be in it?

    Thanks

    Neil

  16. #16
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops that was my mistake...put whatever your table's name is.

    I was using some code I had used previously to base your one on.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  17. #17
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it works but it shows like Ride Name: and Ride Description:

    and then nothing after them?

  18. #18
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the address bar show after you press go and enter the parkride.php page?
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  19. #19
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  20. #20
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it show the correct id after http://127.0.0.1/themeparksite/parkride.php?rideid=
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  21. #21
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, if you change the bit after rideid= to 1, 2, or another number it shows the data. mmmm...Could you post your code so I can see if something's missing or wrong?
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  22. #22
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post your code for both pages?
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  23. #23
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this instead of the 2 similar lines in parkride.php.

    PHP Code:
    if (isset(urlencode($_GET['rideid']))) {
    $rideid=urlencode($_GET['rideid']); 
    See if that works.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  24. #24
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    After adding the new code i get this error:

    Code:
    Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in c:\Sites\Single19\rctneil\webroot\parkride.php on line 20
    Below is the code for both pages minus the connection details:

    Parkride.php
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Park Ride</title> 
    </head> 
    <body> 
    </body> 
    </html> 
    <?php 
    // connect to mysql 
    $dbcnx mysql_connect("blah""blah""blah"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    // check to see if the ride id has been passed through the address bar 
    // if it has then assign the variable $rideid to that value from the $_GET array 
    if (isset(urlencode($_GET['rideid']))) { 
    $rideid=urlencode($_GET['rideid']); 

    // get info from database so that it can be displayed on the page later 
    // remember the id has been passed through the address bar so now the query just uses that id's record of data 
    $sql=@mysql_query("SELECT*FROM rides WHERE id='$rideid'"); 
    // mysql_fetch_array is an array which holds all the records field values, assign $getdata variable to this array 
    $getridedata=@mysql_fetch_array($sql); 

    // Start displaying data by using $getridedata array and change the field names to whatever your fields are 
    echo '<b>Ride Name</b>: '.$getridedata['ridename'].'<br />'
    echo 
    '<b>Ride Description</b>: '.$getridedata['description'].'<br />'
    echo 
    '<b>Ride Duration</b>: '.$getridedata['rideduration'].'<p></p>'


    ?>
    Themepark.php
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Theme Park - Park Guide</title> 
    </head> 
    <body> 
    </body> 
    </html> 
    <?php 
    // connect to mysql 
    $dbcnx mysql_connect("blah""blah""blah"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    // do query to get id to pass to address bar 
    $result mysql_query("SELECT id,ridename FROM rides") or die('Error, query failed'); 
    ?> 
    <form method="get" action="parkride.php"> 
    <select name="rideid"> 
    <option selected="selected" value="">--Select a Ride--</option> 
    <?php 
    // go through the database and while there are different rides add them to the list dynamically 
    while ($row mysql_fetch_array($result)) { 
    // $rideid is the variable that the parkride.php page will look for and then use that id to display the right data 
    $rideid=$row['id']; 
    echo 
    '<option value=/"'.$rideid.'/">'.$row['ridename'].'</option>'

    ?> 
    </select> 
    <input type="submit" value="Go to Ride" /> 
    </form>
    Thanks

    Neil

  25. #25
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I am just trying out a few things ready for when i implement the database into the real website and i would like to know if there is a way for me to have a url to an image in the database and when a row is displayed on a page the url would convert to show the image instead of the images path? What sort of field type would i use?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •