jaykappy Posted March 20, 2013 Share Posted March 20, 2013 I have a php page that has a search input box on it. When the user enters a search value and clicks a search link it passes the value to another page and runs a query. This works great. But when I am on that new page and run the query again it returns all the records not the ones that would be returned from the new Query value. Wondering if I need to clear something, set to null etc.... I tried to show as much code as I can.... IF I GO back to the mainPageIndex and do the seach again it runs fine.....it ONLY breaks when I try to run again from the MainPageIindexSearch page.... MainPageIndex.php <script type="text/javascript"> window.onload = function() { $(".Searchbutton").click(function(){ if( !$('#searchvalue').val() ) { alert("Please Enter a Search Value"); } else{ window.location.href = "/MainPageindexSearch.php?ItemValue=" + $("#searchvalue").val(); } }); </script> <h2 id="headerLogin"> <span id="SpanDepartment"><a href="javascript:;"><img src="img/Search.gif" align="center" border="0" Class="Searchbutton"></a></span> <span id="SpanDepartment"><input id="searchvalue" type="text" name="Search" value="" placeholder="Search Value"/> </span> <span id="SpanDepartment"> <?php echo $_GET["Dept"]; ?></span> </h2> MainPageindexSearch.php <script type="text/javascript"> window.onload = function() { $(".NewSearchbutton").click(function(){ if( !$('#Newsearchvalue').val() ) { alert("Please Enter a Search Value"); } else{ window.location.href = "/MainPageindexSearch.php?Value=" + $("#Newsearchvalue").val(); $('#resulttable2').show(500); $('.hide2').show(500); } }); } </script> <?php $query = " SELECT Id,Yr,ProjectName,Department,Owner,MaplibraryName, Description,MaplibraryPath,PageSize,Scale,LastModified, Notes,ModifiedBy,FullPath,Path_jpg,PDF_Path,JPG_Path FROM tbl_maplibrary WHERE Description LIKE :Values OR MaplibraryName LIKE :Values ORDER BY Yr DESC "; $stmt = $db->prepare($query); $searchValue = trim($_GET['ItemValue']); $stmt->execute(array(":Values" => "%{$searchValue}%" )); $rows = $stmt->fetchAll(); ?> <h2 id="headerLogin"> <span id="SpanDepartment"><a href="javascript:;"><img src="img/Search.gif" align="center" border="0" Class="NewSearchbutton"></a></span> <span id="SpanDepartment"><input id="Newsearchvalue" type="text" name="NewSearch" value="" placeholder="Search Value"/> </span> <span id="SpanDepartment"> <?php echo $_GET["Dept"]; ?></span> </h2> <table id="resulttable" class="hide"> <tr> <th></th> <th></th> <th>Ids</th> <th>Year</th> <th>MapLibrary Name</th> <th>Description</th> </tr> <?php foreach($rows as $row): ?> <tr class="listRow2" > <td><input type="button" style="padding:2px 5px 2px 5px;" Class="modifybuttonimg" /></td> <td id="imagehover" style="padding:5px 4px 2px 5px;" width="25"><a href="<?php echo htmlentities($row['PDF_Path'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank"><img src="<?php echo htmlentities($row['JPG_Path'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank" alt=" " border="1" height="20" width="20"></a></td> <td width="15"><?php echo htmlentities($row['Id'], ENT_QUOTES, 'UTF-8'); ?></td> <td width="10"><?php echo htmlentities($row['Yr'], ENT_QUOTES, 'UTF-8'); ?></td> <td width="360"><?php echo htmlentities($row['MaplibraryName'], ENT_QUOTES, 'UTF-8'); ?></td> <td width="395"><?php echo htmlentities($row['Description'], ENT_QUOTES, 'UTF-8'); ?></td> </tr> <?php endforeach; ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/275921-php-query/ Share on other sites More sharing options...
Solution monkeypaw201 Posted March 20, 2013 Solution Share Posted March 20, 2013 Right off the bat, I see window.location.href = "/MainPageindexSearch.php?ItemValue=" + $("#searchvalue").val(); and window.location.href = "/MainPageindexSearch.php?Value=" + $("#Newsearchvalue").val(); Shouldn't these be the same? Otherwise you're looking for a value that doesn't exist? Quote Link to comment https://forums.phpfreaks.com/topic/275921-php-query/#findComment-1419820 Share on other sites More sharing options...
jaykappy Posted March 20, 2013 Author Share Posted March 20, 2013 monkeypaw201.....AWESOME!!!!!......thanks man... must have been over that code 500 times... It was the ItemValue and Value....both needed to be ItemValue.... Cheers.....thanks for the extra set of eyes..... Quote Link to comment https://forums.phpfreaks.com/topic/275921-php-query/#findComment-1419896 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.