Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

One query works but the other doesnt??

Recommended Posts

Hi,
I have used the following code for my queries:

$connect = connect_to_db("con.inc");
$query = "SELECT * FROM purc WHERE
ID='{$_SESSION['ID']}'";
$result = mysql_query($query,$connect)
or die("sql_del: ".mysql_error($connect));

$connect1 = connect_to_db("con.inc");
$query1 = "SELECT * FROM [b]purc_item[/b] WHERE
ID='{$_SESSION['ID']}'";
$result1 = mysql_query($query,$connect1)
or die("sql_del: ".mysql_error($connect1));

The only difference is the table which is highlighted in bold and i have changed the variable names. Now the following code is used to extract the data:

echo "The ID for the product is: <br>";

while($row = mysql_fetch_array($result))
{
echo ''.$row['ID'].'';
}

echo "The quantity for the product is: <br>";

while($row = mysql_fetch_array([b]$result1[/b]))
{
echo "<td><b>";
echo ''.$row['quantity'].'';
echo "</b></td>";
}
echo "<br><br>";

The first piece of data is extracted perfectly but the second piece doesnt seem to work?? I have changed the variable name. It seems i can keep extracting data from the first query but not the second? I had this problem before and wanst able to see what i was doing wrong?

Share this post


Link to post
Share on other sites
The value of $row used in the first loop is being reset in the second loop. Try this:

while([b]$row1[/b] = mysql_fetch_array($result1))
{
echo "<td><b>";
echo ''.$[b]row1[/b]['quantity'].'';

Share this post


Link to post
Share on other sites
[code] $result1 = mysql_query($query,$connect1)[/code]
That should be:
[code] $result1 = mysql_query($query1,$connect1)[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.