Php And Mysql Help...

Discussion in 'Gaming' started by Equivalent Exchange, Jun 23, 2006.

  1. Equivalent Exchange

    Equivalent Exchange Well-Known Member

    Posts:
    1,466
    Likes Received:
    0
    Joined:
    Nov 9, 2005
    Okay, I'm trying to write part of a program that will print a list of all "pagetitle" fields

    Code:
    $getpages = mysql_query("Select * FROM pages");
    $numpages = mysql_num_rows($getpages);
    $i = 1;
    echo $numpages;
    echo "[list]";
    while (($i <= $numpages)) {
    	$showtitle = mysql_query("SELECT pagetitle FROM pages WHERE pageid='$i'");
    	echo "[*]" . $showtitle . "";
    	$i++;
    }
    echo "[/list]";
    The first part runs fine, it figures out the amount of rows without a hickup.

    Then it goes to print each pagetitle, however..

    [​IMG]

    Thats what i end up getting for output, and those arnt the values in pagetitle...

    Help?
     
  2. willwill100

    willwill100 Well-Known Member

    Age:
    32
    Posts:
    231
    Likes Received:
    0
    Joined:
    Nov 6, 2005
    Location:
    Manchester, UK
    i got those errors when i did my project. take out the while clause, check that $numpages is giving out a value. if there is no problem whith the num_row, the prob is in the while clause.

    try this:

    Code:
    $getpages = mysql_query("SELECT * FROM `pages`");
    $numpages = mysql_num_rows($getpages);
    $i = 1;
    echo $numpages;
    echo "[list]";
    while ($i <= $numpages) {
    $showtitle = mysql_query("SELECT `pagetitle` FROM `pages` WHERE pageid='$i'");
    echo "[*]" . $showtitle . "";
    $i++;
    }
    echo "[/list]";
    post the results!!!
     
  3. johndapunk FTW

    johndapunk FTW Senior Member

    Age:
    30
    Posts:
    2,513
    Likes Received:
    0
    Joined:
    Jan 19, 2006
    Location:
    Palm Beach
    k erm will.... learn php part of mysql b4 helping, yeah, but nt anyway.
    here ya go Equivalent.
    Yours:
    Correct:
    Code:
    $getpages = mysql_query( "SELECT * FROM pages" );
    $num = mysql_num_rows( $getpages );
    echo $numpages.'[list]';
    for( $i = 1; $i <= $numpages; $i++ ) {
    $s = mysql_query( "SELECT pagetitle FROM pages WHERE 'pageid' = '$i'" ); // $s is short for $select
    $r = mysql_fetch_array( $s ) // $r is short for $result
    // you could also go: $r = mysql_fetch_array( mysql_query( "SELECT pagetitle FROM pages WHERE 'pageid' = '$i'" ) ); 
    //but its just not as neat.
    $showtitle = $r[ 'COLUMNNAME' ]; // I'm not sure what the column name
    // is for your title field, so I can't finish that part.
    echo '[*]'.$showtitle.'
    ';
    }
    echo '[/list]';
    I prefer using the for() statement compared to that technique with the while() statement, thats why i used it.
     
  4. Equivalent Exchange

    Equivalent Exchange Well-Known Member

    Posts:
    1,466
    Likes Received:
    0
    Joined:
    Nov 9, 2005
    Thanks a bunch man. I was gonna use for() too, but it had been a while since my programming class, and couldnt remember the order, ha.

    I'll post results in a sec...
     
  5. johndapunk FTW

    johndapunk FTW Senior Member

    Age:
    30
    Posts:
    2,513
    Likes Received:
    0
    Joined:
    Jan 19, 2006
    Location:
    Palm Beach
    kk.

    Always remember, if in doubt, check php.net. It's the Google of PHP :P
     
  6. Equivalent Exchange

    Equivalent Exchange Well-Known Member

    Posts:
    1,466
    Likes Received:
    0
    Joined:
    Nov 9, 2005
    Thats the error, I bolded line 19

    and yeah, I actually had php.net open for the full duration of last night :lol:


    Edit:

    Okay, that whole thing above was fixed, there was a missing semicolon (always the simple problems)

    the thing is, the result page is just... blank now

    Edit again:

    Tweek Tweek tweek and finally working, thanks john, [+]repatized
     

Share This Page