简体   繁体   中英

the function mysql_result

If there is an error function mysql_result then it returns 0?

I looked everywhere but i could not find an answer ....

<?php
    include "config.php";
    $result = mysql_query("SELECT `price` FROM `prices` where bin = 1 limit 0,10" ) ;
    $i=0;
    $d=0;
    while($i!=10){
        $d=$d+mysql_result($result, $i)or die($d);  
        $i++;
    }
?>

its returns 7 errors ...

( ! ) Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 5 in C:\\wamp\\www\\fom\\Untitled 1.php on line 7

Try this:

<?php
    include "config.php";
    $result = mysql_query("SELECT `price` FROM `prices` where bin = 1 limit 0,10" ) ;
    $i=0;
    $rows = mysql_num_rows($result);
    $d=0;
    while($i < $rows && $tmp=mysql_result($result, $i++)){
        $d+=$tmp;
    }
?>

In my opinion, you shouldn't use mysql_result. It is slower than the other methods.

Try mysql_fetch_array()

prototype:

while ($row =
    mysql_fetch_array ($result)){

echo (whatever you want depending upon the index);

}

or you can also return it as an array.

尝试删除第7行的die($ d)并再次检查。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM