Is it possible to run two queries inside of one connection. What I am doing is I am populating a form with profile data. But then I need to populate two drop downs from a database that contains the values. I have included how I have it setup but my first drop down never is populated what am I doing wrong?
<?php
session_start();
include("includes.php");
$uid = $_SESSION[username];
try
{
开发者_如何学Python$con = mysql_connect("XXX.XXX.XXX.XX","ita","iiiii");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bia", $con);
$options = mysql_query("SELECT * FROM `Schools`");
$options = array();
while($row = mysql_fetch_assoc($options))
{
$options[] = $row;
}
$result = mysql_query("SELECT * FROM `users` WHERE uid = '$uid'");
while($row = mysql_fetch_assoc($result)){
?>
<form id="myform" name="myform" action="profiledo.php" method="post">
<p>First Name
<input type="text" name="firstname" id="textfield" value="<?php echo( htmlspecialchars( $row['FirstName'] ) ); ?>" />
<br />
<label for="collegedropdown"></label>
<select name="collegedropdown" id="collegedropdown">
<?php
foreach($options as $option) {
print '<option value='.$option.'>'.$option.'</option>'."\n";
}
}
?>
</select>
You can have any number of queries in a single connection.
Here are a couple of things I can see right away:
- mysql_fetch_assoc returns an array, but I'm tempted to say you're treating it like a string?
- There are no quotes around your
value
? - You're overwriting
$options
(it's your MySQL result and then turns into your results array)?
精彩评论