sorry bill, i misunderstood your question. I thought you wanted to only return one row, not just get one value. Given my new understanding, I would do something like this which is only a slight variant on what you did $result = mysql_query("select euro from brandstofprijzen where id=2") or die (mysql_error()); $row=mysql_fetch_array($result); $euro =$row[0];
-----Original Message----- From: bill [mailto:[EMAIL PROTECTED]] Sent: Wednesday, September 11, 2002 7:50 AM To: David Buerer Subject: Re: [PHP] Re: mysql query Maybe I wasn't clear. The value returned should be called "euro" not "row" I didn't think I needed LIMIT because the query should be written to only get one row; at least the function only returns the first row. kind regards, bill David Buerer wrote: Look into the LIMIT command, it will limit the number of rows in the result set to the number you specify -----Original Message----- From: bill [ mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] Sent: Wednesday, September 11, 2002 7:10 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: mysql query function mysql_one_element($query, $element) { // quickly returns just one element from a query $one=mysql_query($query); // add error checking here if you wish $r=mysql_fetch_array($one); $thisvalue=$r[$element]; return($thisvalue); } $row=mysql_one_element("select euro from brandstofprijzen where id=2", "euro"); Chris Schoeman wrote: > I use the script below to get one value out of a database: > > $result = mysql_query("select euro from brandstofprijzen where id=2") > or die (mysql_error()); > while ($row = mysql_fetch_array($result)) > { > $euro = $row["euro"]; > } > mysql_free_result($result); > > This is working fine, but is there an easier (less code) way to do > this? > > Thankx -- PHP General Mailing List ( http://www.php.net/ <http://www.php.net/> ) To unsubscribe, visit: http://www.php.net/unsub.php <http://www.php.net/unsub.php>