Jacko623 Posted February 21, 2007 Share Posted February 21, 2007 Hi everyone, I'm querying my database to pull a random happy hour from one database, then matching it to a database with the bar information. For some reason, the script only pulls 2 bars today even though there are many more than 2 bars with events tonight. Here is the code: <?php //Connect $ConDB=mysql_connect($hostname,$username,$password); $DB=mysql_select_db($dbname,$ConDB); //Day Variables $today = getdate(); $d = "$today[wday]"; if ($d == 0) { $dday = ('Sun'); } if ($d == 1) { $dday = ('Mon'); } if ($d == 2) { $dday = ('Tues');} if ($d == 3) { $dday = ('Wed'); } if ($d == 4) { $dday = ('Thur');} if ($d == 5) { $dday = ('Fri'); } if ($d == 6) { $dday = ('Sat'); } $hh = "hh$dday"; $ns = "ns$dday"; //Query for Happy Hour $queryH = "SELECT bar_user_id,$hh,$ns FROM partynj_bar_calendar WHERE $hh OR $ns <> NULL Order by Rand() limit 0,5"; $resultH = mysql_query($queryH) or die("Problem with the query <pre>$queryD</pre><br>" . mysql_error()); $rwH = mysql_fetch_assoc($resultH); $HHbar = "$rwH[bar_user_id]"; //Query for Bar $queryB = "SELECT id, bar_name,bar_descrip,city FROM partynj_bar_details WHERE id='$HHbar'"; $resultB = mysql_query($queryB); list($id,$bar_name,$bar_descrip,$city) = mysql_fetch_array($resultB); //Query for Bar's City $queryC = "SELECT city FROM partynj_citylist WHERE id='$city'"; $resultC = mysql_query($queryC) or die("Problem with the query <pre>$queryT</pre><br>" . mysql_error()); //Print ALL INFORMATION ?> <a href="../bars/?<?=stripslashes($bar_name)."|".$id?>&act=all"><?=stripslashes($bar_name)?></a><br> <? if (mysql_num_rows($resultC) == 1) { $rwC = mysql_fetch_assoc($resultC); echo stripslashes($rwC['city']); } else echo 'There is a problem finding where the city ' . stripslashes($bar_name) . ' is located'; if (($bar_descrip) == NULL) { echo (" "); } else echo stripslashes("<br> Description : $bar_descrip <br>"); if (($rwD["$hh"]) AND ($rwD["$nh"]) <> NULL) { echo ("<br> Tonight's specials are : "); echo ($rwH["$ns"]); echo ("<br>"); echo ("<br> Tonight's happy hour special is : "); echo ($rwH["$hh"]); } if (($rwD["$hh"]) == NULL) { echo ("<br> Tonight's specials are : "); echo ($rwH["$ns"]); } echo ("<br> Tonights happy hour is : "); echo ($rwH["$hh"]); ?> To see this in action please go to: http://www.partynj.net/test/happyhour.php Link to comment https://forums.phpfreaks.com/topic/39418-rand-not-going-through-full-db/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.