Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在没有mysql\u fetch\u数组的情况下打印mysql结果资源\u ID(7)_Php_Mysql - Fatal编程技术网

Php 如何在没有mysql\u fetch\u数组的情况下打印mysql结果资源\u ID(7)

Php 如何在没有mysql\u fetch\u数组的情况下打印mysql结果资源\u ID(7),php,mysql,Php,Mysql,有没有办法在没有mysql\u fetch\u数组的情况下打印资源id。我不想循环查看结果。我只想打印顶部的第一行。我知道mysql已经贬值。这是针对旧项目的。您可以在您的情况下使用数组 $all_rows = array(); . . // your query . while($dbrow = mysql_fetch_array($query)) { $all_rows[] = $dbrow; } $first_row_array = $all_rows[0]; // fir

有没有办法在没有mysql\u fetch\u数组的情况下打印资源id。我不想循环查看结果。我只想打印顶部的第一行。我知道mysql已经贬值。这是针对旧项目的。

您可以在您的情况下使用数组

$all_rows = array();
.
.     // your query
.
while($dbrow = mysql_fetch_array($query))
{
   $all_rows[] = $dbrow;
}

$first_row_array = $all_rows[0]; // first row will be stored here
/* 
   uncomment the below line if you do not want to use the 
   first row again while looping through the remaining 
   rows
*/
/* unset($all_rows[0]); */

foreach($first_row_array as $first_row)
{
    // do something with first row data
}


foreach($all_rows as $dbrow)
{
    // loop through all the rows returned including the first row
}

资源本身是一种毫无意义的类型。它只对特定的函数有意义,比如mysql.*。在查询数据库时,MySQL服务器上分配的某些资源保存了您请求的结果;PHP还不能真正访问这些结果。要在MySQL服务器上为您提供这些资源的句柄,您需要一个资源类型变量。这基本上只是你的问题,如果你想访问MySQL服务器上等待你的数据,请使用这个号码

因此,如果您想从MySQL服务器输出数据,您必须从那里获取数据,例如,使用MySQL_fetch_assoc。然后将数据返回给您,您可以打印


如果你只想要第一个结果,只需调用该函数一次。

在查询末尾添加限制1。我还想在另一个地方使用通过fetch array循环运行的剩余行,但如果我们使用fetch_array两次,它将离开第一行。为什么不使用fetch_array…?要么我误解了OP的要求,要么你可能有。据我所知,OP只想从结果集中分别提取第一行,然后再次循环所有行。我不确定fetch_array或fetch_assoc的用法在这里如何适用。编辑:再看一遍问题。我想他指的是第二次不使用fetch_数组来获取剩余的行