Jump to content

Mysql query


JamesThePanda

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.