fetch row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

fetch row

Post by C_Calav »

hi guys,

am i doing something wrong here?

Code: Select all

$order_number = mysql_query($sql_ordernumber, $db) or die ("Execution failed for Order Number: ".mysql_error());
   
$order_row = mysql_fetch_row($order_number);
getting a results of
Array
thanx guys
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

print_r($order_row);

#
foreach ($order_row as $row) {
echo $row['whatever_field'];
}
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

hi thanx for your help,

im not too familair with your code sorry, but i see what your doing.

i tried to change mine a bit.

Code: Select all

$sql_ordernumber = "SELECT * from orders WHERE O_CookieID = '$CookieID'";

   $order_number = mysql_query($sql_ordernumber, $db) or die ("Execution failed for Order Number: ".mysql_error());
   
   $order_row = mysql_fetch_row($order_number);
   
   $O_Id = $row['O_Id'];
i only want O_Id pulled from the DB.

now it is out putting nothing??

thanx
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

$sql_ordernumber = "SELECT * from orders WHERE O_CookieID = '$CookieID'";
$order_number = mysql_query($sql_ordernumber, $db) 
or die ("Execution failed for Order Number: ".mysql_error());
$order_row = mysql_fetch_assoc($order_number);
print_r($order_row);
$O_Id = $row['O_Id'];
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx anjanesh,

i cant seem to print the O_Id to screen?

am i doing anything wrong?

print_r($order_row); this here prints the O_Id but i cant print it on its own.

thanx

Code: Select all

$sql_ordernumber = "SELECT * from orders WHERE O_CookieID = '$CookieID'";
   $order_number = mysql_query($sql_ordernumber, $db) or die ("Execution failed for Order Number: ".mysql_error());
   $order_row = mysql_fetch_assoc($order_number);
   print_r($order_row);
   $O_Id = $row['O_Id'];
   #Finished inserting
      print_r($O_Id);
marike
Forum Newbie
Posts: 24
Joined: Thu Mar 31, 2005 6:19 pm
Location: New York

Post by marike »

Code: Select all

while($order_row = mysql_fetch_assoc($order_number)) {
  print $order_row['O_Id'];
}
or try:

Code: Select all

$order_row = mysql_fetch_assoc($order_number);
  print_r $order_row['O_Id'];
Unless I'm missing something silly, it should work. Hope this helps.

Jcart | Typo :roll:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$sql_ordernumber = "SELECT `O_Id` from `orders` WHERE `O_CookieID` = '$CookieID'";
No use on fetching columns you arn't using ;)
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

C_Calav wrote:i cant seem to print the O_Id to screen?
Ah..sorry - I forgot to replace $row with $order_row

Code: Select all

$sql_ordernumber = "SELECT * from orders WHERE O_CookieID = '$CookieID'";
$order_number = mysql_query($sql_ordernumber, $db) 
or die ("Execution failed for Order Number: ".mysql_error());
$order_row = mysql_fetch_assoc($order_number);
print_r($order_row);
$O_Id = $order_row['O_Id'];
Post Reply