Mysql_fetch_array() [英] Mysql_fetch_array ( )
问题描述
Dears
i只想询问mysql_fetch_array()函数
它是如何工作的?
i知道它检索一个数组
我的问题将在下面的例子中更加明确。
<?php
$ con = mysql_connect ( localhost, root, )
if (!$ con)
{
die( error .mysql_error());
}
$ query = select * from emp ;
$ result = mysql_query($ query);
while($ data = mysql_fetch_array($ result))
{
echo $ data [0]。$数据[1]。$ data [2]。$ data [3]
}
?>
当我执行上面的代码时,它运行正常没有问题。
我的问题来自我尝试下面的代码
<?php
$ con = mysql_connect( localhost, root, );
$ query = select * from emp;
$ result = mysql_query($ query);
$ data = mysql_fetch_array($ result);
// 现在我尝试按记录从DB记录中获取记录。
echo $ data [0]。$ data [1]。$ data [2]。$ data [3]; // 它将打印emp表中的第一行。
// 这是我的问题,让我们再试一次。
$ data = mysql_fetch_array($ result);
echo $ data [0]。$ data [1]。$ data [2]。$ data [3]; // 它将显示emp表中的第二行,这是我的问题如何以及为什么???
?>
当我调用此函数时第二次:[ $ data = mysql_fetch_array($ result); ]
它应该包含整个表格,因此再次显示第一行
为什么显示第二个?
我需要澄清一下,谢谢:)
< blockquote> con = mysql_connect( localhost, root, )
if (!
con)
{
die( 错误 .mysql_error());
}
query = select * from emp跨度>;
Dears
i just want to asks about mysql_fetch_array( ) function
how does it works ?
i know that it retrieves an array
my question will be more clarify in the below example .
<?php
$con=mysql_connect("localhost","root","")
if (!$con)
{
die ("error ".mysql_error());
}
$query="select * from emp";
$result=mysql_query($query);
while( $data=mysql_fetch_array($result))
{
echo $data[0].$data[1].$data[2].$data[3]
}
?>
when i execute the above code , it works fine with no problem .
my question comes after i try the below code
<?php
$con=mysql_connect("localhost","root","");
$query="select * from emp ";
$result=mysql_query($query);
$data =mysql_fetch_array($result);
//now i try to get the record from DB record by record .
echo $data[0].$data[1].$data[2].$data[3]; //it will print the first row from emp table .
//here is my question , lets try to execute it again .
$data =mysql_fetch_array($result);
echo $data[0].$data[1].$data[2].$data[3]; // it will display the second row from emp table and here is my question How and why ???
?>
when i call this function for the second time : [ $data =mysql_fetch_array($result); ]
it should contain the whole table and therefore display the first row again
why it display the second one?
kindly i need a clarification for this , thanks :)
con=mysql_connect("localhost","root","") if (!
con) { die ("error ".mysql_error()); }
query="select * from emp";
这篇关于Mysql_fetch_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!