Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

HELP get random fields from a column ??

images php coding issues or problems here.

Moderators: macek, egami, gesf

HELP get random fields from a column ??

Postby silhouett » Thu Jul 21, 2011 10:43 am

I have a mysql database that has these fields id picfile piclink approved

Normally I do every thing using the id. I am looking to randomly get four images that are marked approved being that approved is true. I want the four picfile or piclink one being the file on my server the other being an http:// reference. I want the four random images or picfile, piclink to be placed in four variables
each time I call the routine... I do not want to unapproved ones and of course I need to stay with in the maxium number that the id is up to. Basically I am looking to grab four fields from a column not a row and assign them to a variable if the corresponding row approved field is true... :D


Any help would is thanked in advance.
User avatar
silhouett
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Jul 18, 2011 3:40 pm

Re: HELP get random fields from a column ??

Postby egami » Fri Jul 22, 2011 4:28 am

SELECT * FROM table WHERE approved='1' ORDER BY RAND() LIMIT 4
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: HELP get random fields from a column ??

Postby silhouett » Fri Jul 22, 2011 7:09 am

Ok this part works to a point


$sql = "select id,picfile from $table where approved='1' order by rand() Limit 1";
$result = mysql_query($sql) or die("Failed: $sql - ".mysql_error());
$resrow = mysql_fetch_array($result);
$theid1 = $resrow[0];
$picfile1 = $resrow[1];



but with out having to duplicate this four times how can I get 4 images
I tried changing limit to 4 and looking at $resrow[2] and $resrow[3] but it seems
only $resrow 1 and 2 get a value.

I tried Select * but I didnt get any result... and fetch_row as well

I am a beginner at this select command and query so any help is great :D
User avatar
silhouett
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Jul 18, 2011 3:40 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron