I really could not understand what I am missing then I thought it would nice to ask you guys. Here is my code sample.
foreach ($disArray as $a) {
$query = "SELECT num FROM ".$tableName." WHERE question='" . $a."'";
$result = mysql_query($query, $this->conn) or die('Error: '.mysql_error());
$row = mysql_fetch_array($result);
//$row['num'] = $row['num'] + 1;
$numb = $row['sayi'] + 1;
$query = "UPDATE ".$tablename." SET `num`=" . $numb . "WHERE `question`=" . $a . "\"";
mysql_query($query, $this->conn);
}
Here disArray
is an array :) And I am looping through it and it stores "senteces" in it. What I am trying to do is comparing those sentence with the ones in the table but I guess I have an error in my this $query = "SELECT num FROM ".$username." WHERE question='" . $a."'";
query, as it gives and error like开发者_如何学Go this;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE question='Where are you from?'' at line 1
Also I was getting an error that says mysql_fetch_array requires resource but you are giving booling etc. But I do not know what it stops giving that error as well. What do you think guys? What would be the problem? Thanks in advance!
instead of $username you should provide database tablename to check
$query = "SELECT num FROM '".$username."' WHERE question='" . $a."'";
Apparently problem is in your username variable, check if the value is correctly set.
I recomend add quote as shown below!
$query = "UPDATE ".$tablename." SET num
=" . $numb . "WHERE question
='" . $a . "'"
Instead of:
$query = "SELECT num FROM ".$tableName." WHERE question='" . $a."'";
Use this:
$query = ' SELECT `num` FROM `'.$tableName.'` WHERE `question` = "'.$a.'" ';
精彩评论