Jump to content

PHP Query


jaykappy
Go to solution Solved by monkeypaw201,

Recommended Posts

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>  

 

 

 
 
Link to comment
Share on other sites

  • Solution

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.