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);
> 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"];
> }
> }
Nope...that's not correct!
PHP will put every column of ONE row in an array. You will have to loop
trough your recordset to get all rows.
function get_shipping_address($address_array)
{
$conn = db_connect();
$orderid = get_order_id($orderid);
$query = "SELECT * FROM orders WHERE orderid = '$orderid'";
while( $row = mysql_fetch_array($query) );
{
$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"];
// Do something...
}
}
HTH
Erwin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php