RE: WHY need to query 2x to get results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It worked like a charm. (initially I was trying to use reset() guess it was
the wrong call)

One other thing, The 1st call was supposed to get the Column Headers and the
second to get the results. I thought they are independent of each other??
Guess not?

thanks very much.

Cheers,
Mun Heng, Ow
H/M Engineering
Western Digital M'sia 
DID : 03-7870 5168


-----Original Message-----
From: Terry Riley [mailto:moscow@cix.co.uk]
Sent: Tuesday, July 22, 2003 7:33 PM
To: php-db@lists.php.net
Subject: Re:  WHY need to query 2x to get results


Because you have already fetched one row before outputting the record 
count. Therefore the row pointer is at the second record before you 'print 
out'.

Try putting 

mysql_data_seek($result,0);

in place of your second 

$result = mysql_query($sql);

This should return the pointer to the first retreived record.

Hope that helps

Terry

----------Original Message---------  

> Hi,
> 
> 	I have a code that goes like this. Scroll down to the 
"<----------"
> sign. How come I need another $result = mysql_query($sql) at that 
> location?
> If I don't have it, the results coming out will only start printing 
> from the
> 2nd Row.. Omitting the 1st.
> 
> Results as wanted 
> 
> row 1		value1
> row 2		value2
> row 3 	value3
> 
> Getting this instead
> 
> row 2		value2
> row 3 	value3
> 
> ????
> 
> Pls Help.
> 
> 	$result = mysql_query($sql);
> 
> 	$num_results = mysql_num_rows($result);
> 
> 	$row = mysql_fetch_row($result); 
> 	
> 	echo '<p><h4>There are ' . $num_results; 
> 	echo ' FA entries found</p></h4>' . "\n";
> 	
> 	echo '<table border="2" cellpadding="5">' . "\n";
> 	echo '<td colspan="' . sizeof($row) . '" align="center" >';
> 	echo '</td>' . "\n";
> 
> # ===========================
> # Print out the Table Field Names
> # ===========================
> 	echo '<!-- Results Table Header Field Names -->';
> 	echo "\n";
> 	echo '<tr>' . "\n";
> 	
> 	for ($k = 0; $k < sizeof($row) ; $k++)
> 	{
> 		echo "\t" . '<td>';
> 		echo mysql_field_name($result,$k);
> 		echo "</td> \n";
> 	}
> 
> # ===========================
> # Print out the Table Results
> # ===========================
> 	
> 	$result = mysql_query($sql);   <---------------======WHY Is THIS
> needed????
> 
> 	for ($i = 0; $i < $num_results ; $i++)
> 	{
> 		echo "<tr>\n"  ;
> 		$row = mysql_fetch_row($result);
> 		for ($j = 0; $j < 12 ; $j++)
> 		{
> 			echo "\t" . '<td>';
> 			echo  $row[$j] ;
> 			echo "</td> \n";
> 		}
> 
> 		echo "</tr>\n";
> 	}
> Cheers,
> Mun Heng, Ow
> H/M Engineering
> Western Digital M'sia 
> DID : 03-7870 5168
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux