如何从php生成的SQL查询中获取值?

时间:2010-03-15 14:09:10

标签: php sql mysql html

所以我做了一个像这样的查询

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $streams_set = mysql_query($query, $connection);
    confirm_query($streams_set);

在我的数据库中有filds

ID,UID,SID,TIME(所有INT类型执行时间)

所以我正在尝试将查询表格打印成表格

          <form>

  <select class="multiselect" multiple="multiple" name="SIDs">

           <?php        

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $streams_set = mysql_query($query, $connection);
    confirm_query($streams_set);


            $streams_count = mysql_num_rows($streams_set);
            for ($count=1; $count <= $streams_count; $count++) {
        echo "<option value=\"{$count}\"";
        echo ">{$count}</option>";
    } 
          ?>
          </select>
          <br/>
          <input type="submit" value="Submit Form"/>
            </form>

如何从我的SQL查询中打印出“选项”“值”SID?

4 个答案:

答案 0 :(得分:2)

while ($row = mysql_fetch_array($streams_set)) {
 echo '<option value="'.$row['SID'].'">'.$row['SID'].'</option>';
}

答案 1 :(得分:2)

<form>
  <select class="multiselect" multiple="multiple" name="SIDs">
  <?php      

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $queryResult = mysql_query($query, $connection);
    while($row = mysql_fetch_assoc($queryResult)) {          
        echo '<option value="'. $row["id"] .'">'. $row["title"] .'</option>';
    } 
 ?>
 </select>
 <br/>
 <input type="submit" value="Submit Form"/>
</form>

您只需将idtitle索引替换为相应的字段。

答案 2 :(得分:2)

答案 3 :(得分:1)

Ole Jak, 看一下PHP的mysql_fetch_array http://php.net/manual/en/function.mysql-fetch-array.php,这就是你想要在while循环中做的事情: - )