如何显示各自数据的列名。
$sql="SELECT * FROM <Tablename> WHERE domain_name='google.com'";
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result,MYSQLI_NUM);
echo "<table>";
for ($i=0; $i <sizeof($row) ; $i++) {
echo "<tr>";
echo "<td>";
echo mysql_field_name($row,$i); // its not working.
echo $row[$i]."<br/>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
请帮忙。
答案 0 :(得分:2)
您可以使用fetch_field_direct
:
for ($i=0; $i <sizeof($row) ; $i++) {
...
$finfo = $result->fetch_field_direct($i);
echo $finfo->name;
...
}
答案 1 :(得分:0)
试试此代码
if ($result->num_rows > 0) {
while($row = mysqli_fetch_array($result,MYSQLI_NUM)) {
echo "<tr>";
echo "<td>";
echo $row[0]."<br/>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
答案 2 :(得分:0)
使用while(true)
{
size_t bytes_avail;
ioctl(fd, FIONREAD, &bytes_avail);
if(bytes_avail == 0)
break;
int n = read (fd, buf, (sizeof buf)-1);
if(n<0)
{
//error handling
fprintf(stderr, "Error while receiving message: %s\n", strerror(errno));
return;
}
buf[n] = '\0';
// you can add a check here to see if (length+n) < 1024
strcat(msg, buf);
length += n;
}
获取列名称。
mysqli_fetch_assoc
您将获得$sql='SELECT * FROM mytesttable WHERE username="as"';
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_assoc($result);
header('Content-type: application/json');
echo json_encode($row);
。如果您需要在output as json response
中输出,将来这可能会有所帮助。
谢谢,希望这对其他人有帮助。