Hi guys,
I've just started to get my hands dirty with PHP classes and are having trouble with the following.
Here is my class file: (class_search.php)
<?
class search{
function form_search(){
global $config,$sql,$tableprefix;
$config = new config;
$sql = new sql;
$sql->_select_db($config->dbname);
$keywords = $_POST['keyword'];
$query = "SELECT * FROM ".$tableprefix."keywords WHERE keyword LIKE '%".$keywords."%' ORDER BY price DESC";
$numrows = @$sql->_num_rows($sql->_query($query));
if($numrows > 0){
$result = $sql->_query($query);
?>
<tr>
<td colspan="2" align="left" valign="top">Search results for "<i><? echo $keywords; ?></i>": <b><? echo $numrows; ?></b> matches </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?
while($row = $sql->_fetch_array($result)){
if(is_numeric($row['price'])){$row['price'] = "$" . $row['price'];} // PUT THE $ IN FRONT IF NUMERIC
?>
<tr>
<td width="80%" align="left" valign="top"><? echo $row['keyword']; ?></td>
<td><? echo $row['price']; ?></td>
</tr>
<?
}
}else{
?>
<tr>
<td colspan="2" align="left" valign="top">Your search matched <b>0</b> records.</td>
</tr>
<?
}
}
function category_search(){
global $config,$sql,$tableprefix;
$config = new config;
$sql = new sql;
$sql->_select_db($config->dbname);
$cat = $_GET['category'];
$query = "SELECT * FROM ".$tableprefix."keywords WHERE keyword LIKE '".$cat."%' ORDER BY price DESC";
$numrows = @$sql->_num_rows($sql->_query($query));
if($numrows > 0){
$result = $sql->_query($query);
?>
<tr>
<td colspan="2" align="left" valign="top">Search results for "<i><? echo $cat; ?></i>": <b><? echo $numrows; ?></b> matches </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?
while($row = $sql->_fetch_array($result)){
if(is_numeric($row['price'])){$row['price'] = "$" . $row['price'];} // PUT THE $ IN FRONT IF NUMERIC
?>
<tr>
<td width="80%" align="left" valign="top"><? echo $row['keyword']; ?></td>
<td><? echo $row['price']; ?></td>
</tr>
<?
}
}else{
?>
<tr>
<td colspan="2" align="left" valign="top">There are currently no records for this category.</td>
</tr>
<?
}
}
}
?>
...and here is my index.php where the user puts in a search word and the class begins.
<?
if (isset($_POST['submit']) || isset($_GET['category']) || $_POST['enter_btn'] == 1){
include('class/class_search.php');
$cc = new search($keyword);
?>
<h2>Results</h2>
<b>* </b><?=$cc->form_search(); ?><br><br>
<?
}
?>
<html>
<body>
<table width="540" border="0" align="center">
<tr>
<td align="center"><h2>Keyword Categories</h2></td>
</tr>
<tr>
<td align="center"> [<a href="http://www.adsenseheaven.com" class="link_categories">Home</a>]
<a href="http://www.adsenseheaven.com/index.php?category=a" class="link_categories">A</a>
<a href="index.php?category=b" class="link_categories">B</a>
<a href="index.php?category=c" class="link_categories">C</a>
<a href="index.php?category=d" class="link_categories">D</a>
<a href="index.php?category=e" class="link_categories">E</a>
<a href="index.php?category=f" class="link_categories">F</a>
<a href="index.php?category=g" class="link_categories">G</a>
<a href="index.php?category=h" class="link_categories">H</a>
<a href="index.php?category=i" class="link_categories">I</a>
<a href="index.php?category=j" class="link_categories">J</a>
<a href="index.php?category=k" class="link_categories">K</a>
<a href="index.php?category=l" class="link_categories">L</a>
<a href="index.php?category=m" class="link_categories">M</a>
<a href="index.php?category=n" class="link_categories">N</a>
<a href="index.php?category=o" class="link_categories">O</a>
<a href="index.php?category=p" class="link_categories">P</a>
<a href="index.php?category=q" class="link_categories">Q</a>
<a href="index.php?category=r" class="link_categories">R</a>
<a href="index.php?category=s" class="link_categories">S</a>
<a href="index.php?category=t" class="link_categories">T</a>
<a href="index.php?category=u" class="link_categories">U</a>
<a href="index.php?category=v" class="link_categories">V</a>
<a href="index.php?category=w" class="link_categories">W</a>
<a href="index.php?category=x" class="link_categories">X</a>
<a href="index.php?category=y" class="link_categories">Y</a>
<a href="index.php?category=z" class="link_categories">Z</a>
</td>
</tr>
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center"><h2>Keyword Search</h2></td>
</tr>
<tr>
<td align="center">
<form name="search" method="post" action="index.php">
<input name="keyword" type="text" class="input_box">
<input name="enter_btn" type="hidden" value="1">
<input name="submit" type="submit" class="input_button" value="Search">
</form>
</td>
</tr>
<tr>
<td align="left"></td>
</tr>
</table>
</body>
</html>
My problem is i can't get it to produce the results. The query is fine, i'm just not able to get the classes to start.
Any help much appreciated.
Cheers.