RE: [PHP] Why does query work in MySQL but not in PHP doc
| From: | Emile Axelrad | Date: | Sat, 08 Jul 2000 11:29:28 +0000 |
| Subject: | RE: [PHP] Why does query work in MySQL but not in PHP doc | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5528@lists.php.net to get a copy of this message | ||
> I am using two tables within one database and want to query both tables:
>
> When I type this line in MySQL program it works:
> SELECT * from albums, songs WHERE albums.AlbumID = 2 and
> songs.albumid = 2 and albums.album = "Collection";
its a fine SQL query on its own...nothing wrong.... [although you might like
to put AND in uppercase because it's a command/operator...
> When I try and use this with php form I get nothing
> $query = "SELECT * FROM albums, songs WHERE albums.AlbumID = 2
> and songs.albumid = 2 and albums.album = "Collection";
You want this:
a) You didn't have a closing "
b) Collection should have been in single ' delimiters so that the $query
variable isn't closed at the first one:
$query = "SELECT * FROM albums, songs WHERE albums.AlbumID = 2 AND
songs.albumid = 2 AND albums.album = 'Collection'";
> $result = mysql_db_query("musicdb", $query);
Fine...
> if ($result) {
> echo "Found these entries in the database:<ul>";
>
> while ($r = mysql_fetch_array($result)) {
> $AlbumID = $r["AlbumID"];
> $Album = $r["Album"];
>
>
> <TD> <? echo "$Album"; ?></TD>
> <TD> <? echo "$Artist"; ?></TD>
Fine, need a closing
}
}
remember.
- Emile Axelrad - www.protonic.com : free fast technical support -