|
Posted by J.O. Aho on 10/10/80 11:39
- Dazed wrote:
> How do I combine the two following statements where I am selecting
> everything from "category" where id=$id and sponsor='0' or $userid ?
>
> Thanks for any help!
>
> $result = mysql_db_query($database, "SELECT * FROM category WHERE
> id=$id and sponsor='0'");
>
> $result = mysql_db_query($database, "SELECT * FROM category WHERE
> id=$id and sponsor=$userid");
From the manual: http://www.php.net/manual/en/function.mysql-db-query.php
This function is deprecated, do not use this function. Use mysql_select_db()
and mysql_query() instead.
<?PHP
/* You should have had this before in your code */
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
/* This select that we use yourdatabase as the current database */
$db_selected = mysql_select_db('yourdatabase', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
/* We use mysql_query() */
$result = mysql_query("SELECT * FROM category WHERE id=$id and (sponsor='0' OR
sponsor='$userid')");
if($result) {
while ($row = mysql_fetch_array($result)) {
/* We just make an ugly printout of the data */
print_r($row);
}
}
?>
//Aho
[Back to original message]
|