RE: [PHP-WIN] MS SQL Query question
| From: | Ron dot Herhuth at tatumpartners dot com | Date: | Tue, 25 May 2004 19:20:58 +0000 |
| Subject: | RE: [PHP-WIN] MS SQL Query question | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-23833@lists.php.net to get a copy of this message | ||
Trevor,
That is the key!!! You rock...cut my page load time in half.
Thanks my good man!
Ron
>From: Gryffyn, Trevor
>To: Derrick Hermanson; Herhuth, Ron; php-windows@lists.php.net
>Sent: 05/25/2004 3:11 PM
>What's happening is the pointer on the results is advancing until it
>hits the end of the result set. When you run it again, the pointer is
>still at the end of the result set and therefore sees nothing 'ahead' of
>it.
>
>The same thing can happen with arrays. I'm not sure if you have to do
>it still, but I habituatlly do a "reset($arr);" after I do a sort on the
>array because the sort did (still does?) leave the array pointer at the
>end of the array, necessitating a 'reset'.
>
>Read some of the notes here:
>http://us4.php.net/mysql_fetch_array
>
>This one in particular should help:
>********************************
>Ben
>06-Apr-2004 09:59
>One of the most common mistakes that people make with this function,
>when using it multiple times in one script, is that they forget to use
>the mysql_data_seek() function to reset the internal data pointer.
>
>When iterating through an array of MySQL results, e.g.
>
><?php
>while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> foreach ($line as $col_value) {
> echo $col_value . '<br />';
> }
>}
>?>
>
>the internal data pointer for the array is advanced, incrementally,
>until there are no more elements left in the array. So, basically, if
>you copy/pasted the above code into a script TWICE, the second copy
>would not create any output. The reason is because the data pointer has
>been advanced to the end of the $line array and returned FALSE upon
>doing so.
>
>If, for some reason, you wanted to interate through the array a second
>time, perhaps grabbing a different piece of data from the same result
>set, you would have to make sure you call
>
><?php
>mysql_data_seek($result, 0);
>?>
>
>This function resets the pointer and you can re-iterate through the
>$line array, again!
>********************************
>
>-TG
>
>
>> -----Original Message-----
>> From: Derrick Hermanson [mailto:dhermanson@acton.com]
>> Sent: Tuesday, May 25, 2004 3:05 PM
>> To: Ron.Herhuth@tatumpartners.com; php-windows@lists.php.net
>> Subject: RE: [PHP-WIN] MS SQL Query question
>>
>>
>> try something like this
>>
>> $result = mssql_query ($query);
>> if ($result) {
>> while ($template_args = msssql_fetch_array ($res)) {
>> //what ever you want to do with the data
>> }
>> }
>>
>> Derrick Hermanson
>> Programmer/Analyst I
>> Acton International LTD.
>> 402.470.5816
>> mailto:dhermanson@acton.com
>>
>>
>> -----Original Message-----
>> From: Ron.Herhuth@tatumpartners.com
>> [mailto:Ron.Herhuth@tatumpartners.com]
>> Sent: Tuesday, May 25, 2004 1:30 PM
>> To: php-windows@lists.php.net
>> Subject: [PHP-WIN] MS SQL Query question
>>
>>
>>
>> When I run a query the syntax looks like this:
>>
>> $result = mssql_query($query);
>> $numRows = mssql_num_rows($result);
>>
>> for($i=0; $i<$numRows; $i++)
>> {
>> $row = mssql_fetch_array($result);
>> }
>>
>> but if I go to try and loop through the resultset again it wont work
>> unless I run this line again "$result = mssql_query($query);"
>>
>> I'm sure this is wasting resources but I can't seem to get
>> around it. Any
>> suggestions?
>>
>> Thanks,
>> Ron
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>