...

View Full Version : Dropdown list from DB



cheryl
02-15-2006, 02:13 PM
<style type="text/css">
<!--
.style1 {
color: #FF6600;
font-family: Verdana;
font-weight: bold;
}
.style2 {font-family: Verdana}
-->
</style>
</head>

<body>

<?
include("db.php");

$link = @mysql_connect("localhost", $dbusername, $dbpassword);

if (!$link)

die ("Couldn't connect to MySQL");

mysql_select_db($dbname, $link)

or die ("Couldn't open $db".mysql_error());


$orgSelect = "Select clientName From client Order By clientName ASC";

$orgSelected = mysql_query($orgSelect, $link)
or die ("Couldn't execute orgSelect query");

while ($row = mysql_fetch_array($orgSelected))
{
$orgoption = $row["clientName"];

$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}

$tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";

$tableSelected = mysql_query($tableSelect, $link)
or die ("Couldn't execute tableSelect query");

while ($row = mysql_fetch_array($tableSelected))
{
$tableOption = $row[""];

$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}
?>
<form method="POST" action="searchresults.php">
<table width="430" border="0"> ">
<tr>
<td width="363"><span class="style1"><u>Search</u></span></td>
</tr>
<tr>
<td><span class="style2">Organisation:</span><span class="style4">
<select name="clist" id="clientlsit">
<?php echo "$clientOp";?>
</select>
</span></td>
</tr>
<tr>
<td class="style2">Member Type:
<select name="typetable" id="mtypetable">
<? echo "$tableOp";?>
</select></td>

</tr>
<tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>



i can't seem to populate the dropdown list from database.

Wanna retrieve clientName from client table, and the member, nonmember and nimember table from db.

i'm getting "Couldn't execute tableSelect query" error.

someone please help see if anything wrong with the codes.

degsy
02-15-2006, 02:35 PM
You have some bad coding in there, but the main reason is because you are saving the loop into a variable but not echoing it.



while ($row = mysql_fetch_array($orgSelected))
{
$orgoption = $row["clientName"];

$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}
?>




while ($row = mysql_fetch_array($orgSelected))
{
$orgoption = $row["clientName"];

$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}
echo $clientOp;

?>

cheryl
02-15-2006, 03:09 PM
<style type="text/css">
<!--
.style1 {
color: #FF6600;
font-family: Verdana;
font-weight: bold;
}
.style2 {font-family: Verdana}
-->
</style>
</head>

<body>

<?
include("db.php");

$link = @mysql_connect("localhost", $dbusername, $dbpassword);

if (!$link)

die ("Couldn't connect to MySQL");

mysql_select_db($dbname, $link)

or die ("Couldn't open $db".mysql_error());


$orgSelect = "Select clientName From client Order By clientName ASC";

$orgSelected = mysql_query($orgSelect, $link)

or die ("Couldn't execute orgSelect query");

while ($row = mysql_fetch_array($orgSelected))
{
$orgoption = $row["clientName"];

$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}
echo $clientOp;

$tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";

$tableSelected = mysql_query($tableSelect, $link)
or die ("Couldn't execute tableSelect query");

while ($row = mysql_fetch_array($tableSelected))
{
$tableOption = $row[""];

$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}
echo $tableOp;
?>
<form method="POST" action="searchresults.php">
<table width="430" border="0"> ">
<tr>
<td width="363"><span class="style1"><u>Search</u></span></td>
</tr>
<tr>
<td><span class="style2">Organisation:</span><span class="style4">
<select name="clientlist" id="clientlist">
<?php echo "$clientOp";?>

</select>
</span></td>
</tr>
<tr>
<td class="style2">Member Type:
<select name="typetable" id="typetable">
<? echo "$tableOp";?>

</select>
</td>

</tr>
<tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>


i think there's still something wrong with it.

how can i select TABLES from the db??

marf
02-15-2006, 08:43 PM
Umm this is what I think


while ($row = mysql_fetch_array($orgSelected))
{
$orgoption = $row["clientName"]; // I dont see anywhere this variable is used

$name = $row['clientName'];

$clientOp .= "<OPTION value=".$name.">".$name."</OPTION>";
}
echo $clientOp; //This isn't needed, he echos the whole thing further down


because he is using the .= operator it just keeps adding an option to the string, which should work perfectly.

cheryl
02-16-2006, 01:06 AM
it still doesn't work. I got a Couldn't execute tableSelect query.

could someone see what is wrong with it?



<style type="text/css">
<!--
.style1 {
color: #FF6600;
font-family: Verdana;
font-weight: bold;
}
.style2 {font-family: Verdana}
-->
</style>
</head>

<body>

<?
include("db.php");

$link = @mysql_connect($dbhost, $dbusername, $dbpassword);

if (!$link)

die ("Couldn't connect to MySQL");

mysql_select_db($dbname, $link)

or die ("Couldn't open $dbname".mysql_error());

//$clientName = 'clilentName';
//$tableType = 'tableType';


$orgSelect = "Select clientName From client Order By clientName ASC";

$orgSelected = mysql_query($orgSelect, $link)

or die ("Couldn't execute orgSelect query");

while ($row = mysql_fetch_array($orgSelected))
{
$clientName = $row['clientName'];

$clientOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}


$tableSelect = "Select member, nonmember, nimember From forzanim_imsdb";

$tableSelected = mysql_query($tableSelect, $link)

or die ("Couldn't execute tableSelect query");

while ($row = mysql_fetch_array($tableSelected))
{
$tableType = $row['tableType'];

$tableOp .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
}

?>
<form method="POST" action="searchresults.php">
<table width="430" border="0"> ">
<tr>
<td width="363"><span class="style1"><u>Search</u></span></td>
</tr>
<tr>
<td><span class="style2">Organisation:</span><span class="style4">
<select name="clientlist" id="clientlist">

<?php echo "$clientOp";?>

</select>
</span></td>
</tr>
<tr>
<td><span class="style2">Member Type:
</span>
<select name="typetable" id="typetable">

<? echo "$tableOp";?>

</select>
</td>

</tr>
<tr><td colspan='2' align='center'><input type="SUBMIT" name='submit' value="Search"> <input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>


i need to be able to get the client(organisation) & table type (member, nonmember &nimember) dropdown list before i can continue to write queries to select the data.

would appreciate there are people who can help. thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum