Jump to content

Search and radio buttons


MDanz

Recommended Posts

Ok i have Search everything working correctly.  Now i have added radio buttons to represent where i want the results to be displayed.

 

So far my results are displayed in 1 column two rows on the left side of the page.  How do i go about, if i selected radio button 2 then the results move 60px to the right?

 

this is how i display so far in search.php, everything works fine

 

echo '<table>';

 

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

//results are in here

 

 

}  echo '</td></tr>';

 

 

 

    }

   

   

    echo '</table>';

 

 

These are the newly added radio buttons, i've only gone up to two, too keep it short

 

<form action='search.php' method='get'>

<font face ='Arial' size='5'> </font>

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

 

 

In simple  .. If radio button 2 is pressed then echo new table(results) 60px to the right.

Its search.php i have to change but i don't know how to implement an if statement into it for the radio buttons.

 

I'm aiming for a multiple search function if your wondering. 

Link to comment
https://forums.phpfreaks.com/topic/169062-search-and-radio-buttons/
Share on other sites

<?php
if($_GET['RadioGroup1']== 2 )
$margin = 'style="margin-left:60px"';
else
$margin = 'style="margin-left:0px"';
echo '<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>';
//results are in here


}   echo '</td></tr>';



     }
     
     
     echo '</table>';
?>

thx man it is working..

 

 

I added this but now it isn't

 

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 '<table '.$margin.'>';

 

now the results aren't moving, any idea why?

thx man Just one more thing i need help on...

 

<?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 '<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've got 3 images in my database..  Now because its multiple search.  say i search "Basketball" with radio button 2 and "Car" with radio button 3.. how do i keep both these images displayed.  Currently, The search resets when i press the search button. I want the previous search to still be displayed...

 

How do i do this?  Its still difficult to do this from my pseudocode lol.. thx again you've been a great help

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.