28rain Posted February 15, 2009 Share Posted February 15, 2009 This code only returns 1 result from the table, when there are actually four?! <? $db_name = "testDB"; $table_name = "watch"; $connection = mysql_connect("127.0.0.1", "****", "****") or die(mysql_error()); $db = mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "SELECT id, format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq FROM $table_name ORDER BY id"; $result = mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $id = $row['id']; $format = $row['format']; $title = stripslashes($row['title']); $artist_fn = stripslashes($row['artist_fn']); $artist_ln = stripslashes($row['artist_ln']); $rec_label = stripslashes($row['rec_label']); $my_notes = stripslashes($row['my_notes']); $date_acq = $row['date_acq']; if ($artist_fn != ""){ $artist_fullname= trim("$artist_fn $artist_ln"); } else { $artist_fullname = trim("$artist_ln"); } if ($date_acq == "0000-00-00"){ $date_acq = "[unknown]"; } $display_block = "<p><strong>$title</strong> on $rec_label, by $artist_fullname<br> $my_notes <em>(acquired:$date_acq, forat:$format)</em></p>"; } ?> <html> <head> <title>My Music (Ordered by ID)</title> </head> <body> <h1>My Music: Ordered by ID</h1> <? echo "$display_block"; ?> <p><a href="my_menu.html">Return to menu.</a></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/145280-solved-why-does-this-only-show-1-result/ Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 You're overwriting $display_block variable in each loop pass Change $display_block = "<p><strong>$title</strong> on $rec_label, by $artist_fullname<br> to $display_block .= "<p><strong>$title</strong> on $rec_label, by $artist_fullname<br> = means "replace content on the left, with content on the right" .= means "add string to the right to the string on the left" Quote Link to comment https://forums.phpfreaks.com/topic/145280-solved-why-does-this-only-show-1-result/#findComment-762663 Share on other sites More sharing options...
28rain Posted February 15, 2009 Author Share Posted February 15, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145280-solved-why-does-this-only-show-1-result/#findComment-762666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.