I want to mysql query in a table that has 4 fields: id, user_one, user_two, hash.
$check_con = mysql_query("SELECT count(hash) FROM messages_group WHERE (user_one=$my_id AND user_two=$other_id) OR (user_one=$other_id AND user_two=$my_id)");
$amsik = mysql_fetch_array($check_con);
$currenthash=$amsik['hash'];
if ($amsik['COUNT(hash)'] > 0){
mysql_query("INSERT INTO messages VALUES('', '$currenthash', '$my_id', '$message')");
header('location: m.php?hash='.$currenthash.'');
} else{
mysql_query("INSERT INTO messages_group VALUES('$my_id', '$other_id', '$random_number','')");
mysql_query("INSERT INTO messages VALUES('', '$random_number', '$my_id', '$message')");
header('location: m.php?hash='.$random_number.'');
}
}
This if statement doesn't work. It always goes with the else part. I mean when I try to run it if even there is more than 1 rows, it creates a new hash in messages_group by random number. What should i do?