| | |
Display values in listbox from db table regarding selected item in listbox?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 159
Reputation:
Solved Threads: 6
Hi frnds..
i want to daisplay values in listbox from database table regarding selected item in first listbox?
here i copied the code...in this i got values of first listbox frm db table..after i want 2nd listbox values from db table of 1st selected item..
plz help ma asap...
i am eagarly waiting 4 reply..
Thanks in advance...
i want to daisplay values in listbox from database table regarding selected item in first listbox?
here i copied the code...in this i got values of first listbox frm db table..after i want 2nd listbox values from db table of 1st selected item..
plz help ma asap...
i am eagarly waiting 4 reply..
<!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="100%" height="208" border="0">
<tr>
<th width="87%" height="21" scope="col">
<div align="right">
<table width="60%" border="0">
<tr>
<th width="34%" scope="col"><div align="right"><a href="addcourses.php">Add Courses</a></div></th>
<th width="40%" scope="col"><div align="right"><a href="addsubcourses.php">Add Sub Courses</a></div></th>
<th width="26%" scope="col"><div align="right">Add Content</div></th>
</tr>
</table>
</div></th>
<th width="13%" scope="col"><a href="logout.php">Logout</a></th>
</tr>
<tr>
<td>
<form name="form" method="post" action="content.php">
<table width="100%" height="118" border="0">
<tr>
<td><div align="right"><strong>Course</strong></div></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="cname" id="select" >
<?php
include("config.php");
$ress=mysql_query("select cname from addcourse ") or die(mysql_error());
while ($row = mysql_fetch_array($ress)) {
?>
<option value="<?php echo $row['cname']; ?> " > <?php echo $row['cname']; ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<th width="57%" scope="col"><div align="right">Sub Course </div></th>
<th width="8%" scope="col">:</th>
<th width="35%" scope="col" align="left">
<select name="subcname" id="">
<?php
include("config.php");
$result=mysql_query("select subcname from subcourse ") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row['subcname']; ?> " > <?php echo $row['subcname']; ?></option>
<?php
}
?>
</select></th>
</tr>
<tr>
<td><div align="right"><strong>Content</strong></div></td>
<td><div align="center"><strong>:</strong></div></td>
<td><textarea name="content" id="textfield2" rows="5" cols="30"></textarea></td>
</tr>
<tr>
<td>
<div align="right">
<input type="submit" name="button" id="button" value="Add Content" />
</div></td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</td>
<td> </td>
</tr>
</table>
</body>
</html>Thanks in advance...
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Keep Smiling....Never Depress
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
Okay, I did NOT test this, so who knows if it will actually work or what bugs, spelling, and syntax errors I have in it ... but this is the idea I would go with and you can check the errors to figure out what I did wrong. :-)
Hope it helps ...
content.php
form.html
Hope it helps ...
content.php
php Syntax (Toggle Plain Text)
<?php include_once( "config.php" ); $doc = new DOMDocuemt('1.0'); $doc->loadHTMLFile('form.html'); $nodes = $doc->getElementsByTagName('*'); foreach ( $nodes as $node ) { switch ( $node->getAttribute('id') ) { case 'select': $select = $node; break; case 'select2': $select2 = $node; break; } } $result = mysql_query("SELECT `cname` FEOM `addcourse`") or die(mysql_error()); if ( mysql_num_rows( $result ) ) { while ( $obj = mysql_fetch_object( $result ) ) { $option = $doc->createElement('option'); $option->setAttribute('value',"obj->cname"); $option->nodeValue = $obj->cname; $select->appendChild( $option ); } mysql_free_result( $result ); } else { die( "No results for first select box query" ); } if ( $cname = $_REQUEST['cname'] ) { $result = mysql_query("SELECT `subcname` FEOM `subcourse` WHERE `cname`='$cname'") or die(mysql_error()); // WHERE `cname`='$cname' ... here `cname` must match field searched specific to your `subcourse` database table if ( mysql_num_rows( $result ) ) { while ( $obj = mysql_fetch_object( $result ) ) { $option = $doc->createElement('option'); $option->setAttribute('value',"obj->subcname"); $option->nodeValue = $obj->subcname; $select2->appendChild( $option ); } } else { die( "No results for second select box query" ); } } print $doc->saveHTML(); ?>
form.html
html Syntax (Toggle Plain Text)
<!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="100%" height="208" border="0"> <tr> <th width="87%" height="21" scope="col"> <div align="right"> <table width="60%" border="0"> <tr> <th width="34%" scope="col"><div align="right"><a href="addcourses.php">Add Courses</a></div></th> <th width="40%" scope="col"><div align="right"><a href="addsubcourses.php">Add Sub Courses</a></div></th> <th width="26%" scope="col"><div align="right">Add Content</div></th> </tr> </table> </div></th> <th width="13%" scope="col"><a href="logout.php">Logout</a></th> </tr> <tr> <td><form name="form" method="post" action="content.php"> <table width="100%" height="118" border="0"> <tr> <td><div align="right"><strong>Course</strong></div></td> <td><div align="center"><strong>:</strong></div></td> <td><select name="cname" id="select"></select></td> </tr> <tr> <th width="57%" scope="col"><div align="right">Sub Course </div></th> <th width="8%" scope="col">:</th> <th width="35%" scope="col" align="left"> <select name="subcname" id="select2"></select></th> </tr> <tr> <td><div align="right"><strong>Content</strong></div></td> <td><div align="center"><strong>:</strong></div></td> <td><textarea name="content" id="textfield2" rows="5" cols="30"></textarea></td> </tr> <tr> <td><div align="right"><input type="submit" name="button" id="button" value="Add Content" /></div></td> <td> </td> <td> </td> </tr> </table> </form></td> <td> </td> </tr> </table> </body> </html>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
hi,create a new field parentid in ur table and insert values like this
in front end u will display based on id like this
i hope u got what iam trying to say and dont worry about aid here i called it for editing
if any doubts post here
php Syntax (Toggle Plain Text)
<? $qry2="INSERT INTO fm_forums(title,description,parentid) VALUES ('".$_POST['title']."','".$_POST['description']."','".$_POST['selcategory']."')"; $res2=mysql_query($qry2) or die(mysql_error());?> <table width="85%" border="0" align="center" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC"> <tr bgcolor="#E1E1E1"> <td width="25%" bgcolor="#FFFFFF"><strong>Sub-Topic Title : </strong></td> <td width="75%" bgcolor="#FFFFFF"><input name="title" type="text" class="Inputform" id="title2" size="60" <? if (isset($_GET['aid'])){?>value="<?=$subcategory?>"><? }?></td> </tr><? $ers="SELECT * FROM fm_forums WHERE parentid=0"; $sed=mysql_query($ers) or die(mysql_error()); $sed1=mysql_fetch_array($sed); $qry4="SELECT * FROM fm_forums WHERE parentid=".$sed1['forumid']; $res4=mysql_query($qry4) or die(mysql_error()); $num4=mysql_num_rows($res4); if($num4>0) { ?> <tr bgcolor="#E1E1E1"> <td bgcolor="#FFFFFF"><strong>Under Topic : </strong></td> <td bgcolor="#FFFFFF"> <select name="selcategory" class="box2" id="selcategory"> <option value="">------Selectsubtopic-------</option> <? while($row4=mysql_fetch_array($res4)) { ?> <option value="<?=$row4['forumid']?>" <? if ((isset($_GET['forumid']))&&($row4['forumid']==$category)){?>selected<? }?>> <?=$row4['title']?><? } }?> </option> </select></td> </tr> <tr bgcolor="#E1E1E1"> <td bgcolor="#FFFFFF"><strong>Summary :</strong></td> <td bgcolor="#FFFFFF"><textarea name="description" cols="60" rows="8" class="Inputform" id="description"><? if (isset($_GET['aid'])){ echo "$subcategory1";}?></textarea></td> </tr> </table>
php Syntax (Toggle Plain Text)
<tr> <th width="57%" scope="col"><div align="right">Sub Course </div></th> <th width="8%" scope="col">:</th> <th width="35%" scope="col" align="left"> <select name="subcname" id=""> <?php include("config.php"); $result=mysql_query("select subcname from subcourse where parentid=".$row[id]) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { ?> <option value="<?php echo $row['subcname']; ?> " > <?php echo $row['subcname']; ?></option> <?php } ?> </select></th> </tr>
if any doubts post here
Failure is success if we learn from it
Re: Display values in listbox from db table regarding selected item in listbox?
0
#10 Aug 27th, 2008
![]() |
Other Threads in the PHP Forum
- Previous Thread: How To Get a Subset of Multidimensional Array
- Next Thread: retreving value from database and displaying them in tree menu.
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack href htaccess html image include insert integration ip java javascript joomla keywords library limit link login loop mail menu mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web website xml youtube





