Jump to content

[SOLVED] Why does this only show 1 result?


28rain

Recommended Posts

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>

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.