Re: Re: mysql
| From: | Erik Price | Date: | Wed, 10 Apr 2002 13:59:57 +0000 |
| Subject: | Re: Re: mysql | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92388@lists.php.net to get a copy of this message | ||
On Wednesday, April 10, 2002, at 07:45 AM, David Robley wrote:
Yes, just last night I discovered that the while or other loop is really only necessary if you're retrieving possible multiple results. You can do it very simply just like $sql = "SELECT..."; $result = mysql_query($sql, $db); $row = mysql_fetch_row($result); echo $row[0]; And of course the above can be modified for multiple columns/array elements. Someone did suggest that you use an if statement, however, in the event that no records are retrieved -- if (!$result = mysql_query($sql, $db)) { echo "No records found."; } else { $row = mysql_fetch_row($result); } Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.comI've been looking on the net and the php docs for a simple mysql query solution, can someone please let me know the best way to get the values of a query that only returns 1 record? All the select query examples on the net are examples of multiple records being returned, and therefor, there is repition methods shown. For this I don't need any repitition, I just need to know the best way to get the DB values from the query into variables. Cheers. -MasonA while or similar should still work with only one record; but of course you could just drop the while and use the 'enclosed' code just once. If you have a particular sample you want to reduce, post it if you need more help.