Jump to content

[SOLVED] my drop down box won't populate sql


husin

Recommended Posts

helloe, i have tried like a 5 other ways of populating my dropdown but nothing seems to work. can u guys try and see what's wrong or just give code that works! thank you!

 

ill show u my code:

---

<?php

require("myConnectionInfo.php");

$Query = "select dlname, dfname from donor order by ascending;"

$result=mysql_query($Query);

 

echo '<select name="list">';

while($rec=mysql_fetch_array($result))

{

echo '<option value="' . $rect['dlname'] . '">' . $rec['dfname'] . '</option>';

}

echo '</select>';

?>

 

<html>

<head></head>

<body>

<SELECT NAME=list><OPTION VALUE=0>Choose<?=$options?></SELECT>

<body>

</html>

---

Try this but givei t something to order by...

<?php
require_once("myConnectionInfo.php");
$query = "SELECT * FROM donor ORDER BY (What do you want to order it by ?) ASC")
$result=mysql_query($query);

echo '<select name="list">';
while($rec=mysql_fetch_array($result))
{
echo '<option value="' . $rect['dlname'] . '">' . $rec['dfname'] . '</option>';
}
echo '</select>';
?>

<html>
<head></head>
   <body>
      <SELECT NAME=list><OPTION VALUE=0>Choose<?=$options?></SELECT>
   <body>
</html>

alright, i tried what u said, but nothing. oh and i realized i a "t" after one of the $rec, but still did nothing. no errors, just the dropdown won't populate. and i checked my sql stuff, it's fine. any ideas?

 

here's my coding again. changed the query a bit, but that has no effects to why it's not working.

 

<?php
require("myConnectionInfo.php");
$query = "select concat (dlname, ", ", dfname) as "Donors" from donor order by dlname;;")
$result=mysql_query($query);

echo '<select name="list">';
while($rec=mysql_fetch_array($result))
{
echo '<option value="' . $rec['dlname'] . '">' . $rec['dfname'] . '</option>';
}
echo '</select>';
?>

<html>
<head></head>
   <body>
      <SELECT NAME=list><OPTION VALUE=0>Donors<?=$options?></SELECT>
   <body>
</html>

RESOLVED--thanks for tryn guys. my teacher helped me out :P it was actaully very simple!

 

here's my code. it's a little different though than what i had before:

 

//----//
<?php
//to avoid the caching of the page
header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Mon, 01 Jan 1900 00:00:00 GMT");
header("Pragma: no-cache");

require("connection.php");
$query = "select * from donor order by dlname;";
$result=mysql_query($query);

$selectBox = "<select id='donorID' name = 'donor' onchange='getDonations();'><option>Click Me</option>";
while($rec=mysql_fetch_array($result))
{
$selectBox = $selectBox."<option = $rec[donorNo]>$rec[dlname] $rec[dfname]</option>";
}
$selectBox = $selectBox."</select>";
?>

<html>

<head>
	<script type="text/javascript">
		function getDonations()
{
		var donorID = "donorID=" + document.getElementById('donorID').value;

		var myHTTP = new XMLHttpRequest();
			myHTTP.open("GET", "table.php", false);
			myHTTP.send(null);
			var response = myHTTP.responseText;
			document.getElementById("tableResults").innerHTML = myHTTP.responseText;
}
	</script>
</head>

<body>
	<label>Select Donor: </label><?php echo $selectBox?>
	<div id='tableResults'></div>
<body>

</html>
//----//

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.