PDA

View Full Version : Creating Dynamic Dropdowns can't get to work


jonathandenwood
04-06-2008, 06:24 PM
Hi folks I'm been trying to doing the Creating Dynamic Dropdowns tutorial. I download the working example? Used the text database file in the download which successfully populated the database. Then I made the connection in Dreamweaver. I check all the names and there are correct. I made the database link in Dreamweaver and I can see the tables. However, when I F12 the page to see it in browser the first field is populated. However the dynamic second field no joy. Have you managed to get the example to really work and if the answer is yes any ideas on what I am doing wrong? I am using MAMP.Pro and my testing server environment.

Take care

Jonathan

tux
04-07-2008, 09:25 AM
Hello Jonathan and welcome to the forums.

Firstly, it would helpful to see the code that you have so it can be compared to Davidj's tutorial code so please post your code wrapping it in code tags using the # button.

Next..

Then I made the connection in Dreamweaver

Davidj only teaches hand coding. Did you use any of Dreamweavers wizards or tools to create the DB connection. When using Dj's tuts Dreamweaver is only really used as a text editor. The connection would have been made as part of the script. Some like....


<?php
require_once("Connections/connection.php"); // database connection
?>


Regards, Paul

jonathandenwood
04-07-2008, 02:35 PM
Hi Tux, and thanks for the reply and information. Yes, you are correct I did use Dreamweaver to make the connection to database. However, I did make sure that the files names were the same as in Dj's example files which I downloaded from Dreamweaverclub. Here is the connection code that Dreamweaver made for me plus the root path.

dwc/Connections/conection.php



<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connection = "localhost";
$database_connection = "dwc";
$username_connection = "guardia5_carol";
$password_connection = "strides666";
$connection = mysql_pconnect($hostname_connection, $username_connection, $password_connection) or trigger_error(mysql_error(),E_USER_ERROR);
?>Here is the code from the file that Dj made which I am tying to connect to.

<?php
require_once("Connections/connection.php"); // database connection

$make = $_POST['make'];


if ($make){
/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////////
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form id="form1" name="form1" method="post" action="dropdown.php" >

<select name="make" onChange="document.forms[0].submit()">
<option value="">Select Make</option>
<option value="1" <?php if(!(strcmp(1, $make))){echo "selected";}?>>Alfa Romeo</option>
<option value="2" <?php if(!(strcmp(2, $make))){echo "selected";}?>>Audi</option>
<option value="3" <?php if(!(strcmp(3, $make))){echo "selected";}?>>BMW</option>
<option value="4" <?php if(!(strcmp(4, $make))){echo "selected";}?>>Citroen</option>
</select>


<select name="model">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['car_model_id']; ?>"><?php echo $rowModel['car_model']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result)); ?>
</select>

</form>

</body>
</html>I know that I have probably made a really stupid mistake. But I can't see it can you help?

Take care

Jonathan

tux
04-07-2008, 02:44 PM
The fact you have used the DW wizards is why this has failed. You must follow the tut to the letter.

Did you create the connection script?? "Connections/connection.php"

If I was you I would revisit Dj tuts and follow them from the very beginning.

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php

Doing this will make things become a lot clearer. Once you have done this come back if you need more help.

Regards, Paul

jonathandenwood
04-07-2008, 04:38 PM
Hi Paul , Thanks for additional advice I will do what you suggest. I have already been looking at the additional training screen-casts on the site. I will make the connection file by hand-coding. However, I don't really understand why this will make a difference being that this file is just a connection script as long as the names are correct it should work? But, like what I said at the beginning I will follow your advice and make the connection file by hand coding it.

Take care

Jonathan

jonathandenwood
04-07-2008, 08:44 PM
Hi Paul, You were right! I did the connection by hand using Dj's example screen-cast on connecting databases using PHP. Thanks, I have a second question I want to adapt the code so when you choose from second menu i.e. "model of car" the models details are displayed on the web-page using a repeat region. Have you any idea how I can do this?

Take care

Jonathan

tux
04-08-2008, 09:22 AM
To achieve a repeat region with PHP you can use a 'do while loop'.

ie.....


<?php do {

some code here will loop

} while ( your DB query here )

?>


So all the time your DB query has a result it will perform the code in the braces.

If you continue with Djs tuts you will find that this is explained in more detail. I must stress that going through Dj's tuts in full will give you most of the basics you will need to understand and get started coding with PHP. start with " Part 1, Tools of the Trade"

Let me know how you get on.

Regards, Paul