user1405062
user1405062

Reputation: 85

How To Create Mysql Select Statement With Limit

Hello. I need help with doing a mysql select, where the values in wins is higher than lets say 100 ? So it selects only the users who have had more than 100 win's

Then i need to inserts each one into a table.

Here is what i have so far

<?php
// i have toke my connect out


// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM users") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>username</th> <th>wins</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td>"; 
    echo $row['username'];
    echo "</td><td>"; 
    echo $row['wins'];
    echo "</td></tr>"; 
} 

echo "</table>";
?>

I am guessing id need a were statement ? Saying select were wins > 100 ? I have done loads of select were's be for but never select were is over. I also will need to insert each one of the results into another table called rewards

Upvotes: 0

Views: 102

Answers (1)

Fahim Parkar
Fahim Parkar

Reputation: 31627

Your current query SELECT * FROM users will give you ALL data that is present in your table.

To get the data where wins > = 100 just add this condition so that new statement will be

SELECT * FROM users where wins >= 100

To insert into rewards table (considering you have fields as username, wins) use below

insert into rewards 
(username, wins) 
select username, wins 
from users 
WHERE wins >= 100

Upvotes: 0

Related Questions