0

Below given is part of code:

$query1 = "SELECT * FROM table4 WHERE dr_id='{$drid}'";  
                $result1=mysql_query($query1,$con);
                $values1= mysql_fetch_array($result1);
                echo "<br>".$values1['mor_max'];
                $i=$values1['mor_max'];
                $i--;
                echo "<br>".$i;
                $query2="UPDATE table4 SET mor_max= $i WHERE dr_id='{drid}'";

                $result2=mysql_query($query2,$con);

                $values2= mysql_fetch_array($result2);
                echo "<br>".$values2['mor_max'];

Using $i in update query gives no error. Is that ok ? I am a newbie in php so please help. Also warning I am getting is "mysql_fetch_array() expects parameter 1 to be resource, boolean given". Please suggest more efficient way of doing the same.

Lajos Veres
  • 13,452
  • 7
  • 42
  • 56
Mithilesh
  • 188
  • 1
  • 6
  • 17
  • 1
    Don't use the MySQL extension anymore (escpecially if you're creating a new project)! Switch to MySQLi or PDO. Regarding your error message, have you already searched the Internet? It is very common. – ComFreek Oct 23 '13 at 16:29

3 Answers3

2

For decrementing this query should be enough:

UPDATE table4 SET mor_max=mor_max-1 WHERE dr_id='{drid}'
Lajos Veres
  • 13,452
  • 7
  • 42
  • 56
0

You can easily do this in a query

$query = "UPDATE table4 SET mor_max= mor_max -1 WHERE dr_id='{$drid}'";
mysql_query($query, $con);
MaxEcho
  • 13,989
  • 6
  • 76
  • 86
0
$query1 = "SELECT * FROM table4 WHERE dr_id='{$drid}'";  
                $result1=mysql_query($query1,$con);
                $values1= mysql_fetch_array($result1);
                echo "<br>".$values1['mor_max'];
                $i=$values1['mor_max'];
                $i--;
                echo "<br>".$i;
                $query="UPDATE table4 SET mor_max= $i WHERE dr_id='{drid}'";
                $result=mysql_query($query2,$con);
$query2 = "SELECT * FROM table4 WHERE dr_id='{$drid}'";
                $result2 = mysql_query($query1,$con);
                $values2= mysql_fetch_array($result2);
                echo "<br>".$values2['mor_max'];

this code will work. You are getting "mysql_fetch_array() expects parameter 1 to be resource, boolean given" because you are updating in the second query and trying to fetch the same query that is by the way updating the database. you should use the select statement after that you can use the mysql_fetch_array() on that particular query that requires the parameter to be resource.