Jump to content

limit question


taylorv

Recommended Posts

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.

Link to comment
Share on other sites

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

}

}

Link to comment
Share on other sites

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.