Line 13 is re-assigning $result, the save variable you're using in line 1!
1 while($row = mysql_fetch_array($result))
2 {
3 $pri = $row['pri'];
4 $fg = $row['fg'];
5 $molw = $row['molw'];
6 $density = $row['density'];
7 $denstype = $row['denstype'];
8 $pctd = $row['pctd'];
9 $maxpctd = $row['maxpctd'];
10 $compid = $row['compid'];
11
12 $sql = "select * from compounds where compid = \"$compid\"";
13 $result = mysql_query($sql,$conn);
14 $row = mysql_fetch_array($result);
15
16 $compname = $row['compname'];
17 $concentration = $row['concentration'];
18 $concunit = $row['concunit'];
19 $type = $row['type'];
20 $composition = $row['composition'];
21
22 if ($fg=="Y")
23 $html .= "<b>$concentration $concunit $compname</b><br>";
24 else if ($pri=="Y")
25 $html .= "<font color=\"#000066\"> $concentration $concunit
$compname</font><br>";
26 else
27 $html .= " $concentration $concunit $compname<br>";
28 }
-----Original Message-----
From: Lee P Reilly [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 20, 2002 9:24 AM
To: PHP List
Subject: [PHP] while loop question - problem (new set of eyes needed)
Hi,
I wonder if someone could have a quick look at this for me? It's a
simple while loop, but it's not acting the way (I think) it should. If I
break down the while loop, it reads:
--------------------------------------------
// $result contains 3 rows
while($row = mysql_fetch_array($result))
{
echo " xxx ";
}
--------------------------------------------
=> xxx xxx xxx is displayed (as expected)
If I add the following code to the loop, it only seems to iterate
through it *once*:
--------------------------------------------
while($row = mysql_fetch_array($result))
{
$pri = $row['pri'];
$fg = $row['fg'];
$molw = $row['molw'];
$density = $row['density'];
$denstype = $row['denstype'];
$pctd = $row['pctd'];
$maxpctd = $row['maxpctd'];
$compid = $row['compid'];
$sql = "select * from compounds where compid = \"$compid\"";
$result = mysql_query($sql,$conn);
$row = mysql_fetch_array($result);
$compname = $row['compname'];
$concentration = $row['concentration'];
$concunit = $row['concunit'];
$type = $row['type'];
$composition = $row['composition'];
if ($fg=="Y")
$html .= "<b>$concentration $concunit $compname</b><br>";
else if ($pri=="Y")
$html .= "<font color=\"#000066\"> $concentration $concunit
$compname</font><br>";
else
$html .= " $concentration $concunit $compname<br>";
}
--------------------------------------------
Expected results:
--------------------------------------------
Actin #2543: Description here.
1 mol AEBSF
1.3 mol Calcium Chloride
1.4 mol Potassium Chloride
--------------------------------------------
Actual results:
--------------------------------------------
Actin #2543: Description here.
1 mol AEBSF
--------------------------------------------
i.e the last two compounds are not displayed.
I can't for the life of me see the problem. A new set of eyes looking at
this would be GREATLY appreciated. Thanks very much in advance.
- Best regards,
Lee
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php