Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892428
Share on other sites

<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>';

 

 

}

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892430
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892440
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892467
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892476
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/169145-search-loop/#findComment-892490
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.