开发者

PHP MySQL Run Two Queries in one Connection?

开发者 https://www.devze.com 2023-03-23 15:54 出处:网络
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 va

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)?
0

精彩评论

暂无评论...
验证码 换一张
取 消