We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,524 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Grabbing content from my dropdown list option

I have a dropdown list at the bottom of my page. It's populating like it's supposed to but when I choose whatever option I want and click submit it doesn't repopulate the content on the page like I want it to.

I'm trying to have content of the page change with whatever option was chosen.

Here's the code I have thus far.

///// Data from Datdbase ////
$sql = "SELECT * FROM table WHERE title = 'title'";
$result = mysql_query($sql,$db) or die(mysql_error()."<br />SQL: $sql");

$img = array();
$title = array();
while($row = mysql_fetch_array($result)){
	// process data
	$title[] =  $row['title'];
	$img[] =  $row['img'];
}
	
///// Data from database ////
$sql = "SELECT * FROM table WHERE st_title = 'st_title'";
$result = mysql_query($sql,$db) or die(mysql_error()."<br />SQL: $sql");
//$row = mysql_fetch_array($result);
$ch_id = array();
$ch_title = array();
$ch_content = array();

//do{
while($row = mysql_fetch_array($result)){
	// process data
	$ch_title[] =  $row['ch_title'];
	$ch_content[] =  $row['ch_content'];
	$ch_id[] =  $row['ch_id'];


}//while($row = mysql_fetch_array($result));
for($i = 0; $i < count($ch_title); $i++){
	?>
		<h3><img src="images/<?php print $img[$i]; ?>" alt="<?php print $title[$i]; ?>" border="0"/></h3>
		<fieldset>
		<legend><?php print $ch_title[$i]; ?></legend>
			<?php print $ch_content[$i]; ?>
			</fieldset>
			<form action="JS.php" method="get">
<select name="ch_id">
		  <option value="">Next</option>
		  <?php
			for ($i=0; $i < count($ch_id); $i++){
				print '<option value="'.$ch_id[$i].'">'.$ch_title[$i].'</option>';
			}
		  ?>
</select>
<input type="submit" value="next" />
</form>

Help would truly be great.
thanks

4
Contributors
2
Replies
2 Years
Discussion Span
8 Months Ago
Last Updated
4
Views
MegL
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

As far as the code are concern, it only get data from database and populates it into the dropdownlist in the page.

Probably you have to decide what it should do after you get the selected dropdownlist data from user after he clicked on the "next" button in the form. Hope this would help.

Derice
Junior Poster in Training
83 posts since Mar 2007
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

Is this like a script for throwing multiple pages worth of material onto one with a change in the value of the combo box changing the content of the page without having to reload the page multiple times?

If so, then the answer you are looking for isn't in the php realm, but the javascript realm.

Take this and try it, see if this is something like what you are looking for.

<html>
<head>
<title>Test</title>
<script>
function hidem() {
 	document.getElementById('id1').style.display = "none";
 	document.getElementById('id2').style.display = "none";
 	document.getElementById('id3').style.display = "none";
}

function changeIt(divid) {
	hidem();
	document.getElementById(divid).style.display = "block";
}


</script>
</head>
<body>
<div id="id1"><img src="id1.jpg" /><br />This is One.</div>
<div id="id2" style="display:none"><img src="id2.jpg" /><br />This is Two.</div>
<div id="id3" style="display:none"><img src="id3.jpg" /><br />This is Three.</div>
<br /><br />
<select id="dropbox" onChange="changeIt(this.value)">
<option value="id1">Show me One.</option>
<option value="id2">Show me Two.</option>
<option value="id3">Show me Three.</option>
</select>
</body>
</html>

p.s. - Before anyone here goes to crucify me over my insanely poor javascript skills, understand this is WHY I work in php... :)

Geesh, it's ugly but it works. Understand that the option values could have been dynamically created, as well as the divs for your content. I'm thinking that this is what you were looking to achieve, but I could have misunderstood.

Wraithmanilian
Junior Poster
196 posts since Dec 2009
Reputation Points: 17
Solved Threads: 42
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.2993 seconds using 2.72MB