I am trying to create a search function on my website but I am having some troubles. I received a little help but I do not know if it is necessarily the best way.
I have 2 files – search.html and result.php
search.html contains the form with the instructions to run result.php
Here is the code for result.php
[QUOTE]
<?
$name = $_POST[‘name’];
include “DBConnect.inc.php”;
$sql = “SELECT * FROM tablename WHERE column like ‘%.$name.%’ ORDER BY column “;
$res = mysql_query($sql);
$row = mysql_fetch_array($res, MYSQL_ASSOC);
foreach($row as $r)
{
echo “name = $r”;
}
?>
I have been getting this error when i try to run it
” Warning: Invalid argument supplied for foreach() in /home/buf/public_html/Database/Inspection/result.php on line 12″
Any help with this would be much appreciated.
tablinfo
if (!is_array($trimmed))
{
$kw = $trimm = str_replace(",", " ", $kw);
//echo "and kw is ".$kw. " ";
}
if (!is_array($trimmed))
{
$first_trim = str_replace(",", " ", $trimmed_array['0']);
}
privacy
title
description
keywords
if (!is_array($trimmed))
{
$trimm = str_replace(",", " ", $trimm);
}
else
{
$trimm =preg_replace("/@quote@/"," ",$trimm);
$trimm =preg_replace("/@comma@/",",",$trimm);
}
$trimmed = Key_Fixer($trimmed);
foreach ($trimmed as $keywords)
{
$counting++;
$keywords =preg_replace("/@quote@/"," ",$keywords);
$keywords =preg_replace("/@comma@/",",",$keywords);
$counting++;
}
if (!is_array($trimmed))
{
$trimm = str_replace(",", " ", $trimm);
}
else
{
$trimm =preg_replace("/@quote@/"," ",$trimm);
$trimm =preg_replace("/@comma@/",",",$trimm);
}
$query = "SELECT * FROM 'insert_table_name_here' WHERE (";
if (!is_array($trimmed))
{
$kw = $trimm = str_replace(",", " ", $kw);
}
else
{
$kw =preg_replace("/@quote@/"," ",$kw);
$kw =preg_replace("/@comma@/",",",$kw);
}
if (!is_array($trimmed))
{
$first_trim = str_replace(",", " ", $trimmed_array['0']);
}
else
{
$first_trim = preg_replace("/@quote@/"," ",$trimmed_array['0']);
$first_trim = preg_replace("/@comma@/",",",$first_trim);
}
privacy
title
description
keywords
$row_num_links_main = @mysql_num_rows ($numresults);
// next determine if 's' has been passed to script, if not use 0.
// 's' is a variable that gets set as we navigate the search result pages.
$s = $_GET['s'];
$row_num_links_main<br />";
if (empty($s)) {
$s=0;
}
// now let's get results.
$query .= " LIMIT $s,$limit" ;
$numresults = @mysql_query ($query) or die (COUN_EXEC);
$row= @mysql_fetch_array ($numresults);
do{
$adid_array[] = $row['id'];
}while( $row= @mysql_fetch_array($numresults));
$query_value = "SELECT * FROM 'insert_table_name_here' WHERE id = '$value'";
$num_value= @mysql_query ($query_value);
$row_linkcat= @mysql_fetch_array ($num_value);
$row_num_links= @mysql_num_rows ($num_value);
if($trimm != 'b' ){
$titlehigh = preg_replace( "'($trimm)'si" , "<b>$trimm</b>" , $titlehigh);
$linkhigh = preg_replace( "'($trimm)'si" , "<b>$trimm</b>" , $linkhigh);
$linkdesc = preg_replace( "'($trimm)'si" , "<b>$trimm</b>" , $linkdesc);
$file_name = $row_linkcat[ 'filename' ];
}
echo "<p>";
$next_assur = $counting_links - $s;
$counting_links++;
echo "<br /><u><strong><a href='http://".$row_linkcat[ 'url' ]."/".$row_linkcat[ 'filename' ]."'>".$row_linkcat[ 'title' ]."</a></strong></u><br />";
echo $linkdesc."...</p>";
echo "<p style='color: #f00;'>".$linkhigh."</p><br />";
if($row_num_links_main > $limit)
{
echo "<table style='text-align: center; margin: auto;' cellspacing='10px'><tr>";
if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1 && ($argh - $s) == $limit) {
// not last page so display next link
$n=$s+$limit;
echo "<td><a href='$PHP_SELF?s=$n&q=$var&catid=$catid'> ".NEXT." >> </a></td>";
}
echo "</tr></table>";
}
$kw[$T] = $tryit;
if ($kw[$T] == $eye[$T])
{
$kw[$T]= preg_replace("/(s)+/","@quote@",$kw[$T]); //The quotes will be @quote@ between their spaces.
$kw[$T]= preg_replace("/(,)+/","@comma@",$kw[$T]);
}
$str2 .=$kw[$T]; //$str2 becomes the new version of the original $str string.
$T++;
You think it is a mess? Imagine how long it'd take me to explain it all, as I took two different tutorials and put them together to come out with all that code.[/QUOTE]However much effort you make it is all for nothing if you don't use the forum's built in code formatting as no one will bother reading it.
In this case, it is just a matter of copy/paste mostly.?[/QUOTE]Oh dear! Haven't you ever wondered why most people's code is nicely highlighted in the forum and yours is not? It's because they use the PHP code tags.
0.1.9 — BETA 6.17