Jump to content


Photo

limit question


  • Please log in to reply
3 replies to this topic

#1 taylorv

taylorv
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 March 2003 - 04:18 PM

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.

#2 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 25 March 2003 - 09:21 AM

WHERE won > 0 ???

P.

EDIT: Sorry... just realised your problem... thinking....
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 taylorv

taylorv
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 March 2003 - 02:19 PM

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>\" ;
}
}

#4 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 26 March 2003 - 11:59 AM

Fine.... good you only have 31 rows...

I think there might be a nice join solution but if it works...

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users