View Full Version : How to print all the records.

02-13-2010, 11:49 AM

The below code prints only the first record.

How do i modify or what should i do to make it print all the records in the table.

Thanks in advance


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>


//including configuration file
$db_host=""; // PARAMETERS OF THE DB
$con=mysql_connect($db_host,$db_user,$db_pass) or die("Unable to connect to database");

mysql_select_db("$database", $con);

$row=mysql_query("SELECT * FROM t_master")or die (mysql_error());

while($result = mysql_fetch_array($row))
//Assigning database results to variable
$song1 = $result['songno1'];
$song2 = $result['songno2'];
$song3 = $result['songno3'];
$song4 = $result['songno4'];
$song5 = $result['songno5'];
$songno_1 = $result['songno_1'];
$songno_2 = $result['songno_2'];
$songno_3 = $result['songno_3'];
$songno_4 = $result['songno_4'];
$songno_5 = $result['songno_5'];

//Comparing with lookup table
$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song1")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$songname1 = $song1;

//Trim each song name to 25 Characters
$song1name = substr($songname1,0,23);

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song2")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$songname2 = $song2;
//Trim each song name to 25 Characters
$song2name = substr($songname2,0,23);

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song3")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$songname3 = $song3;
//Trim each song name to 25 Characters
$song3name = substr($songname3,0,23);

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song4")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$songname4 = $song4;
//Trim each song name to 25 Characters
$song4name = substr($songname4,0,23);

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song5")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$songname5 = $song5;
//Trim each song name to 25 Characters
$song5name = substr($songname5,0,23);

<table border="1" width="100%">
<?php echo "<td>$id</td>";?>
<?php echo "<td>#$id HumFM 13-2-10 1)$song1name 2)$song2name 3)$song3name 4)$song4name 5)$song5name</td>";?>
<?php } ?>



02-13-2010, 12:34 PM
You are using $row as the return value of mysql_query() everywhere. So by the time of the 2nd iteration $row is not result of the query "SELECT * FROM t_master" any more. This is why your main while-loop stops after the 1st iteration.