contraboybish Posted November 18, 2007 Share Posted November 18, 2007 Ok, l am building a new site using PHP which has a lot of pages pulling from an Access Database. I would like to have a dropdown list that pulls exhibitions from the database and then when the user selects one it shows the rest of the details from DB just below the dropdown list, hope that makes sense. I open the DB as follows.... <?php require_once('../App_Data/odbc_open.php'); $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage ORDER BY ExhibitionShortDate ASC") or die (odbc_errormsg()); ?> How do i populate a dropdown and when the user selects a date it shows the details. a hint would be nice, so that i can try and work it out myself? Hope someone can help Bish Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/ Share on other sites More sharing options...
MadTechie Posted November 18, 2007 Share Posted November 18, 2007 This may help Dynamic DropDown PHP/AJAX Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393839 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 That looks very daunting for a newbie!!! Ok, lets go slowly!! How would l populate a dropdown list Bish Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393850 Share on other sites More sharing options...
rarebit Posted November 18, 2007 Share Posted November 18, 2007 On this site it shows how to use forms (in html), on it is a link to 'Simple drop down box', http://www.w3schools.com/html/html_forms.asp, you could use that and when submitted (or automatically submitted by js), the page is recreated with appropriate data. This isn't as sophisticated as using AJAX, but could lead you towards the more advanced dynamic concepts, this way will also work if js is turned off. Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393858 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 Ok, thankyou for the pointer, adapting the above with php as follows, works. require_once('../App_Data/odbc_open.php'); $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage ORDER BY ExhibitionShortDate ASC") or die (odbc_errormsg()); echo '<form action=""> <select name="Exhibitions">'; while($row = odbc_fetch_array($query)) { echo '<option value="'.$row['exhibitionsDate'].'">'.$row['exhibitionsDate'].'</option>'; } odbc_close($odbc); echo '</select> </form>'; Now the next step is to have the details of any selection made show just below the dropdown list? Bish Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393864 Share on other sites More sharing options...
rarebit Posted November 18, 2007 Share Posted November 18, 2007 This is what I (used to) use: function helpers_form_select_s($name, $values, $selected) { $sret = "<select name=\"".$name."\">"; foreach($values as $v) { if (strcmp($v, $selected) == 0) { $sret .= "<option selected>".$v; } else { $sret .= "<option>".$v; } } $sret .= "</select>"; return $sret; } Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393865 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 How do l use this? Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393920 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 Can someone tell me if l am on the right road? I have populated the dropdown and now i need to select an item and see results just below it!!! require_once('../App_Data/odbc_open.php'); $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage ORDER BY ExhibitionShortDate ASC") or die (odbc_errormsg()); echo '<form action=""> <select name="Exhibitions">'; while($row = odbc_fetch_array($query)) { echo '<option value="'.$row['exhibitionsDate'].'">'.$row['exhibitionsDate'].'</option>'; } echo '</select> </form>'; while($row = odbc_fetch_array($query)) { if ( can i do a match here? ) } odbc_close($odbc); Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393942 Share on other sites More sharing options...
MadTechie Posted November 18, 2007 Share Posted November 18, 2007 **untested are you trying this ? <?php $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage ORDER BY ExhibitionShortDate ASC") or die (odbc_errormsg()); echo "<form method=\"post\">\n<select name=\"Exhibitions\">"; while($row = odbc_fetch_array($query)) { $sel = ($row['exhibitionsDate'] == $_POST['Exhibitions'])?"Selected":""; echo "<option value=\"{$row['exhibitionsDate']} $sel\">{$row['exhibitionsDate']}</option>"; } echo "</select> <input name=\"submit\" type=\"submit\" /> </form>"; if(isset($_POST['submit'])) { $FindDate = $_POST['Exhibitions']; $query = odbc_exec($odbc, "SELECT * FROM table WHERE Exhibitions=$FindDate") or die (odbc_errormsg()); echo "<pre>"; while($row = odbc_fetch_array($query)) { print_r($row); } } odbc_close($odbc); ?> Of course your need to update the second query i used table as i don't know the table your going to use Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393947 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 Wow that was quick, i will have a go at that. Will let you know, many thanks Bish Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393951 Share on other sites More sharing options...
contraboybish Posted November 18, 2007 Author Share Posted November 18, 2007 Took a little tweaking but yay it works :-) My first experience on PHP Freaks and the feedback is aweome. Many Thanks Bish P.s. This is what l used in the end <?php echo '<img src="../Headers/exhibitions.jpg" alt="Exhibitions 2007/2008" style="float: left"/><br /><br />'; require_once('../App_Data/odbc_open.php'); $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage ORDER BY ExhibitionShortDate ASC") or die (odbc_errormsg()); echo "<form method=\"post\">\n<select name=\"Exhibitions\">"; while($row = odbc_fetch_array($query)) { $sel = ($row['exhibitionsDate'] == $_POST['Exhibitions'])?"Selected":""; echo "<option value=\"{$row['exhibitionsDate']} $sel\">{$row['exhibitionsDate']}</option>"; } echo "</select> <input name=\"submit\" type=\"submit\" /> </form>"; if(isset($_POST['submit'])) { $FindDate = $_POST['Exhibitions']; $query = odbc_exec($odbc, "SELECT * FROM ExhibitionsPage WHERE exhibitionsDate='$FindDate'") or die (odbc_errormsg()); echo "<pre>"; while($row = odbc_fetch_array($query)) { echo '<div class="style2">Description: '.$row['exhibitionsDescription'].'</div>'; } } odbc_close($odbc); ?> Quote Link to comment https://forums.phpfreaks.com/topic/77813-solved-microsoft-access-dropdown-list/#findComment-393956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.