Page 1 of 1

Query Not Executing Correctly

Posted: Wed Sep 22, 2004 4:54 am
by Harlequin
I have the following query which returns a "Query Empty" error:

Code: Select all

$Query = mysql_query("SELECT * FROM events
   WHERE EventCode == 'PMJ';
   ORDER BY EventTime DESC");
   $Data = mysql_query($Query) or die("Error: " . mysql_error());
   while($row = mysql_fetch_array($Query))
Can anyone see what I can't...? I've checked and double checked and it seems OK and there's definately data in the tale.

echo

Posted: Wed Sep 22, 2004 5:17 am
by phpScott
echo out the query and run it against the db directly

but I think it is the == try just using a single =
mysql isn't the same a php for checking if an item is equal.

Posted: Wed Sep 22, 2004 5:36 am
by Harlequin
Well, this is just driving me mad...

This works when I execute it against the database:

Code: Select all

SELECT * FROM events
WHERE EventCode = 'PMJ';
But this, in the PHP code doesn't:

Code: Select all

$Query = mysql_query "SELECT * FROM events
WHERE EventCode = 'PMJ'";
I get "Unexpected T_STRING


Grrr...

Posted: Wed Sep 22, 2004 5:38 am
by timvw
[php_man]types.string[/php_man]

notice that your syntax is wrong.

Posted: Wed Sep 22, 2004 5:43 am
by Harlequin
I know mate but I can't seem to get it right...!

I'll keep plugging away though...

two different codes

Posted: Wed Sep 22, 2004 6:06 am
by phpScott
OK you now have to different sets of codes
the second set
$Query = mysql_query "SELECT * FROM events
WHERE EventCode = 'PMJ'";
will not work because you need the () around the select statement.
try

Code: Select all

$Query = mysql_query ("SELECT * FROM events
WHERE EventCode = 'PMJ'");

Posted: Wed Sep 22, 2004 6:10 am
by Harlequin
I tried that Scott. Now I get a syntax error returned so I must have something screwed up later in the query where I am trying to present the results.

Thanks very much for the tip mate.

Posted: Wed Sep 22, 2004 6:22 am
by Harlequin
Scott.

I know this is basic stuff but I just can't sem to get it working properly:

I Execute the query:

Code: Select all

// Select Events For PMJ:
   $Query = mysql_query ("SELECT * FROM events 
   WHERE EventCode = 'PMJ'");
Then I get the error (SQL Syntax":

Code: Select all

$Data = mysql_query($Query) or die("Error: " . mysql_error());
   while($row = mysql_fetch_array($Query))
   {
// Pull Strings From Table:
   $EventDate=$rowї"EventDate"];
   $EventDateBroken = explode("-", $EventDate);
What's causing the error...? Can you see it...?

Posted: Wed Sep 22, 2004 6:27 am
by John Cartwright

Code: Select all

<?php
   $Data = mysql_query($Query) or die("Error: " . mysql_error()); 
   while($row = mysql_fetch_array($Query)) 
   { 
// Pull Strings From Table: 
   $EventDate=$row["EventDate"]; 
   $EventDateBroken = explode("-", $EventDate); 
?>
should b

Code: Select all

<?php
   $Data = mysql_query($Query) or die("Error: " . mysql_error()); 
   while($row = mysql_fetch_array($Data)) 
   { 
// Pull Strings From Table: 
   $EventDate=$row["EventDate"]; 
   $EventDateBroken = explode("-", $EventDate); 
?>

just say it

Posted: Wed Sep 22, 2004 6:28 am
by phpScott
you are doing

Code: Select all

$Query = mysql_query("SELECT * FROM events
   WHERE EventCode == 'PMJ';
   ORDER BY EventTime DESC");
   $Data = mysql_query($Query) or die("Error: " . mysql_error());
   while($row = mysql_fetch_array($Query))
what you are doing is creating the $Query with mysql_query() in it.
then with $DATA you are agian using mysql_query().

try

Code: Select all

$Query = "SELECT * FROM events
   WHERE EventCode == 'PMJ';
   ORDER BY EventTime DESC";
   $Data = mysql_query($Query) or die("Error: " . mysql_error());
   while($row = mysql_fetch_array($Data))
$query now only holds the text for the query, it then gets submitted to mysql_query();
$Data will now hold your result set.

Posted: Wed Sep 22, 2004 6:29 am
by John Cartwright

Code: Select all

// Select Events For PMJ:
   $Query = "SELECT * FROM events 
   WHERE EventCode = 'PMJ'";
and then

Code: Select all

<?php
   $Data = mysql_query($Query) or die("Error: " . mysql_error()); 
   while($row = mysql_fetch_array($Query)) 
   { 
// Pull Strings From Table: 
   $EventDate=$row["EventDate"]; 
   $EventDateBroken = explode("-", $EventDate); 
?>
should b

Code: Select all

<?php
   $Data = mysql_query($Query) or die("Error: " . mysql_error()); 
   while($row = mysql_fetch_array($Data)) 
   { 
// Pull Strings From Table: 
   $EventDate=$row["EventDate"]; 
   $EventDateBroken = explode("-", $EventDate); 
?>

Posted: Wed Sep 22, 2004 7:34 am
by Harlequin
Worked a treat 8)

Now all i need to do is get the tables layed out correctly. For some reason when I insert a table below the code for the last table it's header text appears above the last table. 8O

good luck

Posted: Wed Sep 22, 2004 7:54 am
by phpScott
good luck
view source of the web page is your friend.

Posted: Wed Sep 22, 2004 8:06 am
by Harlequin
AHA...!

I forgot to close the <table> TAG 8)

Thanks once again...!