Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
stocked in making double dynamic dependent select lis in php
Old 06-18-2009, 07:16 AM stocked in making double dynamic dependent select lis in php
Junior Talker

Posts: 3
Name: romala
Trades: 0
hello guys;
I have read and watched and tried 2 million times to create the same thing that is in the tutorials in "Dynamic populating the drop down list based on the selected value of first list" but when I want to change it to my own website and convert it the way that works with my website I get stocked and it doesn't work!
I have 2 tables in mysql database; one is """car_names""" which contains the brand of the cars like: BENZ, BMW, NISSAN, HONDA, ...... and this table has 4 rows as below: :
1=> id
2=> menu_name
3=> position
4=> visible
the second table is """car_models""" which contains the type of the cars related to the first table like: 220E, 330E, civic, accord, sunny, .... and this table has 5 rows as below:
1=> id
2=> carname_id
3=> menu_name
4=> position
5=> visible
As I have created my web page in php I have 2 dropdown select lists that if you choose any car from the first list it works perfectly and brings me all the car's names from the first table from the database>>> menu_name's row. BUT if I choose for example HONDA from the first list the second list still remains empty. I have tried to change the code the I have downloaded from Dynamic populating the drop down list based on the selected value of first list and replace it with mine in or exchange some parts with my code but it didn't work!
I will really appreciate your helps and comments.
Please help me to get this code work for my website, it has been a headache for me about 2 months already!
I don't know how to upload the files here in this website but if you need I can send you the mypage with mysql database files for you.

here is my code:

Code: Select all<?php require_once('Connections/cars.php'); ?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="200" border="0" cellpadding="0" cellspacing="0" id="sidebar">
<tr>
<td valign="top"><form name="form1" method="post" action="">
<table width="200" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="66" height="50">&nbsp;</td>
<td width="110">&nbsp;</td>
</tr>
<tr>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_cars, $cars);
$query_rs_names = "SELECT * FROM car_name ORDER BY position";
$rs_names = mysql_query($query_rs_names, $cars) or die(mysql_error());
$row_rs_names = mysql_fetch_assoc($rs_names);
$totalRows_rs_names = mysql_num_rows($rs_names);

?>

<td align="left" nowrap><label for="name_list" class="carnames-left">CAR BRANDS</label></td>
<td align="right"><select name="name_list" class="carnames" id="name_list">
<option value="">... Choose ...</option>
<?php
do {
?>
<option value="<?php echo $row_rs_names['menu_name']?>"><?php echo $row_rs_names['menu_name']?></option>
<?php
} while ($row_rs_names = mysql_fetch_assoc($rs_names));
$rows = mysql_num_rows($rs_names);
if($rows > 0) {
mysql_data_seek($rs_names, 0);
$row_rs_names = mysql_fetch_assoc($rs_names);
mysql_select_db($database_cars, $cars);
$query_rs_models = "SELECT * FROM car_model WHERE carname_id = {$row_rs_names["id"]} ORDER BY position";
$rs_models = mysql_query($query_rs_models, $cars) or die(mysql_error());
$row_rs_models = mysql_fetch_assoc($rs_models);
$totalRows_rs_models = mysql_num_rows($rs_models);
}
?>

</select></td>
</tr>
<tr>
<td align="left" nowrap><label for="model_list" class="carnames-left">CAR TYPE</label></td>
<td align="right"><select name="model_list" class="carnames" id="model_list">
<option value="">... Choose ...</option>
<?php
do {
?>
<option value="<?php echo $row_rs_models['menu_name']?>"><?php echo $row_rs_models['menu_name']?></option>
<?php
} while ($row_rs_models = mysql_fetch_assoc($rs_models));
$rows = mysql_num_rows($rs_models);
if($rows > 0) {
mysql_data_seek($rs_models, 0);
$row_rs_models = mysql_fetch_assoc($rs_models);
}
?>

</select>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE
romalagajini is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to stocked in making double dynamic dependent select lis in php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09469 seconds with 12 queries