Re: [php] dependable combo boxes with mysql database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, November 4, 2005 11:24 am, Bhoomi Vora wrote:
> I have a php page which contains three combo boxes.
> The first one will have the value
>
> from the mysql database table on page load itself.
>
> Then depending upon the value selected in the first
> combobox the second combo box
>
> should be populated with the respective values from
> another mysql database table, and
>
> once again depending upon the value selected in second
> combobox the third combobox
>
> should be populated with the respective values from
> one more different database table.
>
> I have read through mailing list and also searched in
> google and found that it can be
>
> done with javascript onblur function but nothing is
> working. Here is the code:
> ------------------------------------------------------------------
> <?php
> include_once("inc\connection.inc");
>
> //with this function first combobox will be populated
> on pageload
> function
> display_db_combo($tablename,$columnname,$connection)
> {
> 	$query_string="select $columnname from $tablename";
>
> 	$result=mysql_query($query_string);
>
> 	while($row=mysql_fetch_array($result)) {
>
> 			print("<option>$row[0]</option>");
>
> 	}
>
> }
> ?>

Do this again, only put the data for D2 and D3 in JavaScript arrays:
<?php
function
dump_js_array($tablename,$columname,$connection)
{
.
.
.
print("<script language=\"javascript\">\n";
print("\tvar D2 = array(''\n"); //this is printing out JavaScript code
while($row...) {
    print("\t\t,'$row[0]'\n"); //elements of array (note '' above)
}
print("\t);\n"); //end of JavaScript array
print("</script>\n");
}
?>

Then you can use the onblur() in JavaScript to pull data out of those
JavaScript arrays to populate D2 and D3.

You'll have to work out the JavaScript part somewhere else, as it's
JavaScript and not PHP, and I'd probably get it wrong.

> <HTML>
> <HEAD>
> <TITLE>Untitled Page</TITLE>
> <META NAME="Generator" CONTENT="Created by BlueVoda">
> </HEAD>
> <BODY bgcolor="#FFFFFF" text="#000000">
> <DIV style="position:absolute; left:175px; top:70px;
> width:592px; height:483px;
>
> z-index:24"  align="left" valign="top">
> <FORM name="form_cust" method="POST"
> action="thisform.php"
>
> enctype="multipart/form-data">
>
> <DIV style="position:absolute; left:198px; top:65px;
> width:6px; height:15px; z-index:0"
>
>  align="left" valign="top">
> <FONT style="FONT-SIZE:9pt" color="#00008B"
> face="Arial"><B>:</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:198px; top:108px;
> width:6px; height:15px;
>
> z-index:1"  align="left" valign="top">
> <FONT style="FONT-SIZE:9pt" color="#00008B"
> face="Arial"><B>:</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:198px; top:167px;
> width:6px; height:15px;
>
> z-index:2"  align="left" valign="top">
> <FONT style="FONT-SIZE:9pt" color="#00008B"
> face="Arial"><B>:</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:65px; top:60px;
> width:97px; height:22px; z-index:3"
>
>  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Service</B></FONT>
> </DIV>
>
> <select name="D1" size="1"
> style="position:absolute;left:230px;top:68px;z-index:7"
>>
> <?php
> display_db_combo("service_master","service_name",$conn);?>
> </select>
>
> <DIV style="position:absolute; left:65px; top:106px;
> width:83px; height:22px;
>
> z-index:4"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Product</B></FONT>
> </DIV>
> <select name="D2" size="1"
> style="position:absolute;left:230px;top:108px;z-index:8">
> </select>
>
> <DIV style="position:absolute; left:65px; top:152px;
> width:103px; height:44px;
>
> z-index:5"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Nature of
>
> Problem</B></FONT>
> </DIV>
> <select name="D3"
> style="position:absolute;left:230px;top:170px;z-index:9"
> size="1"
>
> value="">
> </select>
>
> <DIV style="position:absolute; left:177px; top:1px;
> width:270px; height:22px;
>
> z-index:9"  align="center" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B><U>Complaint
>
> Registration</B></U></FONT>
> </DIV>
> <INPUT type="reset" name="Edit_Reset" value="Reset"
>
> style="position:absolute;left:376px;top:429px;z-index:10">
> <INPUT type="submit" name="comp_send" value="Send"
>
> style="position:absolute;left:148px;top:429px;z-index:11">
> <INPUT type="text"
>
> style="position:absolute;left:230px;top:240px;width:161px;z-index:12"
> size="23"
>
> name="T3" value="">
> <DIV style="position:absolute; left:257px; top:330px;
> width:60px; height:18px;
>
> z-index:13"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Upper</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:257px; top:359px;
> width:72px; height:18px;
>
> z-index:14"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Middle</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:257px; top:386px;
> width:60px; height:18px;
>
> z-index:15"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Lower</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:65px; top:240px;
> width:123px; height:66px;
>
> z-index:16"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Problem
>
> Description</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:198px; top:240px;
> width:6px; height:15px;
>
> z-index:17"  align="left" valign="top">
> <FONT style="FONT-SIZE:9pt" color="#00008B"
> face="Arial"><B>:</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:65px; top:310px;
> width:123px; height:44px;
>
> z-index:18"  align="left" valign="top">
> <FONT style="FONT-SIZE:12pt" color="#00008B"
> face="Courier New"><B>Severity of
>
> Problem</B></FONT>
> </DIV>
> <DIV style="position:absolute; left:198px; top:329px;
> width:6px; height:15px;
>
> z-index:19"  align="left" valign="top">
> <FONT style="FONT-SIZE:9pt" color="#00008B"
> face="Arial"><B>:</B></FONT>
> </DIV>
> <INPUT type="radio" name="" value=""
>
> style="position:absolute;left:221px;top:330px;z-index:20">
> <INPUT type="radio" name="" value=""
>
> style="position:absolute;left:221px;top:357px;z-index:21">
> <INPUT type="radio" name="" value=""
>
> style="position:absolute;left:221px;top:381px;z-index:22">
> <INPUT type="submit" name="comp_preview"
> value="Preview"
>
> style="position:absolute;left:253px;top:429px;z-index:23">
>
> </FORM>
>
> </DIV>
> </BODY>
> </HTML>
> ------------------------------------------------------------------
>
> In the above code there are three combo box namely D1,
> D2 and D3.
>
> D1 will be populated on pageload. Now D2 should be
> populated on event like 'onblur' to D1 and similarly
> D3 should be populated on event like 'onblur' to D2.
>
> Pl. give me the exact code or proper guideline how
> should I accomplish this on the same page.
>
> Appreciate your replies.
>
> Thanks and regards.
>
> BJV
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux