kee2ka4 Posted September 10, 2008 Share Posted September 10, 2008 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 https://forums.phpfreaks.com/topic/123575-i-can-pass-a-value-from-a-form-using-a-get-method-how-to-do-the-same-using-hype/ Share on other sites More sharing options...
r-it Posted September 10, 2008 Share Posted September 10, 2008 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 https://forums.phpfreaks.com/topic/123575-i-can-pass-a-value-from-a-form-using-a-get-method-how-to-do-the-same-using-hype/#findComment-638223 Share on other sites More sharing options...
kee2ka4 Posted September 10, 2008 Author Share Posted September 10, 2008 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 https://forums.phpfreaks.com/topic/123575-i-can-pass-a-value-from-a-form-using-a-get-method-how-to-do-the-same-using-hype/#findComment-638265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.