JamesThePanda Posted January 13, 2010 Share Posted January 13, 2010 Hi I have this database in it there are 3 fields ID, age, name, what I want to do is when I user types in a age the database returns all the users with that age. So someone types in 20 and then it outputs all the names that have a age of 20. This is a learning script at the moment. What is the MySQL I need to do this. thanks James Quote Link to comment Share on other sites More sharing options...
waynewex Posted January 13, 2010 Share Posted January 13, 2010 <?php $age = 0; //by default if(isset($_POST['age'])){ $age = (int) $_POST['age']; } $query = "SELECT * FROM yourtablename WHERE age = '$age'"; $result = mysql_query($query) or trigger_error(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo $row['name'].' - Age '.$row['age'].'<br />'; } ?> You'll need to make a HTML form that has a textfield called 'age' that allows users to enter in the age that they're looking for. Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted January 13, 2010 Author Share Posted January 13, 2010 LOL Im going to have to put a connet to sql thing in there, Ill try that out now Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted January 13, 2010 Author Share Posted January 13, 2010 whoops Quote Link to comment 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.