Thread: sql query
View Single Post
(#2)
Old
grace1004 grace1004 is offline
Senior Member
grace1004 is on a distinguished road
 
Posts: 890
Join Date: Dec 2010
Default 04-30-2012, 02:02 AM

The following code is applicable in case the matching result is just one row.

PHP Code:
<?php 
 $host
="mysql16.000webhost.com"
 
$user ="a7246488_serg91"
 
$password "xxxx"
 
$database ="a7246488_drinks"

 
$connection mysql_connect($host$user$password) or die ("couldn't connect to server");        
 
$db mysql_select_db($database$connection) or die("couldn't select database."); 

 
$name $_POST['term']; //name of the drink entered by a user
         
 
$query ="select NAME, INGREDIENTS, INSTRUCTIONS, CATEGORY from a1(1) where NAME = '%$name%'"
 
$result mysql_query($query) or die ("Couldn't execute the query.");     
    
 
// display $result in an array
 
$row mysql_fetch_array($result);  
 if(
$row) { 
        
        echo
'Name:'.$row['name']; 
        echo
'<br>Ingredients: '.$row['Ingredients']; 
        echo
'<br>instructions: '.$row['Instructions']; 
        echo
'<br>category: '.$row['category']; 
        echo
'<br>Image: '.$row['image'];  
}
else {
echo 
"No matching result!";
}        
?>

Last edited by grace1004; 04-30-2012 at 02:12 AM.
Reply With Quote