Re: Anything wrong with this function?

From: Date: Thu, 31 Oct 2002 09:14:25 +0000
Subject: Re: Anything wrong with this function?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122218@lists.php.net to get a copy of this message
You still need to execute the query to get a result set.
$query = "select orderid from receipts"; $shippingquery = "select shipping from receipts"; $orderid = mysql_result($query); $shipping = mysql_result($shippingquery);
$query and $shippingquery are not result sets. $this_var = mysql_query ( $query ); $orderid = mysql_result ( $this_var ); mysql_free_result ( $this_var ); $that_var = mysql_query ( $shippingquery ); $shipping = mysql_result ( $that_var ); mysql_free_result ( $that_var ); However, I don't think you're going to get the desired result from mysql_result() unless you're only planning on returning one piece of data. Steve Jackson wrote:
Well the db_connect() function selects the DB so I don't need to repeat that. And I've tried Select orderid from receipts where customerid = '10' as a test and it still returned nothing. Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com stephen.jackson@violasystems.com Mobile +358 50 343 5159
-----Original Message----- From: John Nichel [mailto:jnichel@by-tor.com] Sent: 31. lokakuuta 2002 10:57 To: stephen.jackson@violasystems.com Cc: PHP General; MySQL General Mailing list Subject: Re: [PHP] Anything wrong with this function? You're not executing the query, or selecting a db. But that's just the tip of the iceberg. If you have more than one "orderid" and more than one "shipping" your queries will return all of them. I'm not sure if this is what you want, but if it is, you really should be using something like mysql_fetch_array() instead of mysql_result(). If you're looking for just one result, you should change your SQL to somethere like this.... SELECT orderid FROM databasename.receipts WHERE some_unique_key = 'some_unique_identifier' function get_order_id_receipt($orderid, $shipping) { //Get order ID from DB to pass to receipt. $conn = db_connect(); $query = "select orderid from receipts"; $shippingquery = "select shipping from receipts"; mysql_select_db ( YOUR_DATABASE_NAME ); $orderid_result = mysql_query ( $query ); $orderid = mysql_result($orderid_result); $shipping = mysql_result($shippingquery); //return $orderid; } Steve Jackson wrote:
Can anyone see why I am having problems with this page. I'm trying to connect to the DB and display results using
the function
get_order_id_receipt. The DB connection works because I can produce the cart based on the users session so I don't get why this doesn't work.... <? include ('products_fns.php'); include ('order_fns.php'); include ('db_fns.php'); include ('output_fns.php'); // The shopping cart needs sessions, so start one session_start(); do_html_header("Please print out this page for your records."); function get_order_id_receipt($orderid, $shipping) { //Get order ID from DB to pass to receipt. $conn = db_connect(); $query = "select orderid from receipts"; $shippingquery = "select shipping from receipts"; $orderid = mysql_result($query); $shipping = mysql_result($shippingquery); //return $orderid; } //debug test echo mysql_error(); echo "test & $orderid"; echo "test & $shipping"; display_receipt($orderid); echo "<table width='760' cellpadding='0' background='images/shopbg.gif'><tr><td>&nbsp;</td></tr></table>"; display_cart($cart, false, 0); echo "<table width='760' cellpadding='0' background='images/shopbg.gif'><tr><td>&nbsp;</td></tr></table>"; echo "<table width='760' cellpadding='0' background='images/shopbg.gif'><tr><td>&nbsp;</td></tr></table>"; display_success_form(); //empty shopping cart //session_destroy(); do_html_footer(); ?> Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com <http://www.violasystems.com/> stephen.jackson@violasystems.com Mobile +358 50 343 5159


« previous php.general (#122218) next »