1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Radio Button Help

Discussion in 'PHP' started by lost, Nov 16, 2005.

  1. #1
    i have a search page that contains a textbox for the user to enter a search item and a search button. Once the search button is pressed it does a search on that particular item and looks for it in stored database.
    now, sometimes it can return more than one match. so for example, if i do a search on the color red in my car database, if i have 2 red cars but with different models it will still return both matches.

    i have the output listed in a table with columns and rows. now the problem is that the user can select only one of the matches using a radio button, then submit thier results to go to another page.
    i've added the radio buttons, but what i need to know is how do i go about tracking which one was selected because the radio buttons aren't identified to the items.
    This is what i have now:

    
    <?php
       $page_title = 'System Configuration - Generic Search';
       $radio = '<INPUT TYPE="radio" NAME="check1" VALUE="">';
       include('./awacswebhome.inc');
    ?>
    <CENTER>
    <?php
       //if 'Submit' button was pressed
       if(isset($_POST['genericsearchbutton']))
       {
          require_once('./mysql_connect.php');
          $searchfor = ereg_replace('\*', '%', $_POST['searchfield']);
          $stype = $_POST['searchtype'];
          $query ="SELECT * FROM systemconfig_generic WHERE $stype LIKE '$searchfor'";
          $result = @mysql_query($query);
    
          if($rows = @mysql_fetch_array($result))
          {
             echo "<FONT SIZE=2><BR><BR>Found the following results for <B>'";
             echo $_POST['searchfield'];
             echo "'</B> in <B>'$stype'</B> field:<BR><BR>";
    	     echo '<TABLE BORDER="1" CELLPADDING="4" CELLSPACING="2">';
    	     echo '<TR><TD><FONT SIZE=2><B>Check</TD><TD><B><FONT SIZE=2>System</B></TD><TD><B><FONT SIZE=2>Description</B></TD><TD><B><FONT SIZE=2>Part No</B></TD></TR>';
    
             extract($rows);
             echo "<TR><TD>$radio</TD><TD><FONT SIZE=2>$system</TD><TD><FONT SIZE=2>$description</TD><TD><FONT SIZE=2>$partno</TD></TR>";
    
             while($rows = @mysql_fetch_array($result))
             {
    	        extract($rows);
                echo "<TR><TD>$radio</TD><TD><FONT SIZE=2>$system</TD><TD><FONT SIZE=2>$description</TD><TD><FONT SIZE=2>$partno</TD></TR>";
             }
             echo '</TABLE>';
          }
          else
          {
             echo "<BR><FONT SIZE=2>No entries found for <B>'";
             echo $_POST['searchfield'];
             echo "'</B> in <B>'$stype'</B> field.<BR>";
             echo "<FONT SIZE=2>Try using '*' for wildcard searching.<BR>";
          }
          include('./genericgoback.inc');
          include('./genericselect.inc');
          mysql_close();
      }
    
    
    PHP:
     
    lost, Nov 16, 2005 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    while ($rows = @mysql_fetch_array($result)) {
      extract($rows);
      echo '<TR><TD><input type=radio name="car" value="part-'.$partno.'" /></TD><TD><FONT SIZE=2>'.$system.'</TD><TD><FONT SIZE=2>'.$description.'</TD><TD><FONT SIZE=2>'.$partno.'</TD></TR>';
    }
    
    PHP:
    On the page that the form gets submitted to, you'll have the GET variable car and the contents will be part-XXXXX. You wouldn't have to prepend it with "part-" if that will just mess you up. Also you could use the row's id or something like that. :)
     
    exam, Nov 16, 2005 IP
  3. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Exam, but I'm not sure that would work.
    I've attached an example of what i have...i need to know how to retrieve the query that matches with the selected radio box.
     

    Attached Files:

    lost, Nov 17, 2005 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Whatever field is the unique field for each row (by looking at your thumbnail, it appears that maybe system is?) If not, you need to add a column (Field) id and have that be an auto_increment int. That is what you would use in my example above instead of part number. I had just assumed that a part number would be unique. If you want, send me or post a couple of sample rows from your database, so I can see what's up.
     
    exam, Nov 17, 2005 IP
  5. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i do have a unique field called 'gid' that autoincrements in the database...so i tried putting this in:

    
             echo "<TR><TD><INPUT TYPE=radio NAME="radio" VALUE="'.$gid.'"/></TD><TD><FONT SIZE=2>$system</TD><TD><FONT SIZE=2>$description</TD><TD><FONT SIZE=2>$partno</TD></TR>";
    
    
    PHP:
    and its giving me a parse error:
    Parse error: parse error, expecting `','' or `';'' in C:\Server\Apache2\htdocs\genericsearchlist.php on line 26
     
    lost, Nov 17, 2005 IP
  6. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, you have a parse error. try this
    echo "<TR><TD><INPUT TYPE=radio NAME=\"radio\" VALUE=\"$gid\"/></TD><TD><FONT SIZE=2>$system</TD><TD><FONT SIZE=2>$description</TD><TD><FONT SIZE=2>$partno</TD></TR>"; 
    PHP:
     
    exam, Nov 17, 2005 IP
  7. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Still not working :(
     
    lost, Nov 17, 2005 IP
  8. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'd help if you posted the error you're getting :(
     
    exam, Nov 17, 2005 IP
  9. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks exam for you help, i fixed the syntax error :)
     
    lost, Nov 18, 2005 IP
  10. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You're welcome :)
     
    exam, Nov 18, 2005 IP