Jump to content

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/148159-solved-random-by-group/
Share on other sites

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...?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.