
I need the mysql query to get the items whose nid > 910 for user_id=1 and nid > 902 for used_id <> 1.
Anybody done this? Searched but cant find it, since i am new to php and mysql.
SQL Query:
SELECT * FROM table_name WHERE (nid>910 AND user_id=1) OR (nid>902 and user_id!=1);
But if you want to call it from PHP you'll need something like this:
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("exampledb",$dbhandle)
or die("Could not select exampledb");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM table_name WHERE (nid>910 AND user_id=1) OR (nid>902 and user_id!=1);");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'user_id'}." Nid:".$row{'nid'}."<br />";
}
?>