我需要从数据库中提取记录,如下所示:
id
name
request1
request2
request3
request4
request5
time
请求字段可以是0或1
我有我的SQL查询SELECT * FROM table ORDER BY id ASC
,但我只获得一行记录,但我需要打印这样的记录:
id1 - name1 - request1
id1 - name1 - request2
id2 - name2 - request4
id2 - name2 - request5
这意味着每个单独的“request = 1
”
我怎么能负担得起?
require("datisql.php");
dbconnect();
mysql_query("SET CHARACTER SET 'utf8'");
$result2 = mysql_query("SELECT * FROM richieste ORDER BY id DESC");
while($row = mysql_fetch_array($result2)) {
$id="{$row['id']}";
$nominativo="{$row['nominativo']}";
$data="{$row['timestamp']}";
echo"<div>...........";
}
这是请求表的摘要:click me
答案 0 :(得分:0)
我的回答是基于所有请求列都在一行中的假设。如果我错了,我会改变它。我将处理一个看起来像这样的记录集的方法是遍历每一行并将每一行抛出到for循环中:
// Add each of the request types to an array
$requestTypes = array('Interior','Exterior');
// Loop through the resultset
while( $row = mysql_fetch_array( $result2 ) ){
foreach($requestTypes as $type){
$id= $row['id'];
$nominativo = $row['nominativo'];
$requestedType = $row[$type];
$data = $row['timestamp'];
}
}