Jump to content

search URL


cdoggg94

Recommended Posts

I am trying to get a search form's action to be a link that goes like this:

MYSITE.com/cTrends/Agent/results.php?Details=78&findthis=jackson&submit=Search

 

this is my form:

<form id="form1" name="form1" method="get" action="results.php?Details=<?php echo $detnum ;?>">
   //$detnum in this case is = 78..

    <label>    </label>
    <table border="0">
      <tr>
      <td>
        
          <div align="center"><br />
            <input name="findthis" type="text" id="findthis" size="15" />
            <input type="submit" name="submit" id="submit" value="Search" />
          </div></td>
      
      </tr>
      </table>
</form>

 

my problem is that the "?Details=78" will not display...

 

any ideas why ?

 

did I just do it wrong? or is it no possible?

 

im a little confused because when i press submit, the search works fine and if i manually type in the Details part it works too, but it wont print it when I hit submit..

Link to comment
Share on other sites

If you look at the page source, you'll probably see that the ?details=78 isn't even in the action= attribute of the form. I haven't researched the technical explanation for that, but I'm sure it has something to do with using query string parameters when the form's method is get. You can use a hidden form field, or even a session variable for the value though.

Link to comment
Share on other sites

Try somthing like this...

<form class="search" method="get" action="search.php?Search">        
            <input type="text" name="Search" size="50" />
            <a href="document.getElementById('search').submit('search')">Search</a>
</form>

Link to comment
Share on other sites

Are you sure... if you type something in the search bar like your "78" it should redirect you to "search.php?Search=78" to get the url you want try...

<form class="search" method="get" action="search.php?details=<? echo $detnum;?>&Search">        
            <input type="text" name="Search" size="50" />
            <a href="document.getElementById('search').submit('search')">Search</a>
</form>

this will redirect you to the url if you typed is the search box "jackson" "search.php?details=78&search=jackson"

Link to comment
Share on other sites

If you are doing a MySQL database search remember to do this for each $_GET

$search = mysql_real_escape_string($_GET[search]);
$details = mysql_real_escape_string($_GET[details]);

then for example use RLIKE

SELECT * FROM 'table' WHERE 'user' RLIKE '$search' OR 'id' RLIKE '$details'

hope this helps

Link to comment
Share on other sites

my results looks like this from the form above...

 

<?php

$mysearch = $_GET['findthis'];
//echo $mysearch;
mysql_select_db($database_TrendConnect);

$q = "SELECT * FROM Sheet1 WHERE pro_name LIKE '%" . mysql_real_escape_string($mysearch) . "%' OR lcbo_num LIKE '%" . mysql_real_escape_string($mysearch) . "%' ORDER BY pro_name ASC";

$mystuff = mysql_query($q);
$num_rows = mysql_num_rows($mystuff);

if($num_rows >= 1){
echo "<span class='Graphtitle'>There were ".$num_rows." results for your search!</span><br /><br />";

while($row = mysql_fetch_assoc($mystuff)) {
echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo "http://www.MYSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row['pro_name']."</a>     <span class='LTOlist'>".$row['F7']."</span><br /></td></tr></table>";
}
}

if($num_rows == 0){
echo "<span class='Graphtitle'>There were no results for your search</span>";
}

?>

 

$findthis would be "$search" on your example...i dont know how or where to add the "details" part in it when i need it in the URL of this page...sorry if thats a really dumb thing to say...im a little confused :(

Link to comment
Share on other sites

I don't know what your trying to accomplish with details and wouldn't it be easier to retrieve the details from the database anyway I edited your code...

 

<?php

$mysearch = mysql_real_escape_string($_GET['findthis']);
//echo $mysearch;
mysql_select_db($database_TrendConnect);

$q = "SELECT * FROM Sheet1 WHERE pro_name RLIKE '$mysearch' OR lcbo_num RLIKE '$mysearch' ORDER BY pro_name ASC";

$mystuff = mysql_query($q);
$num_rows = mysql_num_rows($mystuff);

if($num_rows >= 1){
echo "<span class='Graphtitle'>There were ".$num_rows." results for your search!</span><br /><br />";

while($row = mysql_fetch_array($mystuff)) {
echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo "http://www.MYSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row['pro_name']."</a>     <span class='LTOlist'>".$row['F7']."</span><br /></td></tr></table>";
}
}elseif($num_rows == 0){
echo "<span class='Graphtitle'>There were no results for your search</span>";
}

?>

RLIKE means Regular expression LIKE so if you have the name jamie and jam in the database and you searched for jam the results will show both jamie and jam if you used the LIKE you would only get jam, and with LIKE it is case sensitive so if you searched Jam you would get no results

Link to comment
Share on other sites

I am going to try that new code right now....

 

The details thing retrieves a clients information from a different table on the data base that I need to display, and when I'm done on the search page they would press back and I want to send back to the original page they were on...

 

Thanks again for your help

Link to comment
Share on other sites

I think that you are right though..

 

something like this should work :

 

<form class="search" method="get" action="search.php?details=<? echo $detnum;?>&Search">        
            <input type="text" name="Search" size="50" />
            <a href="document.getElementById('search').submit('search')">Search</a>
</form>

 

the only problem is that it doesnt use that as a link...i just looked up something and it wanted me to make a JS function and then give the <a id=""> the element from the function

 

like this:

 

<script type="text/javascript">

function changeLink()
{
document.getElementById('MyLink').innerHTML="Bookmark me!";
document.getElementById('MyLink').href="javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit()";
document.getElementById('MyLink').target="_blank";
}
</script>


<body onload changeLink();>

<a id="MyLink" href="http://www.JustaLink.com">Just A Link</a>

 

does that seem correct ?

 

is so i can probably edit it to work for me...

Link to comment
Share on other sites

If you look at the page source, you'll probably see that the ?details=78 isn't even in the action= attribute of the form. I haven't researched the technical explanation for that, but I'm sure it has something to do with using query string parameters when the form's method is get. You can use a hidden form field, or even a session variable for the value though.

Link to comment
Share on other sites

What Pik is telling you, but you don't seem to understand, is:

<form id="form1" name="form1" method="get" action="results.php">
   //$detnum in this case is = 78..

    <label>    </label>
    <table border="0">
      <tr>
      <td>
        
          <div align="center"><br />
            <input name="Details" type="hidden" value="<?php echo $detnum ;?>" />
            <input name="findthis" type="text" id="findthis" size="15" />
            <input type="submit" name="submit" id="submit" value="Search" />
          </div></td>
      
      </tr>
      </table>
</form>

Link to comment
Share on other sites

Well i have figured it out...

 

<form id="form1" name="form1" method="get" action="results.php">
   
    <label>    </label>
    <table border="0">
      <tr>
      <td>
        
          <div align="center">
            <input type="hidden" name="Details" id="Details" value="<?php echo $detnum ;?>" />
            <br />
            <input name="findthis" type="text" id="findthis" size="15" />
            <input type="submit" name="submit" id="submit" value="Search" />
          </div></td>
      
      </tr>
      </table>
</form>

 

i took all the JS out.  I think someone had said something about a hidden field and I went that way and it seems to work exactly how i want it to

 

 

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.