Louie,
I have tried omitting it and also changing it to mysql_link which is defined as all the database info. I have also tried using quotes no quotes and single quotes. I still can't seem to get it to work correctly. In the count(ID) statement is the ID field defined as auto increment?
I will attach what I have written, minus my DB info.
I have set up a table with your elements and am trying to get it to run on that first before I format it for mine.
Cynthia
Do you have any ideas why these lines are having trouble?
$numresults = mysql_query("$countsql", $mysql_link);
$numrows = mysql_result($numresults, 0, num); (54)
AND
$result if (mysql_num_rows($result) > 0) (67)
This is the code. I have not really altered it much so it is still pretty much what you wrote.
<?
// connect to server
$mysql_link = mysql_connect("localhost", "", "");
//select the 'summitdaily_com' database
mysql_select_db("summitdaily_com", $mysql_link);
//Setup initial delimiter
if (eregi("and", $searchwords)) {
$delim = "and";
$takeout = "and";
$boolean = 1;
}
elseif (eregi("or", $searchwords)) {
$delim = "or";
$takeout = "or";
$boolean = 1;
}
else {
$delim = "and";
}
$realsql = "SELECT * FROM listings WHERE ";
$countsql = "SELECT count(ID) as num from listings where ";
if ($boolean == 1) {
$query = eregi_replace("$takeout", ",", $searchwords);
$query = strtolower($query);
$query = split(",", $query);
} else {
$query = strtolower($searchwords);
if (count ($query) == 1) {
$query = split(" ", $query);
}
}
$count = count ($query);
for ($i=0; $i < count ($query); $i++) {
if ($i < (count ($query) - 1)) {
$sql .= '((Name like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(City like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(Type like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(Metawords like \'%'. trim($query[$i]) .'%\')) ';
$sql .= $delim .' ';
} else {
$sql .= '((Name like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(City like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(Type like \'%'. trim($query[$i]) .'%\') OR ';
$sql .= '(Metawords like \'%'. trim($query[$i]) .'%\'))';
}
}
$sql = ereg_replace(".$delim.$", "", $sql);
$statusdo = " AND (status = '1') ";
$countsql = $countsql.$sql.$statusdo;
$limit = 15;
$numresults = mysql_query("$countsql", $mysql_link);
$numrows = mysql_result($numresults, 0, num);
// next determine if offset has been passed to script, if not use 0
if (!isset($offset)) {
$offset=0;
}
$newsql = $realsql.$sql . " AND (status = '1') ORDER by Name LIMIT " . $offset .",". $limit;
$result = mysql_query("$newsql", $mysql_link);
$dbrow1 = "#ffffff";
$dbrow2 = "#eeeeee";
$rowcolor = $dbrow1;
printf('<table width=%s cellspacing=0 cellpadding=6 border=0>', "100%");
printf('<tr><td colspan=2><h1>%s</h1></td></tr>', ucwords($type));
print "<tr><td colspan=2><hr></td></tr>\n";
$result if (mysql_num_rows($result) > 0) {
printf('<tr align="center"><td colspan=2 align="center"><span class="category">%s listings found for %s</span></td></tr>%s', $numrows, $searchwords, "\n");
while ($myrow = mysql_fetch_array($result)) {
if ($myrow["Name"] == "") $myrow["Name"] = ' ';
if ($myrow["Address"] == "") $myrow["Address"] = ' ';
if ($myrow["Phone"] == "") $myrow["Phone"] = ' ';
if ($myrow["map"] == "") {
$maplink = "";
}
else {
$maplink = sprintf('<a href="maps/maptest.php3?id=%s">View on map</a>', $myrow["ID"]);
}
if ($myrow["URL"] == "none") {
print '<tr bgcolor='. $rowcolor .'>';
printf('<td width="%s"><span class="basic"><b>%s</b></span><br><span class="listing-detail">%s</span></td>%s', "70%", $myrow["Name"], $myrow["Address"], "\n");
printf('<td width="%s"><span class="listing-detail">%s</span><br><span class="listing-detail">%s</span><br>%s</td>%s', "30%", $myrow["City"], $myrow["Phone"], $maplink, "\n");
print '</tr>';
}
else {
print '<tr bgcolor='. $rowcolor .'>';
printf('<td width="%s"><a href="http://%s" target="_blank">%s</a><br><span class="listing-detail">%s</span></td>%s', "70%", $myrow["URL"], $myrow["Name"], $myrow["Address"], "\n");
printf('<td width="%s"><span class="listing-detail">%s</span><br><span class="listing-detail">%s</span><br>%s</td>%s', "30%", $myrow["City"], $myrow["Phone"], $maplink, "\n");
print '</tr>';
}
//Change row colors
if ($rowcolor == $dbrow1) {
$rowcolor = $dbrow2;
} else {
$rowcolor = $dbrow1;
}
$i++;
}//End while statement
}//End if statement
else {
printf('<tr><td colspan=2><span class="blue">No listings for %s</span></td></tr>%s', $searchwords, "\n");
}//End else statement
// printf('<tr align="right"><td colspan=2 align="right"><br><a href="%s?city=%s">Return to %s main page</a></td></tr>%s', $PHP_SELF, rawurlencode($city), $city, "\n");
print '</table>';