PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Last edited by Benjamin on Mon Nov 14, 2011 6:19 am, edited 1 time in total.
Reason:Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$search_output = "";
if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']);
$sqlCommand = "SELECT nid, title AS title FROM node WHERE title LIKE '%$searchquery%' OR type LIKE '%$searchquery%'";
include_once("connect_to_mysql.php");
$query = mysql_query($sqlCommand) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 0){
$search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />";
while($row = mysql_fetch_array($query)){
$id = $row["nid"];
$title = $row["title"];
$search_output .= "$id - $title<br />";
} // close while
} else {
$search_output = "<hr />0 results for <strong>$searchquery</strong><hr />";
}
}
?>
<html>
<head>
</head>
<body>
<h2>Search the Exercise Tables</h2>
<form action="http://www.bertgroup.co.uk/?q=node/12" method="post">
Search cars:
<input name="searchquery" type="text" size="44" maxlength="88">
<input name="myBtn" type="submit">
<br />
</form>
<div>
<a href='?q=node/><?php echo $id; ?>.html'><?php echo $search_output; ?></a>
</div>
</body>
</html>
Last edited by Benjamin on Wed Nov 16, 2011 4:29 am, edited 1 time in total.
Reason:Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.