Jump to content

Searching a mysql database


senyo

Recommended Posts

Hi I am stupid and I can't search a database, everything I tried doesn't work, I want to search the table client, field name.

mysql_connect(HOST, USERNAME, PASSWORD);
mysql_select_db(DB NAME)

$qry = "SELECT name FROM client";
$result = mysql_query($qry);

mysql_connect("localhost","2","2");

mysql_select_db("book");
$each="john";
$qry = "SELECT FROM client WHERE client.name LIKE '%".$each."%' ";
$result = mysql_query($qry);

echo $result;

 

WHERE and LIKE have to be in caps.

mysql_connect("localhost","2","2");

mysql_select_db("book");
$each="john";
$qry = "SELECT FROM client WHERE client.name LIKE '%".$each."%' ";
$result = mysql_query($qry);

echo $result;

 

WHERE and LIKE have to be in caps.

 

No they don't.  The problem is that you're not SELECTing anything.  Moving to MySQL Help section.

I have this and it shows no errors only this: Resource id #4Resource id #5

how to make it show the whole entry?

mysql_connect("localhost","2","2");

mysql_select_db("book");
$each="john";
$qry = "SELECT * FROM client WHERE client.name LIKE '%".$each."%'";
$result = mysql_query($qry);


$eror= mysql_query($qry) or die(mysql_error()); 
$sebuty=$result['name'];
echo $sebuty;
echo $result;

echo $eror;


mysql_connect("localhost","2","2");

mysql_select_db("book");
$each="john";
$result= "SELECT * FROM client WHERE client.name LIKE '%".$each."%'";
while($row = mysql_fetch_array($result))
  {
  $sebuty= $row['name'];
  }
echo $sebuty;
echo $result;

echo $eror;

 

Need to fetch the information.

http://php.net/manual/en/function.mysql-fetch-array.php

 

$result= "SELECT * FROM client WHERE client.name LIKE '%".$each."%'";
while($row = mysql_fetch_array($result))

 

should be:

 

$sql= "SELECT * FROM client WHERE client.name LIKE '%".$each."%'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))

 

You should also add in some error handling.  Read this blog for more details:

http://www.phpfreaks.com/blog/or-die-must-die

Thanks it work

 

<?php

mysql_connect("localhost","2","2");

mysql_select_db("book");
$each="john";
$sql= "SELECT * FROM client WHERE client.name LIKE '%".$each."%'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
  {
  $fromdatabase= $row['name'];
  echo $fromdatabase;
  }


?>

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.