BigX Posted March 31, 2008 Share Posted March 31, 2008 Hi guys, I'm working on a search engine! This code is what I got so far and i don't quite understand why I'm not getting any results from my SQL database! Even when my SearchString is a word that is used a lot in my database! <?php require_once('Connections/socialekaart.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? 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; } } $SearchString_rsSearchResults = "-1"; if (isset($_GET['SearchString'])) { $SearchString_rsSearchResults = $_GET['SearchString']; } mysql_select_db($database_socialekaart, $socialekaart); $query_rsSearchResults = sprintf("SELECT * FROM organisaties WHERE Organisatie like %s OR Algemenebeschrijving like %s OR Trefwoorden like %s ORDER BY Organisatie ASC", GetSQLValueString("%" . $SearchString_rsSearchResults . "%", "int"),GetSQLValueString("%" . $SearchString_rsSearchResults . "%", "int"),GetSQLValueString("%" . $SearchString_rsSearchResults . "%", "int")); echo $query_rsSearchResults; $rsSearchResults = mysql_query($query_rsSearchResults, $socialekaart) or die(mysql_error()); $row_rsSearchResults = mysql_fetch_assoc($rsSearchResults); $totalRows_rsSearchResults = mysql_num_rows($rsSearchResults); ?><?php require_once('Connections/socialekaart.php'); mysql_select_db("sociale_kaart"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Zoekresultaten</title> </head> <body> <p>Zoekresultaten voor: <?php echo $_GET['SearchString']; ?></p> <p> </p> <table> <tr> <td>id</td> <td>Categorie</td> <td>Subcategorie</td> <td>Organisatie</td> <td>Adres</td> <td>Telefoonnummer</td> <td>Fax</td> <td>Website</td> <td>Emailadres</td> <td>Openingstijden</td> <td>Algemenebeschrijving</td> <td>Trefwoorden</td> </tr> <?php do { ?> <tr> <td><?php echo $row_rsSearchResults['id']; ?></td> <td><?php echo $row_rsSearchResults['Categorie']; ?></td> <td><?php echo $row_rsSearchResults['Subcategorie']; ?></td> <td><?php echo $row_rsSearchResults['Organisatie']; ?></td> <td><?php echo $row_rsSearchResults['Adres']; ?></td> <td><?php echo $row_rsSearchResults['Telefoonnummer']; ?></td> <td><?php echo $row_rsSearchResults['Fax']; ?></td> <td><?php echo $row_rsSearchResults['Website']; ?></td> <td><?php echo $row_rsSearchResults['Emailadres']; ?></td> <td><?php echo $row_rsSearchResults['Openingstijden']; ?></td> <td><?php echo $row_rsSearchResults['Algemenebeschrijving']; ?></td> <td><?php echo $row_rsSearchResults['Trefwoorden']; ?></td> </tr> <?php } while ($row_rsSearchResults = mysql_fetch_assoc($rsSearchResults)); ?> </table> </body> </html> <?php mysql_free_result($rsSearchResults); ?> [/Code] I put in echo $query_rsSearchResults; to see which sql query is actuallu used and I get: SELECT * FROM organisaties WHERE Organisatie like 0 OR Algemenebeschrijving like 0 OR Trefwoorden like 0 ORDER BY Organisatie ASC Why the '0's?? There should be the words that are searched for!! Anyone? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/98803-dont-get-results-from-my-sql-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.