Jump to content

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


?>

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.