Im trying to make a mysql search with php. I get to search the database then display the text.
The only thing is, if it finds somthing it will just place everything from the database out on the page, if it doesnt find anything, nothing shows (which is what is supposed to do)
heres my code... kinda long:
<?
include('header.php');
include('cfg.php');
$query2 = explode(" ",searchtxt);
for($i=0;$i<count($searchtxt);$i++){
if (strstr($str,$searchtxt[$i]) && $searchtxt[$i]!="")
print $query2[$i]." is into the string!";
$limit=20; // rows to return
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
$goconnect5 = mysql_connect($db_connetion, $db_username, $db_password) or die ("<span class='titel'>Couldnt connect</span>");
$godb5 = mysql_select_db($db_databse, $goconnect5) or die ("<span class='titel'>Couldnt open Database</span>");
$gosql5 = "SELECT * from code WHERE Cpname LIKE '%$query2[i]%' and Cpdec LIKE '%$query2[i]%' order by Cid";
$gosql_result5 = mysql_query($gosql5, $goconnect5) or die ("<span class='titel'>Couldnt connect!</span>");
$result = mysql_query($gosql5, $goconnect5) or die("Could not execute query.");
}
##################################
## Array from database
##################################
while ($row2 = mysql_fetch_array($result)){
$title = $row2["Cpname"];
$doc = $row2["Cpdec"];
$id = $row2["Cid"];
$user_name = $row2["Cuser_name"];
$date = $row2["Cdate"];
$selected = $row2["Cselect2"];
$text = wordwrap( $doc, 20 );
$rest = substr($text, 0, 500);
$rest2 = "$rest...";
?> <br>
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="84%">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#000000">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="58%" align="left" valign="top" class="news">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td class="news">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td align="left" valign="middle"><img src="small.gif" width="26" height="27"><a href="read.php?id=<? echo "$id"; ?>" class="newsheader2">
<? echo "$title"; ?>
</a></td>
</tr>
<tr>
<td bgcolor="<? echo "$row_color"; ?>" class="signup"><span class="newsheader"> By:</span>
<a href="profile.php?name=<? echo "$user_name"; ?>">
<? echo "$user_name"; ?>
</a><span class="newsheader"> Date:</span>
<font color="red">
<? echo "$date"; ?>
</font> <br>
<span class="newsheader"> </span><br>
<? echo "$rest2"; ?>
</td>
</tr>
<tr>
<td bgcolor="#000000" class="signup">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="80%" bgcolor="#CCCCCC" class="signup"><span class="newsheader"> Category:</span>
<a href="cat.php?cat=<? echo "$selected"; ?>">
<? echo "$selected"; ?>
</a></td>
<td width="20%" align="left" valign="middle" bgcolor="#CCCCCC">
<div align="center"> <span class="newsheader">[Read
More] </span></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<?
}
?>
to see it in action go here
http://rbcode.com/category.php?d=1