Jump to content

[SOLVED] Microsoft Access Dropdown List


contraboybish

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

?>

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.