Display values in listbox from db table regarding selected item in listbox?

Reply

Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Display values in listbox from db table regarding selected item in listbox?

 
0
  #1
Aug 26th, 2008
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..

<!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>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      
    </table>
    </form>
    
    </td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>


Thanks in advance...
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #2
Aug 26th, 2008
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
  1. <?php
  2.  
  3. include_once( "config.php" );
  4.  
  5. $doc = new DOMDocuemt('1.0');
  6. $doc->loadHTMLFile('form.html');
  7. $nodes = $doc->getElementsByTagName('*');
  8. foreach ( $nodes as $node ) {
  9. switch ( $node->getAttribute('id') ) {
  10. case 'select': $select = $node; break;
  11. case 'select2': $select2 = $node; break;
  12. }
  13. }
  14.  
  15. $result = mysql_query("SELECT `cname` FEOM `addcourse`")
  16. or die(mysql_error());
  17. if ( mysql_num_rows( $result ) ) {
  18. while ( $obj = mysql_fetch_object( $result ) ) {
  19. $option = $doc->createElement('option');
  20. $option->setAttribute('value',"obj->cname");
  21. $option->nodeValue = $obj->cname;
  22. $select->appendChild( $option );
  23. }
  24. mysql_free_result( $result );
  25. } else {
  26. die( "No results for first select box query" );
  27. }
  28.  
  29. if ( $cname = $_REQUEST['cname'] ) {
  30. $result = mysql_query("SELECT `subcname` FEOM `subcourse` WHERE `cname`='$cname'")
  31. or die(mysql_error());
  32. // WHERE `cname`='$cname' ... here `cname` must match field searched specific to your `subcourse` database table
  33. if ( mysql_num_rows( $result ) ) {
  34. while ( $obj = mysql_fetch_object( $result ) ) {
  35. $option = $doc->createElement('option');
  36. $option->setAttribute('value',"obj->subcname");
  37. $option->nodeValue = $obj->subcname;
  38. $select2->appendChild( $option );
  39. }
  40. } else {
  41. die( "No results for second select box query" );
  42. }
  43. }
  44.  
  45. print $doc->saveHTML();
  46. ?>

form.html
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <body>
  8. <table width="100%" height="208" border="0">
  9. <tr>
  10. <th width="87%" height="21" scope="col"> <div align="right">
  11. <table width="60%" border="0">
  12. <tr>
  13. <th width="34%" scope="col"><div align="right"><a href="addcourses.php">Add Courses</a></div></th>
  14. <th width="40%" scope="col"><div align="right"><a href="addsubcourses.php">Add Sub Courses</a></div></th>
  15. <th width="26%" scope="col"><div align="right">Add Content</div></th>
  16. </tr>
  17. </table>
  18. </div></th>
  19. <th width="13%" scope="col"><a href="logout.php">Logout</a></th>
  20. </tr>
  21. <tr>
  22. <td><form name="form" method="post" action="content.php">
  23. <table width="100%" height="118" border="0">
  24. <tr>
  25. <td><div align="right"><strong>Course</strong></div></td>
  26. <td><div align="center"><strong>:</strong></div></td>
  27. <td><select name="cname" id="select"></select></td>
  28. </tr>
  29. <tr>
  30. <th width="57%" scope="col"><div align="right">Sub Course </div></th>
  31. <th width="8%" scope="col">:</th>
  32. <th width="35%" scope="col" align="left"> <select name="subcname" id="select2"></select></th>
  33. </tr>
  34. <tr>
  35. <td><div align="right"><strong>Content</strong></div></td>
  36. <td><div align="center"><strong>:</strong></div></td>
  37. <td><textarea name="content" id="textfield2" rows="5" cols="30"></textarea></td>
  38. </tr>
  39. <tr>
  40. <td><div align="right"><input type="submit" name="button" id="button" value="Add Content" /></div></td>
  41. <td>&nbsp;</td>
  42. <td>&nbsp;</td>
  43. </tr>
  44. </table>
  45. </form></td>
  46. <td>&nbsp;</td>
  47. </tr>
  48. </table>
  49. </body>
  50. </html>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 178
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 22
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #3
Aug 27th, 2008
hi,create a new field parentid in ur table and insert values like this
  1. <? $qry2="INSERT INTO fm_forums(title,description,parentid) VALUES ('".$_POST['title']."','".$_POST['description']."','".$_POST['selcategory']."')";
  2. $res2=mysql_query($qry2) or die(mysql_error());?>
  3. <table width="85%" border="0" align="center" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
  4.  
  5. <tr bgcolor="#E1E1E1">
  6. <td width="25%" bgcolor="#FFFFFF"><strong>Sub-Topic Title : </strong></td>
  7. <td width="75%" bgcolor="#FFFFFF"><input name="title" type="text" class="Inputform" id="title2" size="60" <? if (isset($_GET['aid'])){?>value="<?=$subcategory?>"><? }?></td>
  8. </tr><?
  9. $ers="SELECT * FROM fm_forums WHERE parentid=0";
  10. $sed=mysql_query($ers) or die(mysql_error());
  11. $sed1=mysql_fetch_array($sed);
  12. $qry4="SELECT * FROM fm_forums WHERE parentid=".$sed1['forumid'];
  13. $res4=mysql_query($qry4) or die(mysql_error());
  14. $num4=mysql_num_rows($res4);
  15. if($num4>0)
  16. {
  17.  
  18. ?>
  19. <tr bgcolor="#E1E1E1">
  20. <td bgcolor="#FFFFFF"><strong>Under Topic : </strong></td>
  21. <td bgcolor="#FFFFFF">
  22.  
  23. <select name="selcategory" class="box2" id="selcategory">
  24. <option value="">------Selectsubtopic-------</option>
  25. <? while($row4=mysql_fetch_array($res4))
  26. { ?>
  27. <option value="<?=$row4['forumid']?>" <? if ((isset($_GET['forumid']))&&($row4['forumid']==$category)){?>selected<? }?>>
  28. <?=$row4['title']?><? }
  29. }?>
  30. </option>
  31.  
  32. </select></td>
  33. </tr>
  34. <tr bgcolor="#E1E1E1">
  35. <td bgcolor="#FFFFFF"><strong>Summary :</strong></td>
  36. <td bgcolor="#FFFFFF"><textarea name="description" cols="60" rows="8" class="Inputform" id="description"><? if (isset($_GET['aid'])){ echo "$subcategory1";}?></textarea></td>
  37. </tr>
  38. </table>
in front end u will display based on id like this
  1. <tr>
  2. <th width="57%" scope="col"><div align="right">Sub Course </div></th>
  3. <th width="8%" scope="col">:</th>
  4. <th width="35%" scope="col" align="left">
  5. <select name="subcname" id="">
  6.  
  7. <?php
  8. include("config.php");
  9. $result=mysql_query("select subcname from subcourse where parentid=".$row[id]) or die(mysql_error());
  10.  
  11.  
  12. while ($row = mysql_fetch_array($result)) {
  13.  
  14. ?>
  15. <option value="<?php echo $row['subcname']; ?> " > <?php echo $row['subcname']; ?></option>
  16. <?php
  17. }
  18. ?>
  19.  
  20. </select></th>
  21. </tr>
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
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #4
Aug 27th, 2008
Thank u praveen,

It looks simple...but i didn,t get totally..i.e where i want to used that code.can u explain me plz...

In which page i will use that query 2?

thanks once again..
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 178
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 22
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #5
Aug 27th, 2008
okay, create parentid field in same dbtable in which u have list values and create a new php page to insert dbvalues in second list box for that use my first code. in the page u posted use my second code to display ur second list box values from db.
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Display values in listbox from db table regarding selected item in listbox?

 
0
  #6
Aug 27th, 2008
Hi langsor..
Thank u verymuch...

here i got an error..
"Fatal error: Class 'DOMDocuemt' not found in C:\wamp\www\training\content.php on line 5 "


can u explain me please....

Thanks in advance
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 178
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 22
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #7
Aug 27th, 2008
i dont knew but may be this attachment may work
Attached Files
File Type: php DomDocument.php (12.2 KB, 2 views)
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #8
Aug 27th, 2008
Originally Posted by praveen_dusari View Post
i dont knew but may be this attachment may work

Thanks praveen..
can u see this attachment..plz do that.. here also using php4..

Thank u once again.....
Attached Files
File Type: zip training.zip (3.8 KB, 2 views)
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 178
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 22
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #9
Aug 27th, 2008
hi saritha,
here is the attachment it worked perfectly for me, hope it helps to u
Attached Files
File Type: zip training1.zip (4.6 KB, 4 views)
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 178
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 22
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: Display values in listbox from db table regarding selected item in listbox?

 
0
  #10
Aug 27th, 2008
hi saritha, i have made little modifications to insert names in add content column
Attached Files
File Type: php addcontent.php (4.5 KB, 6 views)
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC