Jump to content

I can pass a value from a form using a Get method, how to do the same using hype


kee2ka4

Recommended Posts

Hi peeps,

 

I am currently querying a database that displays results on the search.php from index.php. I have a form that uses the "Get" Method and saves the value in "q". Here is my form code:

<form method="get" action="search.php">
      <input id="mainSearchInput" type="text" value="" size="40" name="q"/>
      <input size="40" value="Search" type="submit" />
</form>

 

On presses the "SEARCH", the controller file saves the value of q and queries the database. Here is the php code:

case 'search':

  $q = $_GET['q'];
  $results = find_ad($q);

break;

 

Above code, runs the find_ad($q) function and saves the value in $results and loads the search.php page.

 

 

The above works fine and my question is I would also like to pass the value of q using a hyperlink. So for example if I have the following:

<a href="search.php?q=<?php echo $cat['name'] ?>">

, how can I save the value of "q" from the link to the variable $q in the controller file.

 

Just to be more clear, the get method from the form saves the value of q into variable $q via $q = $GET['q'], my question is if someone clicks the hyperlink how can I save the value of q into the same variable $q.

 

Can someone plz guide me, I hope I am making sense.

 

Thanks,

Zub

Link to comment
Share on other sites

dude i am totally baffled, you are not making sense to me at all. Firstly why do you want to put it into a hyperlink?

Can you also provide us with the code for find_ad() function, maybe it will make more sense.

I do not understand why you cannot insert the value into a hyperlink whereas you already have the value.

Link to comment
Share on other sites

Ok I will explain, I am trying to query the database using two options:

 

1. Search Form, where users can type in a keyword and the function find_ad($q) queries the database and returns a result in form of an array

2. Search Tags, that are hyperlinked. So what I want is clicking on the hyperlinks again runs the fucntion find_ad($q).

 

The user an use "Any" of the two options. Here is my code of function find_ad($q)

function find_ad($query_str = null)
{
  db_connect();
  $select = "SELECT
   				advertdy.id,
   				advertdy.title,
   				advertdy.description,
   				advertdy.price,
   				advertdy.location, ";
   $from = "FROM
   				advertdy ";
   
   $where = "WHERE 
   			advertdy.id > 0 AND advertdy.delete_flag = 0 ";
   
   $order = " ORDER BY advertdy.id DESC";
   if (!empty($query_str))
   {
   		$select .= sprintf("
				match(ad_ID,title,description,location)
				against('%s' IN BOOLEAN MODE)
				as relevance ",
				mysql_real_escape_string($query_str)
				);
		$where .= sprintf("
				AND match(ad_ID,title,location,description) against('%s' IN BOOLEAN MODE) ", 
				mysql_real_escape_string($query_str)
				);
		$order = " ORDER BY relevance DESC";


   }
   
	    
   $query = $select.$from.$where.$order;
   $result = mysql_query($query);
   $result = db_result_to_array($result);
   return $result;
   
}

 

I wanted to know how to pass the value of the search tags (as in the name) into $q variable. So for example if the search tag name is "Test", how do I pass it to the variable $q. My question is related to option 2, how to passes the hyperlink tag name into the function find_ad($q);

 

Thanks,

Zub

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.