when running the below code, I do get what i want from the database, and result on the page, but also i'm receiving error message:
warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\surplape\Desktop\xampplite\htdocs\drupal\includes\common.inc(1695) : eval()'d code on line 17.
when I replace $result = mysql_query($query) with $result = mysql_query($query) or die (mysql_error())
I get
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 'AND uid = 1' at line 1
but syntax seems fine to me, any ideas?
the code:
//get node id
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
//get user id
global $user;
$query= "SELECT * FROM webform_submissions WHERE nid = $nid AND uid = $user->uid";
$result = mysql_query($query);
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "bravo you answered already!";
}
Drupal DB API
Rather than use the mysql functions, try the drupal db api instead.
http://api.drupal.org/api/group/database
$query= "SELECT count(1) FROM webform_submissions WHERE nid = %d AND uid = %d";
$row = db_result( db_query( $query, $nid, $user->uid ) );
if ($row > 0){ whatever here }
KH
suprisingly, nothing
suprisingly, nothing happens
it doesn't return any errors, which i gues is good, but it doesn't give me any results which is bad
What is the value of $nid?
What is the value of $nid? And $user->uid? Also have you looked at using Views - might do everything you want without coding.
MySQL
If you construct the SQL statement...
SELECT count(1) FROM webform_submissions where nid=whatever and uid=whatever
and fire it into say phpmyadmin with the correct values of nid and user->uid I presume you get the correct count you're looking for?
If you use the devel module can you confirm that the sql you're expecting is actually kicking in?
KH
yeah, fired up in phpmyadmin
yeah, fired up in phpmyadmin works just fine.
i'm thinking since error is saying mysql_num_rows() expects parameter 1 to be resource, boolean given
maybe there is something wrong in how I'm getting or passing value on node id, I took the below code from drupal.org forum
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
when I echo the $nodeid i get what i want, but it crushes the sql. why it woul print the value (resource) but used boolean in query?
In your original code you
In your original code you seem to be mixing $nid and $nodeid. However I'd strongly suggest using the DB API as Keith suggests.
well I am tryingit
well I am trying
it goes:
$query= "SELECT count(*) FROM webform_submissions WHERE nid = %d AND uid = %d";
$row = db_result( db_query( $query, $nid, $user->uid ) );
if ($row > 0){
echo "WORKS";
}
else{
echo "YOU'RE SHITTIN ME";
}
and it prints else echo value (excuse the frase, but this is really getting to me)
Can you also get it to echo
Can you also get it to echo the values of $nid and $user->uid?
Also you could try hardcoding these values just for now as a test..
Debugging
It does look as though what you're perhaps expecting in nid and/or user->uid is not correct.
Recode your SQL statement to be...
$cSQL = "SELECT Count(1) FROM webform_submissions WHERE nid=" . $nid . " AND uid=" . $user->uid;
echo $cSQL;
and see if that's what you were expecting and what worked in phpmyadmin.
KH