|sql returns nothing|
For those who might not be aware, the following takes the $_POST vars from a submitted form and does a db lookup based upon the chosen user variables.
$advquery = "SELECT SUM(pc_count) as amount FROM $tablename WHERE pc_place IN('" . implode("','", $_POST['chosenoption']) . "')";
$adv = mysql_fetch_array($advcresult);
echo" $adv[amount] ";
The above returned a result when I echoed $advquery to the browser, and ran the contents through phpmyadmin's sql interpreter. However, the same query when run through the script itself ( as above), outputs nothing to the browser, yet I know for certain it should ( based upon the chosen data at least).
Would anyone know why?
It doesn't use reserved words either.
Heres the table structure, just in case this is the prob.
CREATE TABLE placecount (
pc_count varchar(20) NOT NULL default '',
pc_place varchar(60) NOT NULL default '',
PRIMARY KEY (pc_place),
KEY pc_place (pc_place)
Thanks for any pointers.
I've looked at this pretty closely, and it looks okay to me.
Have you tried calling mysql_error() to see what that says?
I think it's the quote implode...
$imploded_chosenoption = "'".implode("','", $_POST['chosenoption'])."'";
$advquery = "SELECT SUM(pc_count) as amount FROM $tablename WHERE pc_place IN($imploded_chosenoption)";
Will try that first thing in the morning Salsa and let you know how I get on :)
echo"$advchrow[amount] here ";
:( Oh well, tried your suggestion but no joy.
I get "No result".
This is so weird, coz like I said, when I cut and past the echoed $advquery from the submitted page directly via phpmyadmin, the very same query works.
I think I might need to rethink my plan.
You got "No result", but what error did you get from MySQL?
No error at all.
Could be a php setting in the ini file maybe?
Yes, I tested your original $advquery construction, and it seemed to echo out a fine query.
One thing that could be making a difference between venues is, where does $_POST['chosenoption'] come from? Have you tried a,
to see if the array is really there.
Also, I was moving hastily when I gave you the mysql_error() line. You need to echo it or put it in die(), etc.
if(!$advcresult) echo mysql_error(); //or
I wish you well.
another thought. If you haven't included method="post" in your form tag, the array may be in $_GET.
...and just echo out $advcresult to see that in isn't a typo when setting $tablename, or something.
Let me know what you find out.
> Try print_r($_POST);
Yes I'd checked to see if the array existed, and checked the form action of the sending page was set to POST.
> if(!$advcresult) die(mysql_error());
This unlocked it. No connectin to Database (hangs head in shame) How did I miss this? Sigh...
I'd failed to include the require "../dbconn.php"; line in an if condition of the script.
Feel like a right plonker now!
Thanks very much for all your help, :) its very much appreciated.