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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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