Posts: 451
Threads: 16
Joined: Feb 2003
Quote:Code:
// Define sql
$sql = "SELECT foo, joe AS bar
FROM blah
WHERE condition
AND other_condition
LIMIT number, number";
// Do query
if ( !$result = @mysql_query( $sql ) )
{
// die, with nice, formatted output. I suggest a function for this
die('
Database Query Error!
' . mysql_error() . '
$sql
Line: ' . __LINE__ . ', File: ' . __FILE__);
}
// Get each result, and store it in $row as we go
while ( $row = mysql_fetch_array( $result ) )
{
// Do what you will with each result
$foo = $row['foo'];
$joe = $row['bar']; // Note, the AS bar clause means joe is in bar
}
[end oracle's quick db tutorial]
You may not be aware of this, but not all SQL databases use the same logical operators.
I run mySQL and it doesn't like 'AND', rather, it uses the C-Style operator 'f '&&'.
[end 1000101's quick note on oracle's quick db tutorial]
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Posts: 1,845
Threads: 44
Joined: Aug 2002
In standard SQL (stdSQL), which has been internationalized, it is AND, OR, and NOT
Posts: 451
Threads: 16
Joined: Feb 2003
Be that as it may, not all people/servers may be running an SQL database which follows the standard. I was just pointing this out.
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Posts: 3,616
Threads: 287
Joined: Jan 2003
Quote:I'm getting oodles of mysql errors, but he're a toast to rel.
*toast*
get well soon, buddy
Um, um...errors? It was working fine...
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 672
Threads: 27
Joined: Aug 2001
Posts: 530
Threads: 17
Joined: May 2002
Posts: 3,343
Threads: 83
Joined: Mar 2003
Quote:You may not be aware of this, but not all SQL databases use the same logical operators.
I run mySQL and it doesn't like 'AND', rather, it uses the C-Style operator 'f '&&'.
[end 1000101's quick note on oracle's quick db tutorial]
I also run mysql. It handles AND fine. I think you'll find that && may have more precedence, that's all
Besides, it was just an example query. There's nothing wrong with the algo which I posted.
Posts: 451
Threads: 16
Joined: Feb 2003
Quote:I also run mysql. It handles AND fine. I think you'll find that && may have more precedence, that's all
Besides, it was just an example query. There's nothing wrong with the algo which I posted.
heh, I was just pointing out that mySQL can be quirky depending on the version you run
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Posts: 3,343
Threads: 83
Joined: Mar 2003
Better to use Postgres then. But I can't find a free webhost that uses postgres... I have to use it through linux