...

View Full Version : How to print all the records.



coolguyraj
02-13-2010, 11:49 AM
Hi,

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


<html>

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

<body>

<?php
//including configuration file
$db_host="127.0.0.1"; // PARAMETERS OF THE DB
$db_user="root";
$db_pass="test";
$database="backlog";
$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
$id=$result['ticketid'];
$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);
$song1=$result1['songname'];
$songname1 = $song1;

//Trim each song name to 25 Characters
$song1name = substr($songname1,0,23);
$song1movie=$result1['moviename'];
$songno1=$result1['songno'];

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

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

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

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

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

</body>

</html>

SKDevelopment
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum