List:General Discussion« Previous MessageNext Message »
From:Andrew Date:November 10 2003 1:28pm
Subject:RE: select option from associated query
View as plain text  
>Hi All MySQL users
>
>I am having a slight problem and getting inot a bit of a tizz.
>
>I have two tables and I am trying to produce a dropdown select menu whilst
>creating a join.  The two tables are as follows...
>
>CREATE TABLE itinerary (
>  i_id int(3) unsigned NOT NULL auto_increment,
>  i_title varchar(100) default NULL,
>  i_description mediumtext,
>  i_category int(3) unsigned default NULL,
>  i_ordernumber int(3) unsigned default NULL,
>  i_text mediumtext,
>  i_image1 varchar(255) default NULL,
>  i_image2 varchar(255) default NULL,
>  i_image3 varchar(255) default NULL,
>  PRIMARY KEY  (i_id),
>  UNIQUE KEY i_id (i_id),
>  KEY i_id_2 (i_id)
>) TYPE=MyISAM;
>
>and
>
>CREATE TABLE dates2 (
>  d_id int(3) unsigned NOT NULL auto_increment,
>  d_objid int(3) unsigned default NULL,
>  d_startdate date default NULL,
>  d_enddate date default NULL,
>  PRIMARY KEY  (d_id),
>  UNIQUE KEY d_id (d_id),
>  KEY d_id_2 (d_id)
>) TYPE=MyISAM;
>
>The two fields that are associated are dates2.d_objid and itinerary.i_id what I
>want to do is pull out the dates for a selected itinerary.i_id and present them
>in a select menu.  I am using php but it's been a while and have only
>got so far
>inot a tizz :)
>
>Can anyone shed a little light on the quesry or a bit of guidance on how to
>approach this?
>
>Thank you
>Andrew
>

This is what I have used for the query and the php

<?


echo "<select name=\"StartDate\" size=\"1\" class='menuForm'>";

$result=mysql_query("select dates2.d_objid ,dates2.d_startdate,dates2.d_enddate
from dates2 left join itinerary.i_id on dates2.d_objid = itinerary.i_id where
dates2.d_startdate and dates2.d_enddate=" . $Date . " group by
dates2.d_startdate");
while ($row = mysql_fetch_array($result))
    {
        $d_startdate=$row['StartDate'];
		$d_enddate=$row['EndDate'];
echo "<option value=\"$Date\">$d_startdate - $d_enddate </option>";
}
echo "</select>";

?>

which is clearly wrong somewhere :(

Any help would be nice

Andrew

>

Thread
select option from associated id queryAndrew10 Nov
  • RE: select option from associated queryAndrew10 Nov