getting Warning: mysql_result() expects parameter 2 to be long, string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    getting Warning: mysql_result() expects parameter 2 to be long, string?

    Retrieving a data from a table. the table has only one filed.
    table name: qupdate
    filed: last_update

    Code:
    $sql4="SELECT * FROM qupdate";
    $result4=mysql_query($sql4);
    $last_update=mysql_result($result4,"last_update");
    but I am getting Warning:mysql_r esult() expects parameter 2 to be long, string...
    on this line,
    Code:
    $last_update=mysql_result($result,"last_update");
    the following code not executing...
    Code:
    if($last_update==$today)
    {
    	$cqid=mysql_result($result,"cqid");
    $update1="update cquestions set showdate='$tomorrow' where showdate='0000-00-00' and cqid!='$cqid' order by cqid limit 2";
    mysql_query($update1);
    }
    I have run the code on my local server (wamp) php 5.2.5. it runs without any problem.

    when I uploaded the code on the web server, (PHP Version 5.5.18) I am getting this warning and the following code not executing.

    full code:
    Code:
    <?php
    
    $today=date("Y-m-d");
    mysql_query("SET CHARACTER SET utf8");
    echo "<form method='post' id='submit' action='checkresult2.php'>";
    $sql="SELECT * FROM cquestions where showdate='$today' limit 1,1";
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
    echo "<p>" . $row['cqtext'] . "</p>";
    $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
    $result2=mysql_query($sql2);
    while($row2=mysql_fetch_assoc($result2))
    {
    echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext'];
    echo"<br>";
    }
    }
    $tomorrow= date("Y-m-d", strtotime("tomorrow"));
    $sql4="SELECT * FROM qupdate";
    $result4=mysql_query($sql4);
    $last_update=mysql_result($result4,"last_update");
    if($last_update==$today)
    {
    	$cqid=mysql_result($result,"cqid");
    $update1="update cquestions set showdate='$tomorrow' where showdate='0000-00-00' and cqid!='$cqid' order by cqid limit 2";
    mysql_query($update1);
    $update2="update qupdate set last_update='$tomorrow'";
    mysql_query($update2);
    $sql3="SELECT * FROM qupdate";
    $result3=mysql_query($sql3);
    $last_update=mysql_result($result3,"last_update");	
    }
    echo"<br>";
    echo"<br>";
    echo "<div align='left' style='padding-left:160px;'>";
    echo"<input type='submit' id='submit' name='submit' value='التالي' />";
    echo "</div>";
    echo "</form>" ;
    ?>
    how to fix this?
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    In the manual it says:
    string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )

    This means that the second parameter should be an int

    If a string is given as second parameter,
    then PHP will try to convert this to an int (because it expects an integer),
    if that fails, than the warning is shown....

    You should read the docs, and probably (i'm not seeing your comlete code) you can change this second parameter to '0' (without the single quotes), Because this second parameter is defined as: "The row number from the result that's being retrieved. Row numbers start at 0. "

    Comment

    • impin
      New Member
      • Jul 2010
      • 127

      #3
      that's works. great! thank you.

      Comment

      Working...