Jump to content

What must I write for search in the all mysql fields?


plodos

Recommended Posts

$query = "select * from t_table where $type like '%$search%' AND date < NOW() - INTERVAL 70 HOUR";

I want to search in the all fields like

$query = "select * from t_table where [color=red]ALL_FIELDS[/color] like '%$search%' AND date < NOW() - INTERVAL 70 HOUR";

 

these are my fields

lname

fname

university

university_dept

country

tel

fax

.......

What must I write for search in the all fields?

<?php
$columns = array();
$columns[] = "lname";
$columns[] = "fname";
$columns[] = "university";
$columns[] = "university_dept";
$columns[] = "country";
$columns[] = "tel";
$columns[] = "fax";

$search = "search string";

$query = "select * from t_table where (";
foreach($columns as $value)
{
$query .= $value . " LIKE '%$search%' OR ";
}
$query = substr($query, 0, -4) . ") AND date < NOW() - INTERVAL 70 HOUR";
echo $query;

?>

<?php
include("dbconfig.php");
function title_case($title) {
}


$columns = array();
$columns[] = "lname";
$columns[] = "fname";
$columns[] = "university";
$columns[] = "university_dept";
$columns[] = "country";
$columns[] = "research_field";
$columns[] = "address";

$search = (isset($_POST['search'])) ? $_POST['search'] : $_GET['search'];
$search = mysql_real_escape_string($search);

$page = $_GET["page"]; 
if(empty($page) or !is_numeric($page)){ 
$page = 1;
}

$limit = 25; 

$query = "select * from person where (";
foreach($columns as $value)
{
   $query .= $value . " LIKE '%$search%' OR ";
}
$query = substr($query, 0, -4) . ") AND date < NOW() - INTERVAL 70 HOUR";

$result1 = mysql_query($query) or die (mysql_error ()."<br>Query: $query");
$satirsayisi = mysql_num_rows($result1); 

$sayfasayisi = ceil($satirsayisi / $limit); 
$baslangic = ($page-1)*$limit; 


$qry = "select * from person where (";
foreach($columns as $value)
{
   $query .= $value . " LIKE '%$search%' OR ";
}
$query = substr($query, 0, -4) . ") AND date < NOW() - INTERVAL 70 HOUR ORDER BY lname ASC LIMIT $baslangic,$limit";

$data = mysql_query(query) or die (mysql_error ()); 

                     
while($info=mysql_fetch_array($data))
{
	if($info['committee_no']=="1")
	{
	echo "			<font face=\"Verdana\"><br>";
        echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']."  <br>";
        echo title_case($info['university'])." <br>";
        echo title_case($info['university_dept'])." <br>";
	echo"			 </font>";
	}

}


if($page > 1){ 
$back = $page-1;
echo "<p align=\"center\"><b><a href=\"search.php?page=$back&search=$search\"><< Back </a>";
}else{ 

echo "<p align=\"center\"><b> << Back ";
}

echo " | ";

if($page>=$sayfasayisi){ 

echo "Next >> </b></p>";

}else{ 

$next = $page+1;

echo "<a href=\"search.php?page=$next&search=$search\">Next >></a></b></p>";
}
?> 

 

I wrote the same queries but I didnt solve the errors & wornings.

 

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'query' at line 1"

 

what are the problems? I didnt find.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'qry' at line 1

Qry: select * from person where (lname LIKE '%%' OR fname LIKE '%%' OR university LIKE '%%' OR university_dept LIKE '%%' OR country LIKE '%%' OR research_field LIKE '%%' OR address LIKE '%%') AND date < NOW() - INTERVAL 70 HOUR ORDER BY lname ASC LIMIT 0,25

 

I changed only these codes...JUST 2 QUERIES...but problems :S

$query = "select * from person where (";
foreach($columns as $value)
{
   $query .= $value . " LIKE '%$search%' OR ";
}
$query = substr($query, 0, -4) . ") AND date < NOW() - INTERVAL 70 HOUR";

$result1 = mysql_query($query) or die (mysql_error ()."<br>Query: $query");
$satirsayisi = mysql_num_rows($result1); 

$sayfasayisi = ceil($satirsayisi / $limit); 
$baslangic = ($page-1)*$limit; 


$qry = "select * from person where (";
foreach($columns as $value)
{
   $qry .= $value . " LIKE '%$search%' OR ";
}
$qry = substr($qry, 0, -4) . ") AND date < NOW() - INTERVAL 70 HOUR ORDER BY lname ASC LIMIT $baslangic,$limit";

$data = mysql_query(qry) or die (mysql_error ()."<br>Qry: $qry"); 

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.