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.. Thats what i end up getting for output, and those arnt the values in pagetitle... Help?
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!!!
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.
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...
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