On 25 Jul 2002 at 2:04, GOLD, MATTHEW wrote:

>  thank you very much for your quick response.
> 
> How do I run mysql_fetch_row before the while loop?  I don't want two
> loops, because I just want this variable to print out once.
> 
> I tried this, but it didn't work:
> 
> $query = "Select blah1, blah2, blah3 from blahtable";
> $result = mysql_query ($query)
>  or die ("Cannot complete query");
> 
> $row = mysql_fetch_row ($result))
> print ("$row[4]");
> 
> while ($row = mysql_fetch_row ($result))
> {
>  print "$row[1], $row[2], etc.");
> }
> 
> ?>
> 
> I realize that my problem is that I don't really understand arrays...but I
> am new to all of this, and I very much appreciate your help.
> 
> best,
> 
> Matt

So what you want to do is print a field from the first row extracted from the table, 
then 
loop through all the rows and print several fields? I think you want mysql_data_seek.

Whenever you do a mysql_fetch_row, php grabs the current row from the result set, and 
shifts a pointer to the next record in the result set. In this case it seems you need 
to 
print from the first record, then reset the pointer to the first record and print from 
all 
records found. So:

$row = mysql_fetch_row ($result))
print ("$row[4]");

mysql_data_seek($result, 0);  // Add this

while ($row = mysql_fetch_row ($result))

Unless I misunderstand what you are trying to do....

Cheers
-- 
David Robley
Temporary Kiwi!
Quod subigo farinam

"I've been to a film festival in the South of France," said Tom cannily.



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

Reply via email to