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 Link to comment https://forums.phpfreaks.com/topic/188328-mysql-query/ Share on other sites More sharing options...
waynew 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. Link to comment https://forums.phpfreaks.com/topic/188328-mysql-query/#findComment-994194 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 Link to comment https://forums.phpfreaks.com/topic/188328-mysql-query/#findComment-994199 Share on other sites More sharing options...
JamesThePanda Posted January 13, 2010 Author Share Posted January 13, 2010 whoops Link to comment https://forums.phpfreaks.com/topic/188328-mysql-query/#findComment-994210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.