Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 4:54 am
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.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Sep 22, 2004 5:17 am
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.
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 5:36 am
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...
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Sep 22, 2004 5:38 am
[php_man]types.string[/php_man]
notice that your syntax is wrong.
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 5:43 am
I know mate but I can't seem to get it right...!
I'll keep plugging away though...
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Sep 22, 2004 6:06 am
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'");
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 6:10 am
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.
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 6:22 am
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...?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Sep 22, 2004 6:27 am
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);
?>
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Sep 22, 2004 6:28 am
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.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Sep 22, 2004 6:29 am
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);
?>
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 7:34 am
Worked a treat
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.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Sep 22, 2004 7:54 am
good luck
view source of the web page is your friend.
Harlequin
Forum Commoner
Posts: 51 Joined: Tue Sep 21, 2004 10:51 am
Location: UK
Post
by Harlequin » Wed Sep 22, 2004 8:06 am
AHA...!
I forgot to close the <table> TAG
Thanks once again...!