Jump to content

Multiple selections from drop down lists to create a mysql select command


barniegilly

Recommended Posts

Hi I have tried the mysql forum but have had no joy with an answer to my problem so wondered if php would be better.

 

I want my users to be able to select from 5 different drop down lists where they can chose any combination from 1 up to all 5,  I have attached the front end.  These lists are being populated from mysql tables.

 

Code for the drop down lists is as follows

  <form action="horse-events-devon.php?url_countyid=<?php echo  urlencode ($url_countyid ['url_countyid'])  ; ?>&go" method="POST">
    <table id="searchtable">
      <tr>
        <th>Find By Discipline</th>
        <th>Find By Venue</th>
        <th>Find By Championship</th>
        <th>Find By Organiser</th>
        <th>Equine Association</th>
        <th>Submit Your Selections</th>
        </tr>
      <tr>
        <td><select name="dis_id">
                                    <?php 
                                        $upcomingdis = upcomingdis($url_countyid);
                                        $upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis);
                                    ?>
                                    <?php 
                                    do { 
      								?>   <option value="<?php echo $upcoming_dis_bycounty ['dis_id']; ?>" >
								<?php echo $upcoming_dis_bycounty ['dis_description']; ?></option>
								<?php 
                                    } while ($upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis)); 
                                    ?></select></td>
        <td><select name="ven_id">
                                    <?php 
                                        $upvenbycounty_set = upcoming_venevents_bycounty($url_countyid);
                                        $upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set);
                                    ?>
                                    <?php 
                                    do { 
      								?>   <option value="<?php echo $upcoming_ven_bycounty ['ven_id']; ?>" >
								<?php echo $upcoming_ven_bycounty ['ven_name']; ?></option>
								<?php 
                                    } while ($upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set)); 
                                    ?></select></td>
        <td><select name="champ_id">
                                    <?php 
                                        $championship_set = findchampionships();
                                        $champlist = mysql_fetch_assoc ($championship_set);
                                    ?>
                                    <?php 
								do { 
								?>   <option value="<?php echo $champlist ['champ_id']; ?>" >
								<?php echo $champlist ['champ_description']; ?></option>
								<?php 
								} while ($champlist = mysql_fetch_assoc ($championship_set)); 
								?></select></td>
        <td>
        <select name="org_id">
                        <?php 
                            $uporgbycounty_set = upcoming_organevents_bycounty($url_countyid);
                            $upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set);
                        ?>
                        <?php 
                        do { 
                        ?>   <option value="<?php echo $upcoming_org_bycounty ['org_id']; ?>" ><?php echo $upcoming_org_bycounty ['org_name']; ?></option>
                        <?php 
                        } while ($upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set)); 
                        ?></select>
        
        </td>
        <td><select name="ass_id">
                                    <?php
                                        $upassbycounty_set = upcoming_assevents_bycounty($url_countyid);
                                        $upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set);
                                    ?>
                                    <?php 
                                    do { 
                                    ?>   <option value="<?php echo $upcoming_assbycounty ['ass_id']; ?>" >
								<?php echo $upcoming_assbycounty ['ass_description']; ?></option>
                                    <?php 
                                    } while ($upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set)); 
                                    ?></select></td>
      	<td><input name="submit" type="submit" /><input name="countyid" type="hidden" value="<?php echo $url_countyid ['url_countyid']; ?>" /></td>
        </tr>
      </table>
  </form>

 

My search processing is as follows

 

  <?php
if (isset($_POST['submit'])){
if (isset($_GET['go'])){
$countyid = $_POST['countyid'];
$ven_id = $_POST['ven_id'];
$dis_id = $_POST['dis_id'];
$champ_id = $_POST['champ_id'];
$org_id = $_POST['org_id'];
$event_id = $row['event_id'];

	$sql = "SELECT DATE_FORMAT (events.startdate, '%a, %d, %b') 
			   AS stdate, events.event_id, events.title, events.ven_id, events.org_id,
			   venue.county_id, venue.ven_id, eventdisciplines.event_id, eventdisciplines.dis_id, county.county_id, discipline.dis_id \n"
		. "FROM events \n"
		. "LEFT OUTER JOIN eventdisciplines \n"
		. "ON events.event_id = eventdisciplines.event_id \n"
		. "LEFT OUTER JOIN discipline \n"
		. "ON eventdisciplines.dis_id = discipline.dis_id \n"
		. "LEFT OUTER JOIN venue \n"
		. "ON events.ven_id = venue.ven_id \n"
		. "LEFT OUTER JOIN county \n"
		. "ON venue.county_id = county.county_id \n"
		. "WHERE events.ven_id = ({$ven_id} OR events.org_id = {$org_id})\n"
		. "AND events.startdate > NOW()\n"
		. "AND venue.county_id = {$countyid}  \n"
		. "ORDER BY startdate ASC";

$result = mysql_query ($sql, $connection);
?>

 

How am I best to do this please?  my OR within the mysql does not work, should I not be doing this with php in the search processing?  someones help would really be appreciated, just to point me in the right direction.

 

[attachment deleted by admin]

Link to comment
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.