09-28-2005, 10:54 AM
| THREAD STARTER
#9 (permalink)
|
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
| here is the php code... sorry about not including it before. PHP Code: <?php
// search.php
// ok lets get the variables to start off with:
$q = (isset($HTTP_GET_VARS['q'])) ? $HTTP_GET_VARS['q'] : "";
$q = stripslashes($q);
// $country = (isset($HTTP_GET_VARS['c'])) ? $HTTP_GET_VARS['c'] : "";
$title = "PoorDoggie - Search";
if(!empty($q)){ $title .= " '".stripslashes($q)."'"; }
if(empty($q)){
header("Location: ../index.php");
}
// lets now connect to the database:
include "../config.php";
$sql = "SELECT * FROM pd_shops WHERE MATCH (name, description, keywords) AGAINST ('$q' IN BOOLEAN MODE)";
????: NamePros.com http://www.namepros.com/showthread.php?t=127013 $m = 10;
$a = (isset($HTTP_GET_VARS['p'])) ? ($HTTP_GET_VARS['p']-1)*$m : 0;
if(isset($HTTP_GET_VARS['p'])){
$sql .= " LIMIT $a, 10";
}
// $sql = "SELECT * FROM pd_shops WHERE name LIKE '%$q%' OR description LIKE '%$q%' OR keywords LIKE '%$q%' ORDER BY hit_count DESC";
$result = mysql_query($sql);
// here is the content variable:
$content = '<table class="main" width="700">';
$f = 0;
$l = 1;
while($row = mysql_fetch_array($result)){
$content .= '<tr><td rowspan="2" valign="top"><a href="clickthru.php?id=';
$content .= $row['id'];
$content .= '"><img src="';
$content .= $row['image'];
$content .= '" style="border: 0" alt="';
$content .= $row['name'];
$content .= '" /></td><td width="100%" valign="top"><a href="clickthru.php?id=';
$content .= $row['id'];
$content .= '">';
$content .= $row['name'];
$content .= '</a></td></tr><tr><td valign="top" align="justified">';
// $content .= substr($row['description'],0,255);
$content .= $row['description'];
$content .= '...</td></tr><tr><td colspan="2"> </td></tr>';
$l++;
}
$content .= '</table>';
$sql = "SELECT * FROM pd_shops WHERE MATCH (name, description, keywords) AGAINST ('$q' IN BOOLEAN MODE)";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
if(!empty($row['tall_banner'])){
$banners[$f] = $row['tall_banner'];
$url[$f] = $row['url'];
$f++;
}
}
$i = mysql_num_rows($result);
if($i < 1){
$content = "<center><span class=\"main\">Your search returned no results.<br /><br />If you are having trouble try cutting your search queries down to 1 word phrases.</span></center>";
if(isset($banners[0])){
srand((float) microtime() * 10000000);
$rand_keys = array_rand($banners, 1);
$ad = '<a href="';
$ad .= $url[$rand_keys];
$ad .= '"><img border="0" alt="Click Here!" src="';
$ad .= $banners[$rand_keys];
$ad .= '" /></a>';
}
else{
$ad = "";
}
if($i > 10){
$r = $a+$m;
$t = $r-$i;
if(0<$t && $t<10){
$r = $a+($m-$t);
}
$results = "Showing $a-$r of $i results";
}
else{
$results = "Showing $i Results";
}
$p = (isset($HTTP_GET_VARS['p'])) ? $HTTP_GET_VARS['p']++ : "1";
// lets do the page numbers
$nop = $i/$m; // num of pages total (ish)
$pg = 1;
$pages_box = '<select name="pages" id="pages" onChange="location.href=\'index.php?q=';
$pages_box .= $q;
$pages_box .= '&p=\'+this.value">';
while($nop>$pg){
$pages_box .= '<option value="';
$pages_box .= $pg;
$pages_box .= '">';
$pages_box .= $pg;
$pages_box .= '</option>';
$pg++;
}
$pages_box .= '</select>';
$next = $p+1;
$prev = $p-1;
$nav = '<table><tr><td valign="bottom" rowspan="2">';
$nav .= ($p > 1) ? '<a href="index.php?q='.$q.'&p='.$prev.'"><img src="../images/nav/prev.gif" alt="Go back one page..."></a>' : '<img src="../images/nav/prevpaw.gif" alt="PoorDoggie Web Directory">';
$nav .= '</td><td valign="bottom" align="center"><img src="../images/nav/goto.gif" alt="Go to page.."></td><td valign="bottom" rowspan="2">';
$nav .= ($p < $pg) ? '<a href="index.php?q='.$q.'&p='.$next.'"><img src="../images/nav/next.gif" alt="Go back one page..."></a>' : '<img src="../images/nav/nextpaw.gif" alt="PoorDoggie Web Directory">';
$nav .= '</td></tr><tr><td align="center" valign="bottom">'.$pages_box.'</td></tr></table>';
?>
<html>
<head>
<title><?php echo $title; ?></title>
<meta name="description" content="A large web directory with countless sites." />
<meta name="keywords" content="web, directory, search, sites" />
<style>
body{
font-family: arial, tahoma, serif;
font-size: 12px;
}
a, a:visited, a:active{
color: 6c96ba;
}
a:hover{
color: 89ba6c;
text-decoration: none;
????: NamePros.com http://www.namepros.com/showthread.php?t=127013 }
.description, .main{
font-size: 12px;
}
.search{
background: 89ba6c;
}
.query_bar{
background: 6c96ba;
color: #ffffff;
}
img{
border: 0;
}
</style>
</head>
<body onLoad="document.all.q.focus()">
<center>
<table class="main" width="800">
<tr>
<td align="left"><a href="../index.php"><img src="../images/logo.gif" alt="PoorDoggie - The web directory!" /></a></td>
</tr>
<tr>
<form method="get" action="index.php">
<td class="search" width="100%" align="center"><input id="q" name="q" style="width: 254" value="<?php echo stripslashes($q); ?>" /> <input type="submit" value="Search" style="width: 55px;"/></td>
</form>
</tr>
<tr>
<td class="query_bar" align="right">Search results for "<?php echo $q; ?>" - <?php echo $results; ?></td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td valign="top" width="700"><?php echo $content; ?></td>
<td valign="top" align="right"><?php echo $ad; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="center">
<?php echo $nav; ?>
</td>
</tr>
</table>
</center>
</body>
</html> There is an include... will that make more "lines"? When I paste the content of that page into this page then there is just HTML on line 201.
Aha!  I have found the problem!  I was missing a curly bracket here: PHP Code: if($i < 1){
$content = "<center><span class=\"main\">Your search returned no results.<br /><br />If you are having trouble try cutting your search queries down to 1 word phrases.</span></center>";
and now it works... thanks to Axillant's helpful link!  Thanks a lot!
| |
Originally Posted by http://codewalkers.com/tutorials/17/3.html | PHP Code: Parse error: parse error, unexpected ? in ?????????? on line 265
How can this be when the file is only 264 lines long? You've forgotten to close a brace '}' somewhere in your code. Get yourself a editor that can show you where the brace/bracket starts/ends when your cursor is on it. Also, with proper auto-indenting, this should never be an issue.
| |
| |