0

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

1
  • 1
    SELECT * FROM users where wins >= 100 Commented May 19, 2012 at 12:29

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

5 Comments

nope.. that is just one query. using while you will be just displaying all records...
The insert does not work for me. Could you post it has coding ?? and not just words ?
what are the field name that you have in rewards table?
Don't worry i got it now just did a simple insert in the while. And did the select out of the while
can you tell me what did you write inside while loop??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.