taylorv Posted March 24, 2003 Share Posted March 24, 2003 I have a big database of contest entrants and I have randomly selected 30 names from this database to be winners. Part of the rules of this contest were that you could enter as many times as you want, so when I picked a winner, I have updated all their entries as having won and given them a number based on what day they won. (ex. for the first winner - won=\'1\' for the second won=\'2\', etc.) Now for the tricky part... I want to create a page that pulls one record from each winner and displays their information. So how do I pull only one record from all the winners? I thought about doing something like this: $sql1 = \"SELECT * from tbl_name WHERE won=\'1\' LIMIT 1\"; $sql2 = \"SELECT * from tbl_name WHERE won=\'2\' LIMIT 1\"; $sql3 = \"SELECT * from tbl_name WHERE won=\'3\' LIMIT 1\"; Etc. but it seems very ineffiecient.. especially since this contest is going to run for 30 days. So is there a mySQL statement that I can use to make this an easier task? Or do I just have to hash each winner out one at a time? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/261-limit-question/ Share on other sites More sharing options...
pallevillesen Posted March 25, 2003 Share Posted March 25, 2003 WHERE won > 0 ??? P. EDIT: Sorry... just realised your problem... thinking.... Quote Link to comment https://forums.phpfreaks.com/topic/261-limit-question/#findComment-791 Share on other sites More sharing options...
taylorv Posted March 25, 2003 Author Share Posted March 25, 2003 I came up with this and it seems to work... for ($row_count=1; $row_count < 31; $row_count++) { $sql = \"SELECT * FROM tbl_name WHERE won=\'$row_count\' LIMIT 1\"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $fname = $row [0]; $lname = $row [1]; $state = $row [5]; $city = $row [4]; /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ( $row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. print \"<tr bgcolor=\"$row_color\" class=\"answers\">\"; print \"<td nowrap>$row_count - </td>\"; print \"<td>$fname $lname</td> \"; print \"<td>$city, $state</td>\"; print \"</td> \"; print \"</tr>\" ; } } Quote Link to comment https://forums.phpfreaks.com/topic/261-limit-question/#findComment-792 Share on other sites More sharing options...
pallevillesen Posted March 26, 2003 Share Posted March 26, 2003 Fine.... good you only have 31 rows... I think there might be a nice join solution but if it works... P. Quote Link to comment https://forums.phpfreaks.com/topic/261-limit-question/#findComment-807 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.