In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> I have a mysql query that I need to echo a variable from "once" before I go
> into the while loop which would list the entire contents of the array. The
> field shown once will not be displayed in the while looped contents. So
> theoretically, something like this:
> 
> $result = mysql_query("SELECT h.title, a.agentname, a.agenturl,
> IF(h.status='Sold',1,0) AS is_sold FROM homes h, agents a WHERE h.owner=a.id
> AND a.id=$aid ORDER BY is_sold ASC");
> 
> if ($is_sold=="1") {
> echo $agentname." ".$agenturl;
> }
> 
> while ($row=mysql_fetch_array($result)) {
> extract($row);
> echo $title."<br>";
> }
> 
> Currently, I have everything in the while loop which prints things out more
> than what I'd like. Is there a way that I can get around this problem?
> 
> Any suggestions are greatly appreciated thanks. :)

I am not sure I understand the logic of what you are trying to do. It 
seems to me that it might be possible that the value of is_sold might 
vary between records retrieved? In which case just displaying the first 
occurrence might be misleading.

Notwithstanding the logic aspect, the solution to your immediate problem 
is mysql_data_seek

$result = mysql_query("SELECT h.title, a.agentname, a.agenturl,
IF(h.status='Sold',1,0) AS is_sold FROM homes h, agents a WHERE 
h.owner=a.id
AND a.id=$aid ORDER BY is_sold ASC");

//Get first row
$row=mysql_fetch_array($result);
// Record pointer now points to _second_ row of results
extract($row);
if ($is_sold=="1") {
 echo $agentname." ".$agenturl;
}

// Reset pointer to _first_ record of results
if (!mysql_data_seek($result, 0)) {
 echo "Cannot seek to row 0\n";
// Add error handling here
}            

// Now loop through the entire set
while ($row=mysql_fetch_array($result)) {
 extract($row);
 echo $title."<br>";
 }


-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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

Reply via email to