Jump to content

Searching a mysql database


senyo

Recommended Posts

I am using this but I am getting a blank screen

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;


Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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;
  }


?>

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.