SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey there. I am a little lost here, trying to make a simple PHP script.

    I made a MySQL table called "reviews" with the fields "rID" and "title". I inserted one row (rID 1 and title Gladiator).

    I made the following SQL command in reviews.php :


    $sql = mysql_query("SELECT title FROM reviews WHERE rID = $rID");
    if (!$sql) {
    echo("Error retrieving data!");
    exit();
    } ?>


    Now I want the title to show up between the <TITLE> tags, so I made this:

    <TITLE>My Site - Reviews - <? echo $title ?></TITLE>

    It doesn't work. What am I doing wrong? (I know it must be something stupid =)

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    P.S. I go to reviews.php like this:

    reviews.php?rID=1

    so that's not it

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I fiddled around it with for a long while, and used a while clause to display the title. (I took this from the sitepoint tutorial)

    <? while ( $row = mysql_fetch_array($res) ) {
    echo($row["title"]);
    } ?>

    However, when I use this twice in a document (for instance, to show the title in the <TITLE> area and at the top of the page), it doesn't work. Also, it seems pretty pointless to use a while clause for a page that displays only one 'entry' (in this case a review). In the jokes database of the example the while clause is used to show a lot of entries.

    Is there an easier way to get the fields from the database and make them values (with the dollar sign) or something, so I can stick em in the html wherever I want?

    Oh, and am I making any sense at all? =)

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand you correctly you are only after one record from the db. Skip the while clause and just use:
    $row = mysql_fetch_array($res);

    then you can use $row["fieldname"] wherever you want to.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOHOO! Thank you thank you thank you!


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
  •