[英]How to get values from SQL query made by php?
So I made a query like this 所以我做了这样的查询
global $connection;
$query = "SELECT *
FROM streams ";
$streams_set = mysql_query($query, $connection);
confirm_query($streams_set);
in my DB there are filds 在我的数据库中有filds
ID, UID, SID, TIME (all INT type exept time) ID,UID,SID,TIME(所有INT类型的展示时间)
So I am triing to print query relult into form 所以我试图将查询结果打印成表格
<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>
How to print out as "option" "values" SID's from my sql query? 如何从我的SQL查询中以“选项”“值” SID的形式打印出来?
while ($row = mysql_fetch_array($streams_set)) {
echo '<option value="'.$row['SID'].'">'.$row['SID'].'</option>';
}
<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>
You just have to replace the id
and title
index with your appropriate fields. 您只需要用相应的字段替换id
和title
索引。
or mysql_fetch_object() 或mysql_fetch_object()
http://php.net/manual/en/function.mysql-fetch-object.php http://php.net/manual/zh/function.mysql-fetch-object.php
Ole Jak,看看PHP的mysql_fetch_array http://php.net/manual/zh/function.mysql-fetch-array.php ,这是您需要在while循环中执行的操作:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.