0

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

3
Contributors
2
Replies
7
Views
7 Years
Discussion Span
Last Post by Wraithmanilian
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.

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.

Edited by Wraithmanilian: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.