Jump to content

[SOLVED] how do i fetch data from mysql table?


johnwayne77

Recommended Posts

i connect to the db:

 

mysql_connect("localhost", "admin", "pass") or die(mysql_error());

mysql_select_db("test") or die(mysql_error());

 

now, i have a table called: 'shipment' with three fields:

 

tracking

name

address

 

I keep the tracking (which is unique) in a cookie for later use -- so I can do this :

 

$tracking = $_COOKIE['tracking'];

$check = mysql_query("SELECT * FROM shipment WHERE tracking = '$tracking'")or die(mysql_error());

 

Now, my problem is that I need to echo the name and address for tracking and I don't know how.

 

How do I do that? Any Ideas?.

Read some basic php-mysql tutorials....

 

<?php

$check = mysql_query("SELECT * FROM shipment WHERE tracking = '$tracking'")or die(mysql_error());
$row = mysql_fetch_array($check);
echo $row['name']." Lives in ".$row['address'];

?>

 

 

@wildteen88- You're faster :D But no need for a loop, "tracking" is unique.

 

Orio.

You have to put the query into an array like so:

 

$shipment = mysql_fetch_array($check);

 

then to display the rest you would do echo it like this:

 

echo $shipment['name'];

 

or

 

echo $shipment['address'];

 

I hope this helps!

 

 

Archived

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

×
×
  • Create New...

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.