Retrieving rows based on a substring on PHP-MySQL

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, MySQL Tutorial  //  No Comments

how do I retrieve the rows according to the posted string?


<?php
//$query = $_POST['query'];
$query = 'TI';

$conn = mysql_connect($mysql_host, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $conn);

$q=mysql_query("SELECT * FROM productTbl WHERE productName like '$query%'");
while($e=mysql_fetch_assoc($q))
    $output[]=$e;

print(json_encode($output));
mysql_close();
?>

Leave a comment

Share This Post

RSS Wordpress News