Jump to content

simple search question


Jarel101

Recommended Posts

I've created a keyword mysql search, it almost works perfect. The only problem is when I don't enter a keyword into the search form and leave it blank and click the search button, I get the data from my DB table, even though I didn't enter anything in the text box? When I enter a word that's not a keyword I just get a blank page. I would like to code it in away where when I don't enter anything and hit search or enter a keyword that I haven't added, I get a message that says "no results were found" or anything to that effect. My question is how do I do this?

 

HERES MY CODE:

 

SEARCH RESULTS PAGE:

 

<?php require_once('Connections/MyConnection.p… ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

if (PHP_VERSION < 6) {

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

}

 

$theValue = function_exists("mysql_real_escape_strin… ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

 

$maxRows_Recordset1 = 3;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

 

$colname_Recordset1 = "-1";

if (isset($_GET['title'])) {

$colname_Recordset1 = $_GET['title'];

}

mysql_select_db($database_MyConnection… $MyConnection);

$query_Recordset1 = sprintf("SELECT * FROM images2 WHERE key_words LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $MyConnection) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

 

if (isset($_GET['totalRows_Recordset1'])) {

$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

$all_Recordset1 = mysql_query($query_Recordset1);

$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Reco…

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<table>

<tr>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<?php do { ?>

<tr>

 

<td><a href="viewimage.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="<?php echo $row_Recordset1['Layouts']; ?>" width="300" height="250" /></a></td>

<td width="300" height="250" align="center"><?php echo $row_Recordset1['Descriptions']; ?></td>

 

</tr>

<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

</table>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...