RE: [PHP]Only 1 Query Result...help.

From: Date: Mon, 15 Oct 2001 20:12:51 +0000
Subject: RE: [PHP]Only 1 Query Result...help.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71138@lists.php.net to get a copy of this message
SELECT * FROM pics LIMIT 0, 1 --> You'll get the first photo. SELECT * FROM pics LIMIT 1, 1 --> You'll get the second photo. SELECT * FROM pics LIMIT 2, 1 --> You'll get the third photo. SELECT * FROM pics LIMIT 3, 1 --> You'll get the fourth photo. To retrieve the single row, you can do this: if(extract(@mysql_fetch_assoc(@mysql_query("SELECT * FROM pics LIMIT 0,1")))) { // code to print out picture } else { // no picture was retrieved (for some reason) } I haven't tested this, but you get the idea.... If you're only returning one row from the query, you can call mysql_fetch_assoc() directly on the result of the mysql_query() call. I added extract() in there, since it will convert the associative array to global variables, e.g.: $array['item'] = "this is an item" $array['blah'] = "foo" extract($array); Would produce: $item = "this is an item" $blah = "foo" -----Original Message----- From: Chris Cocuzzo [mailto:cuzo@mediaone.net] Sent: Monday, October 15, 2001 12:43 PM To: php-general@lists.php.net Subject: Re: [PHP]Only 1 Query Result...help. maybe I'm an idiot, but I don't understand how that helps in not using a loop to display the results. Could you explain a little more? thanks chris ----- Original Message ----- From: "_lallous" <elias_bachaalany@yahoo.com> To: <php-general@lists.php.net> Sent: Monday, October 15, 2001 3:30 AM Subject: Re: [PHP]Only 1 Query Result...help. > try to see the SELECT * FROM table LIMIT max, offset > > see the LIMIT syntax. > > "Chris Cocuzzo" <cuzo@mediaone.net> wrote in message > news:002b01c154f3$0a113310$ae687780@webs224... > hey- > > I'm trying to put together a photo album system with next/previous buttons > that displays one picture at a time, and obviously the user has to click > through the buttons to navigate the pictures. I'm using this line for the > query > > $picquery = "SELECT picid,path,width,height FROM pics WHERE id = $id"; > > normally to display results I'd use the mysql_fetch_array function and print > it out like: $picdata[src]; > > what i was wondering if there's another function that I can use that'll > stick the results into an array or some other organized data structure so I > can display them, but without using a loop to display just one result > > thanks > chris > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#71138) next »