chrispulliam Posted June 13, 2012 Share Posted June 13, 2012 I have the following two statements in php that I am trying to pass to my database. If I perform a search for Test One with the first statement It displays all entries that have Test One as well as Test Two Test Three and so forth. I then try statement 2 and it does not show me any results. If I Hard code Test One in the search succeeds successfully. What am I doing wrong? Statement 1 "SELECT * FROM media WHERE (program_name LIKE '%$program_name%')" > Statement 2 "SELECT * FROM media WHERE (program_name = '%$program_name%')" Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 13, 2012 Share Posted June 13, 2012 #2 has wild car operators in them, and the equal sign comparison doesn't support wild cards so, that is what it is searching for something that has % on the ends of what $program_name is. remove them and you should get what you are looking for Quote Link to comment Share on other sites More sharing options...
smoseley Posted June 14, 2012 Share Posted June 14, 2012 show your php and your data. Quote Link to comment Share on other sites More sharing options...
chrispulliam Posted June 14, 2012 Author Share Posted June 14, 2012 Here is my code <?php require_once('../Connections/umdb.php'); ?> <?php require("../Connections/grab_globals.inc.php3") ?> <?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_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; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_processing = 10000000; $pageNum_processing = 0; if (isset($_GET['pageNum_processing'])) { $pageNum_processing = $_GET['pageNum_processing']; } $startRow_processing = $pageNum_processing * $maxRows_processing; $program_name = $_POST['program_name']; $colname_processing = "-1"; if (isset($_GET['No'])) { $colname_processing = $_GET['No']; } mysql_select_db($database_umdb, $umdb); $query_processing = "SELECT * FROM media WHERE (program_name LIKE '%$program_name%')"or die(mysql_error()); $query_limit_processing = sprintf("%s LIMIT %d, %d", $query_processing, $startRow_processing, $maxRows_processing); $processing = mysql_query($query_limit_processing, $umdb) or die(mysql_error()); $row_processing = mysql_fetch_assoc($processing); if (isset($_GET['totalRows_processing'])) { $totalRows_processing = $_GET['totalRows_processing']; } else { $all_processing = mysql_query($query_processing); $totalRows_processing = mysql_num_rows($all_processing); } $totalPages_processing = ceil($totalRows_processing/$maxRows_processing)-1; $queryString_processing = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_processing") == false && stristr($param, "totalRows_processing") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_processing = "&" . htmlentities(implode("&", $newParams)); } } $queryString_processing = sprintf("&totalRows_processing=%d%s", $totalRows_processing, $queryString_processing); ?> <?php require_once('../auth.php'); ?> <!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=iso-8859-1" /> <title> user Page</title> <link href="../loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Welcome <?php echo $_SESSION['SESS_NAME'];?></h1> <p><a href="users">Home</a> | <a href="admin">Admin</a> | <a href="logout.php">Logout </a> <form action="reports.php" method="post"> <? $query="SELECT * FROM programs"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=program_name value=''></option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[Title]>$nt[Title]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?></p> <p><br /> <input type="submit" name="submit" value="Submit" /> </p> </form> <p> </p> <p> Records <?php echo ($startRow_processing + 1) ?> to <?php echo min($startRow_processing + $maxRows_processing, $totalRows_processing) ?> of <?php echo $totalRows_processing ?> </p> <table border="1" align="center"> <tr> <td>media_number</td> <td>date_entering</td> <td>program_name</td> <td>program_num</td> <td>comments</td> </tr> <?php do { ?> <tr> <td><a href="users/detail.php?media_number=<?php echo $row_processing['media_number']; ?>"> <?php echo $row_processing['media_number']; ?> </a></td> <td><?php echo $row_processing['date_entering']; ?> </td> <td><?php echo $row_processing['program_name']; ?> </td> <td><?php echo $row_processing['program_num']; ?> </td> <td><?php echo $row_processing['comments']; ?> </td> </tr> <?php } while ($row_processing = mysql_fetch_assoc($processing)); ?> </table> <br /> </body> </html> <?php mysql_free_result($processing); ?> Quote Link to comment Share on other sites More sharing options...
chrispulliam Posted June 14, 2012 Author Share Posted June 14, 2012 @The Little Guy I tried to remove the % and it did not work. Quote Link to comment Share on other sites More sharing options...
chrispulliam Posted June 14, 2012 Author Share Posted June 14, 2012 Here was my issue. Thanks guys for your help! echo "<option value='$nt[Title]'>$nt[Title]</option>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.