MDanz Posted August 6, 2009 Share Posted August 6, 2009 How do i add a search loop to my page. I've got radio buttons for multiple searches. These buttons position results in different places. But when i search for something new the results starts again, when the old results should stay. How do i add a loop, so old results stay? Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/ Share on other sites More sharing options...
waynew Posted August 6, 2009 Share Posted August 6, 2009 Post code. Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892420 Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 ummmmm.. hmmm... any code? I'm guessing its because each is its own form.. I guess if you send the whole lot as a form instead of individual forms then did a whole huge search instead of individual oens then grouped the data, then displayed then it might work Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892422 Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 if your database is indexed properly (has an ID number/something that is incremented with each entry), you could append to the end of the search url lid=## lid being the last ID on the page. That way you know to tell the SQL to start from lid+1. It's ugly, but it would do what you are asking. Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892428 Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 <form action='search.php' method='get'> <center> <input type='text' size='25' name='search'> <input type='submit' name='submit' Value='search' > <label><font color=white>1</font> <input type="radio" name="RadioGroup1" value="1" /> </label> <label><font color=white>2</font> <input type="radio" name="RadioGroup1" value="2" /> </label> <label><font color=white>3</font> <input type="radio" name="RadioGroup1" value="3" /> </label> <label><font color=white>4</font> <input type="radio" name="RadioGroup1" value="4" /> </label> <label><font color=white>5</font> <input type="radio" name="RadioGroup1" value="5" /> </label> <label><font color=white>6</font> <input type="radio" name="RadioGroup1" value="6" /> </label> <label><font color=white>7</font> <input type="radio" name="RadioGroup1" value="7" /> </label> <label><font color=white>8</font> <input type="radio" name="RadioGroup1" value="8" /> </label> </center> </form> <style type="text/css"> <!-- body { background-color: #000000; font color:#FFFFFF; } #Layer1 { position:absolute; width:485px; height:401px; z-index:1; left: 495px; top: 191px; } #Layer2 { position:absolute; width:473px; height:60px; z-index:1; left: -483px; top: 18px; } --> </style> <img src="U-stack Another Logo.jpg" width="145" height="111" /> <?php //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword"; else { if(!isset($search) || strlen($search)<=2) echo "<br><font color=white>search term too short</font>"; else { echo "<br><br><font color=white>you searched for <b>$search</b></font><hr size='1'>"; } mysql_connect("localhost", "Master", "password"); mysql_select_db("Login"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if($x==1) $construct .= "keywords LIKE '$search_each'"; else $construct .= "OR keywords LIKE '$search_each'"; } //echo out $construct $construct = "SELECT * FROM Upload WHERE $construct"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum Stacks Found!</font><p>"; if($_GET['RadioGroup1']== 1 ) $margin = 'style="margin-left:60px"'; else if($_GET['RadioGroup1']== 2 ) $margin = 'style="margin-left:120px"'; else if($_GET['RadioGroup1']== 3 ) $margin = 'style="margin-left:180px"'; else if($_GET['RadioGroup1']== 4 ) $margin = 'style="margin-left:240px"'; else if($_GET['RadioGroup1']== 5 ) $margin = 'style="margin-left:300px"'; else if($_GET['RadioGroup1']== 6 ) $margin = 'style="margin-left:360px"'; else if($_GET['RadioGroup1']== 7 ) $margin = 'style="margin-left:420px"'; else if($_GET['RadioGroup1']== 8 ) $margin = 'style="margin-left:480px"'; else $margin = 'style="margin-left:0px"'; echo '<br><table '.$margin.'>'; while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; echo '<tr><td>'; switch ($type) { case 'I': echo '<img src="http://www.u-stack.com/Image.jpg">'; break; case 'M': echo '<img src="http://www.u-stack.com/Music.jpg">'; break; case 'F': echo '<img src="http://www.u-stack.com/File.jpg">'; break; case 'V': echo '<img src="http://www.u-stack.com/Video.jpg">'; break; case 'J': echo '<img src="http://www.u-stack.com/Job.jpg">'; break; case 'D': echo '<img src="http://www.u-stack.com/Discussion.jpg">'; break; case 'P': echo '<img src="http://www.u-stack.com/Product.jpg">'; break; } echo '</td></tr>'; } echo '</table>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892430 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 I don't quite understand why you would want to keep the old results for a new search. Or even append the data from the old search to the new search. If you must though, there are multiple things you can do. You can store the search term as a session/get variable and append that to the $search variable Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892440 Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 So.. session_start(); $_SESSION['search']=$search; is that right? where would i place this in my code Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892450 Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 i'm having trouble applying session_start(); and $_SESSION['search']=$search; to my code, i know session_start(); goes at the top of the page , i don't even know if i'm correct in doing it this way? Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892464 Share on other sites More sharing options...
kickstart Posted August 6, 2009 Share Posted August 6, 2009 Hi You could do that, or you could use check boxes rather than radio buttons, allowing multiple ones to be selected. Then just loop round them. Although personally as you are putting the results in different places I would be tempted to do it using Ajax. Have a seperate script to return a set of data and update that section of the page without having to refresh the data that has already be retrieved. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892467 Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 thx for all the help i been messing around with sessions but with no success. This is my Search everything works fine. $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword"; else { if(!isset($search) || strlen($search)<=2) echo "<br><font color=white>search term too short</font>"; else { echo "<br><br><font color=white>you searched for <b>$search</b></font><hr size='1'>"; } mysql_connect("localhost", "Master", "password"); mysql_select_db("Login"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if($x==1) $construct .= "keywords LIKE '$search_each'"; else $construct .= "OR keywords LIKE '$search_each'"; } //echo out $construct $construct = "SELECT * FROM Upload WHERE $construct"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum Stacks Found!</font><p>"; if($_GET['RadioGroup1']== 1 ) $margin = 'style="margin-left:60px"'; else if($_GET['RadioGroup1']== 2 ) $margin = 'style="margin-left:120px"'; else if($_GET['RadioGroup1']== 3 ) $margin = 'style="margin-left:180px"'; else if($_GET['RadioGroup1']== 4 ) $margin = 'style="margin-left:240px"'; else if($_GET['RadioGroup1']== 5 ) $margin = 'style="margin-left:300px"'; else if($_GET['RadioGroup1']== 6 ) $margin = 'style="margin-left:360px"'; else if($_GET['RadioGroup1']== 7 ) $margin = 'style="margin-left:420px"'; else if($_GET['RadioGroup1']== 8 ) $margin = 'style="margin-left:480px"'; else $margin = 'style="margin-left:0px"'; echo '<br><table '.$margin.'>'; while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; echo '<tr><td>'; switch ($type) { case 'I': echo '<img src="http://www.u-stack.com/Image.jpg">'; break; case 'M': echo '<img src="http://www.u-stack.com/Music.jpg">'; break; case 'F': echo '<img src="http://www.u-stack.com/File.jpg">'; break; case 'V': echo '<img src="http://www.u-stack.com/Video.jpg">'; break; case 'J': echo '<img src="http://www.u-stack.com/Job.jpg">'; break; case 'D': echo '<img src="http://www.u-stack.com/Discussion.jpg">'; break; case 'P': echo '<img src="http://www.u-stack.com/Product.jpg">'; break; } echo '</td></tr>'; } echo '</table>'; } ?> I haven't included radio buttons but they work correctly. Its a multiple search system if your wondering. How do i keep old results, because when i press a radio button and then search, i have new results on a different area of the page but still want the old results where they were. What do i add to this code to do that? Someone mentioned a session, is that correct? Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892476 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 ahhh, they are searches in different area. I thought you just had one search bar and you wanted the old results along with the new or something crazy like that. Well, like Kickstart said, the best way would be to use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892477 Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 ajax.. i know nothing about it lol :'(, so i need to learn a new programming language for this? Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892483 Share on other sites More sharing options...
kickstart Posted August 6, 2009 Share Posted August 6, 2009 Hi You could store info in a session as suggested, or in hidden form fields, or use check boxes rather than radio buttons. Much the same to the user but mulitples can be selected, and when you put the form back out again you set those check boxes to be checked. Ajax is not a language, it is just a combination of some server language (such as php) and Javascript. It is Asynchronous Javascript And Xml (because you can use XML as the format of the data passed back from the server). What you can do with it is just get data back from the server without refreshing the whole page, and use javascript to update the particular part of the page you want to update. In a recent post I did a quick basic example of Ajax. You might find it useful:- http://www.phpfreaks.com/forums/index.php/topic,263519.msg1242217.html#msg1242217 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892490 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.