plodos Posted October 6, 2008 Share Posted October 6, 2008 $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? Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 6, 2008 Share Posted October 6, 2008 <?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; ?> Quote Link to comment Share on other sites More sharing options...
plodos Posted October 6, 2008 Author Share Posted October 6, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Share Posted October 6, 2008 echo $query and post with what is says. Quote Link to comment Share on other sites More sharing options...
plodos Posted October 6, 2008 Author Share Posted October 6, 2008 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"); Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 6, 2008 Share Posted October 6, 2008 $data = mysql_query(qry) or die (mysql_error ()."<br>Qry: $qry"); You missed your "$" before qry in mysql_query(qry) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.