Problem in fetching array form database in php

Hi there,

I am trying to fetch array form database and its showing data but after that it starts flagging up with error and die.

Please let me know if I mistook somewhere in code.

While Loop is working but It dies after showing last row.

Please help.

Code is here:


$sql   = "Select * from tbl_partymamber where pt_rel = $rel";

	$result = mysql_query($sql);
	$tot_record=mysql_num_rows($result)or die('Cannot delete product image 1. ' . mysql_error());
	if($tot_record>0)
	{
	$sno_22 = 0;
	while($row=mysql_fetch_array($result)or die('Error Cannot Get Data. ' . mysql_error()))       //Loop is working but It dies here in end.....
		{	
			$sno_22++;
			if($sno_22%3==1)
			{
				
				echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
                         }

                        if($sno_22%3==0)
			{
				
				echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
                         }
if($sno_22%3==2)
			{
				
				echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
                         }
}
}


Please let me know your expert comments.

THanks in advance for your help.

Thanks a lot!

while($row=mysql_fetch_array($result)or die('Error Cannot Get Data. ’ . mysql_error())) //Loop is working but It dies here in end…

You can replace this line by;

while($row=mysql_fetch_array($result))
{
//your code to fetch data
}

It dies after the last row because you told it to do so with the ‘or die’ on the fetch. Try this:


$sql   = "Select * from tbl_partymamber where pt_rel = $rel";
$result = mysql_query($sql) or die("Mysql error " . mysql_error() . " on query $sql");
$tot_record=mysql_num_rows($result);
if ($tot_record>0) {
  $sno_22 = 0;
  while ($row=mysql_fetch_array($result) {    
    $sno_22++;
    if ($sno_22%3==1) {
      echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
    }
    if ($sno_22%3==0) {
      echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
    }
    if ($sno_22%3==2) {
      echo "Name: ".$row['pt_name']."Mobile: ".$row['pt_mobile']."Email: ".$row['pt_email']."<br />";
    }
  }
} 

Silllllllly…mistake.

Thanks a lot!..its working fine.