SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What the bleep is wrong witht his?

    PHP Code:

    <?

    //Database & MYSQL Server Information
    $host2 "localhost";
    $user2 "nfire";
    $password2 "49431";
    $database2 "nfire";
    $tablename2="****";


    //Database Connection
    $link2 mysql_connect ($host2$user2$password2);



    $query2 "SELECT id, title, players, esrb, rumble, platform, release_date, dev FROM $tablename2 where id='$id' ";

    $result2 mysql_db_query ($database2$query2$link2);


    print(
    "<h3 align=\"center\">$row2[title]</h3>");


    while (
    $row2mysql_fetch_array($result2)) {

              
           
                
    $title $row2[title];
                
    $players $row2[players];


    echo(
    "
    <h3>
    $title</h3>
    platform: 
    $row2[platform]<br>
    date: 
    $row2[release_date]<br>
    Players: 
    $row2[players]<br>
    Rumble: 
    $row2[rumble]<br>
    ESRB: <img src=\"/esrb/
    $row2[esrb].gif\">
    "
    );

    $host "localhost";
    $user "nfire";
    $password "****";
    $database "nfire";
    $tablename="developers";


    //Database Connection
    $link mysql_connect ($host$user$password);

    $query "SELECT developer, developer_link from $tablename where id='$row2[dev]'";

    $result mysql_db_query ($database$query$link);


    while (
    $row mysql_fetch_array



       
    ($result)) {

    $developer $row[developer];


    $id $developer;
    $developerlink $row[developer_link];

    print(
    "Developer: <a href=\"developers.php?id=$row2[dev]\">$id</a><br>");

    $host3 "localhost";
    $user3 "nfire";
    $password3 "****";
    $database3 "nfire";
    $tablename3="reviews";

    //Connect to Reviews Database

    $link3 mysql_connect ($host3$user3$password3);
    $query3 "SELECT * FROM $tablename3 where id = '$row2[id]'";
    $result3 mysql_db_query ($database3$query3$link3);
    while (
    $row3 mysql_fetch_array($result3)) {
    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");
    } else {
    print(
    "No Reviews Available"); 
    }

    }
    }
    mysql_close ($link);
    mysql_close ($link2);
    mysql_close ($link3);



    ?>
    Here is the error output:

    Parse error: parse error, unexpected T_ELSE in /usr/local/psa/home/vhosts/xboxfire.com/httpdocs/games/games.php on line 85


    I know it has something to do with } else { but I can't find the correct way to do this .

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This could just be my ignorance but I've never seen an else on a while statement, nor do I see the point of ever doing so.

    Eventually (hopefully) a while will return false and then it will move onto the next bit of code. Why not ditch the else and just put the next bit of code on the next line?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eh, let me try and explain.

    This is a games script where it displays a game with all the information about it. Then the reviews links appear underneath of it, now since it's using the reviews db connection and not the game connection, it'll only display the "Reviewed by" then the title if there is a review available, now if there is not a review, it displays nothing. I'd like to display "No Reviews Avalailable". I really need this help, I am so close to being finished with my own CMS it's not even funny.

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm.. not sure, but maybe you could fix this by plugging the while statement inside an if statement. That would make the else{} part valid again.

  5. #5
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    try changing this
    PHP Code:
    while ($row3 mysql_fetch_array($result3)) {
    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");
    } else {
    print(
    "No Reviews Available"); 

    to this
    PHP Code:
    while ($row3 mysql_fetch_array($result3)) {
      if (
    $row3[name] != "") {
    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");
      } else {
        print(
    "No Reviews Available"); 
      }

    that way you actually check what results you are displaying and then decided on what to display.

    (Also more useful titles are usually helpful )

    Sarah
    Regular user

  6. #6
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, it displays Reviews by the right way, but the "No Reviews Available" don't show up...

  7. #7
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) Else never works with while, that's your problem

    2) It doesn't, becuase its' in the while() loop, and the loop isn't being passed through.

    You dont' need ANY loops:

    PHP Code:
    $result3 mysql_db_query ($database3$query3$link3);
    if (
    mysql_num_rows($result3) > 0)
    {
    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");
    } else {
    print(
    "No Reviews Available"); 


  8. #8
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Close, but you forgot to fetch the rows .

    PHP Code:
    $result3 mysql_db_query ($database3$query3$link3);
    while (
    $row3 mysql_fetch_array($result3)) {
    if (
    mysql_num_rows($result3) > 0)

    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");
    } else {
    print(
    "No Reviews Available"); 

    Thanks for your help.

  9. #9
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah that figures, it don't work that way either... this is so retarded... why won't else work?

  10. #10
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the problem,

    PHP Code:
    $query3 "SELECT * FROM $tablename3 where id = '$row2[id]'"
    If there is no entry that is equal to $row2[id], then it won't execute the query... anyone know how I could fix this?

  11. #11
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Disregard this thread, I figured it out!

    PHP Code:
    //Connect to Reviews Database

    $link3 mysql_connect ($host3$user3$password3);
    $query3 "SELECT * FROM $tablename3 where id = '$row2[id]'";
    $result3 mysql_db_query ($database3$query3$link3);
    while (
    $row3 mysql_fetch_array($result3)) {
    print(
    "Review by <a href=\"/reviews/reviews.php?id=$row3[pid]\">$row3[name]</a>");



    }
    }
    }

    if (
    mysql_num_rows($result3) == 0) {
    print(
    "There are no reviews available for this game"); } 
    Basically, just say to hell with "else" worked.

  12. #12
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ha! Ha!

    Gloat, gloat, gloat.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •