foreach question

From: Date: Tue, 29 Jul 2008 19:25:11 +0000
Subject: foreach question
Groups: php.general 
Request: Send a blank email to php-general+get-277434@lists.php.net to get a copy of this message
Hey Everyone... So I am attempting to pull 2 random records from a MySQL database, so I wrote a function which I'll paste below. I had it mostly working with a while() statement, but I wanted to try a foreach to see if I could get the formatting a little bit better. Basically... What it does is grab 2 records at random from the database, and display the images. What I want is something that looks like this: <img1> VS <img2> right now though... I'm at a lose to figure out why it's not returning any records but not throwing any errors... Any ideas what I'm missing? <?PHP //function for pulling random pictures from the database function random($random){ $randomQuery = "SELECT * FROM current ORDER BY Rand() LIMIT 2"; $result = mysql_query($randomQuery); $row[] = $result; foreach($row as $key => $value) { $random[$key] = $value; } return $random; }//End of function ?> Any ideas?

« previous php.general (#277434) next »