Jump to content


Photo

One query works but the other doesnt??


  • Please log in to reply
4 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 April 2006 - 11:06 AM

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 purc_item 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($result1))
{
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?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 April 2006 - 01:17 PM

The value of $row used in the first loop is being reset in the second loop. Try this:

while($row1 = mysql_fetch_array($result1))
{
echo "<td><b>";
echo ''.$row1['quantity'].'';
Legend has it that reading the manual never killed anyone.
My site

#3 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 April 2006 - 01:44 PM

Thanks but there is still no output for the second loop.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 April 2006 - 01:57 PM

$result1 = mysql_query($query,$connect1)
That should be:
$result1 = mysql_query($query1,$connect1)

Legend has it that reading the manual never killed anyone.
My site

#5 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 April 2006 - 02:31 PM

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users