RE: [PHP-DB] WHY need to query 2x to get results

2003-07-22 Thread Terry Riley
I think reset() is only for arrays

Terry

--Original Message-  

> 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



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



RE: [PHP-DB] WHY need to query 2x to get results

2003-07-22 Thread Ow Mun Heng
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:[EMAIL PROTECTED]
Sent: Tuesday, July 22, 2003 7:33 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] 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 'There are ' . $num_results; 
>   echo ' FA entries found' . "\n";
>   
>   echo '' . "\n";
>   echo '';
>   echo '' . "\n";
> 
> # ===
> # Print out the Table Field Names
> # ===
>   echo '';
>   echo "\n";
>   echo '' . "\n";
>   
>   for ($k = 0; $k < sizeof($row) ; $k++)
>   {
>   echo "\t" . '';
>   echo mysql_field_name($result,$k);
>   echo " \n";
>   }
> 
> # ===
> # Print out the Table Results
> # ===
>   
>   $result = mysql_query($sql);   <---==WHY Is THIS
> needed
> 
>   for ($i = 0; $i < $num_results ; $i++)
>   {
>   echo "\n"  ;
>   $row = mysql_fetch_row($result);
>   for ($j = 0; $j < 12 ; $j++)
>   {
>   echo "\t" . '';
>   echo  $row[$j] ;
>   echo " \n";
>   }
> 
>   echo "\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



Re: [PHP-DB] WHY need to query 2x to get results

2003-07-22 Thread Terry Riley
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 'There are ' . $num_results; 
>   echo ' FA entries found' . "\n";
>   
>   echo '' . "\n";
>   echo '';
>   echo '' . "\n";
> 
> # ===
> # Print out the Table Field Names
> # ===
>   echo '';
>   echo "\n";
>   echo '' . "\n";
>   
>   for ($k = 0; $k < sizeof($row) ; $k++)
>   {
>   echo "\t" . '';
>   echo mysql_field_name($result,$k);
>   echo " \n";
>   }
> 
> # ===
> # Print out the Table Results
> # ===
>   
>   $result = mysql_query($sql);   <---==WHY Is THIS
> needed
> 
>   for ($i = 0; $i < $num_results ; $i++)
>   {
>   echo "\n"  ;
>   $row = mysql_fetch_row($result);
>   for ($j = 0; $j < 12 ; $j++)
>   {
>   echo "\t" . '';
>   echo  $row[$j] ;
>   echo " \n";
>   }
> 
>   echo "\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



Re: [PHP-DB] WHY need to query 2x to get results

2003-07-22 Thread Jason Wong
On Tuesday 22 July 2003 18:20, Ow Mun Heng wrote:
> 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);

The above line has gobbled up your 1st row of results and moved the result 
pointer onto the 2nd row.

Use mysql_data_seek() to reset the pointer back to the 1st row.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
Flights never leave from Gate #1 at any terminal in the world
-- Murphy's Laws for Frequent Flyers n4
*/


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