Here is my problem:
I am trying to pull a random row from a recordset retrieved from the database, without using order by rand(). Lets say that this is the record set that is returned.
Item | ShortAbstract | Title
2230 blah,blah,blah Blah
2450 blah,blah,blah Blah
2650 blah,blah,blah Blah
2560 blah,blah,blah Blah
Now what I want to do is randomly pull out a row:
2650 blah,blah,blah Blah
I am not sure that I am using the following code properly. If someone could help me out, that would be great. Here is the code:
$itemQuery = "SELECT DISTINCT c.Item, c.ShortAbstract, c.Title FROM department_item di, content c, " .
"content_rotation cr WHERE di.Department = " . $ID . " AND " .
"c.Item = di.Item AND " .
"cr.StartDate <= '" . $today . "' AND " .
"cr.EndDate >= '" . $today . "' AND " .
"cr.Rotation = 6";
if (!($itemResults = mysql_query($itemQuery)))
{
$errorMsg .= "Error: Could not select article<br>MySQL reported " . mysql_error() . "";
}
else
{
if (mysql_num_rows($itemResults) > 0)
{
while ($input = mysql_fetch_array($itemResults))
{
$array = array($input);
$randomItem = array_rand($array, 1);
print("<h3 align=\"center\">" . $input[$randomItem["Title"]] . "</h3><br><p>" . $input[$randomItem["ShortAbstract"]] . "</p>");
print("<p align=\"right\"><a href=\"http://careers.easyupdates.com/new_purchase.php3?SCREEN=content_item&item=" . $input[$randoItem["Item"]] ."\"><img src=\"images/purchasearticle.gif\" width=\"162\" height=\"8\" border=\"0\" hspace=\"10\" alt=\"Winning\"></a><img src=\"images/purchasebook.gif\" width=\"97\" height=\"8\" hspace=\"10\" border=\"0\"></p>");
}
}
else
{
$errorMsg .= "Error: No rows were returned";
}
}