NoDoze Posted March 5, 2009 Share Posted March 5, 2009 I'm not sure how to describe this so, please bare with me.... This is what I need... on one page: thumb1 - title1 - discription1 - county1 - state1 - url1 thumb2 - title2 - discription2 - county2 - state1 - url2 thumb3 - title3 - discription3 - county3 - state1 - url3 thumb4 - title4 - discription4 - county4 - state1 - url4 then on the next page for these to be generated randomly....so 1, 2, 3, 4 are changing order every time, BUT retaining their order/info by row. This is what I have so far: <tr> <td class="sub-table-images"> <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "<a href=".$row['cutsheet'] . "><img src=".$row['thumb'] . " width='180' height='115' border='0' /></a>"; } ?> </td> <td class="sub-table"><div class="sub-table-im-header"> <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "".$row['title']; } ?> </div> <div class="sub-table-im-txt"> <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "".$row['disc']; } ?> </div> <div class="sub-table-im-loc"> <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "".$row['county'] . ", " . $row['state']; } ?> </div> <div class="sub-table-im-txt"> <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "(<a href=".$row['cutsheet'] . ">pdf</a>)"; } ?> </div></td> </tr> This pulls the data from the mysql db ok, but I need it to be random from page to page. So basically I need the WHERE id='1' to be random like so... ORDER BY RAND() ....but how would I make sure the title, description, county, state, url are from the same id? ...cause if I entered the RAND() for each query it'll pull random for each value, when I just need each row random. ....does any of what I've said make sense...? LOL ...I'm confused... Thanks for any input Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/ Share on other sites More sharing options...
NoDoze Posted March 5, 2009 Author Share Posted March 5, 2009 Ok...I'm trying to think through this one step at a time.... I've gotten to here: <?php $result = mysql_query("SELECT * FROM projects WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo " <a href=".$row['cutsheet'] . "><img src=".$row['thumb'] . " width='180' height='115' border='0' /></a> </td> <td class='sub-table'><div class='sub-table-im-header'> ".$row['title'] ." </div> <div class='sub-table-im-txt'> ".$row['disc'] ." </div> <div class='sub-table-im-loc'> ".$row['county'] . ", " . $row['state'] ." </div> <div class='sub-table-im-txt'> (<a href=".$row['cutsheet'] . ">pdf</a>) </div> "; } ?> ...basically I've combined it to one query... so now I THINK just adding the ORDER BY RAND() to the query should make it work, right? hehe....Hmmm...? Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/#findComment-777729 Share on other sites More sharing options...
NoDoze Posted March 5, 2009 Author Share Posted March 5, 2009 Sweet! LOL Figured it out myself! Worked like a dream... Helps when you break it down into pieces Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/#findComment-777738 Share on other sites More sharing options...
fenway Posted March 8, 2009 Share Posted March 8, 2009 Then post the final working solution, please. Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/#findComment-779817 Share on other sites More sharing options...
NoDoze Posted March 9, 2009 Author Share Posted March 9, 2009 I did! The above just add ORDER BY RAND() to the query! ...did you even read the post...? LOL Seriously... if people don't start reading this before posting, I'm going to consider not answering at all. Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/#findComment-780707 Share on other sites More sharing options...
fenway Posted March 12, 2009 Share Posted March 12, 2009 I did! The above just add ORDER BY RAND() to the query! ...did you even read the post...? LOL Um... guess not... looked like more code to read, as opposed to a working query... my ba. Quote Link to comment https://forums.phpfreaks.com/topic/148159-solved-random-by-group/#findComment-782765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.