[PHP] Address array?

2002-11-04 Thread Steve Jackson
I want to display an address from my database based on an orderid. Where
am I going wrong? I am still unsure how Php interacts with mySQL but am
I right in assuming it should be an array?

My code...

function get_shipping_address($address_array)
{
$conn = db_connect();
$orderid = get_order_id($orderid);
$query = SELECT * FROM orders WHERE orderid = '$orderid';
$row = mysql_fetch_array($query);
foreach ($address_array as $row)
{
$ship_name = $row[ship_name];
$ship_address = $row[ship_address];
$ship_city = $row[ship_city];
$ship_zip = $row[ship_zip];
$ship_country = $row[ship_country];
}
}

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Address array?

2002-11-04 Thread Jason Wong
On Monday 04 November 2002 16:42, Steve Jackson wrote:
 I want to display an address from my database based on an orderid. Where
 am I going wrong? I am still unsure how Php interacts with mySQL but am
 I right in assuming it should be an array?

 My code...

 function get_shipping_address($address_array)
 {
 $conn = db_connect();
 $orderid = get_order_id($orderid);
 $query = SELECT * FROM orders WHERE orderid = '$orderid';
 $row = mysql_fetch_array($query);

You don't need the foreach loop (and in fact you've mixed up its parameters so 
it wouldn't work anyway).

 foreach ($address_array as $row)
   {
   $ship_name = $row[ship_name];
   $ship_address = $row[ship_address];
   $ship_city = $row[ship_city];
   $ship_zip = $row[ship_zip];
   $ship_country = $row[ship_country];
   }

Just simply:

  $ship_name = $row[ship_name];
  $ship_address = $row[ship_address];
  $ship_city = $row[ship_city];
  $ship_zip = $row[ship_zip];
  $ship_country = $row[ship_country];



Here's how foreach can be used:

 foreach ($row as $field_name = $field_value)
{
echo $field_name contains $field_valuebr;
}


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
QOTD:
It's been Monday all week today.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Address array?

2002-11-04 Thread Hugh Danaher
Stephen,
after your line:

$query = SELECT * FROM orders WHERE orderid = '$orderid';

you should add:

mysql_query($query);

in your code line you've just set your variable--you haven't asked mysql to
do anything.

Hope this helps.
Hugh

- Original Message -
From: Steve Jackson [EMAIL PROTECTED]
To: PHP General [EMAIL PROTECTED]
Sent: Monday, November 04, 2002 12:42 AM
Subject: [PHP] Address array?


 I want to display an address from my database based on an orderid. Where
 am I going wrong? I am still unsure how Php interacts with mySQL but am
 I right in assuming it should be an array?

 My code...

 function get_shipping_address($address_array)
 {
 $conn = db_connect();
 $orderid = get_order_id($orderid);
 $query = SELECT * FROM orders WHERE orderid = '$orderid';
 $row = mysql_fetch_array($query);
 foreach ($address_array as $row)
 {
 $ship_name = $row[ship_name];
 $ship_address = $row[ship_address];
 $ship_city = $row[ship_city];
 $ship_zip = $row[ship_zip];
 $ship_country = $row[ship_country];
 }
 }

 Steve Jackson
 Web Developer
 Viola Systems Ltd.
 http://www.violasystems.com
 [EMAIL PROTECTED]
 Mobile +358 50 343 5159


 --
 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