I have two databases. Database one has a list of uploaded documents stored by title, id, who's it for (by position) and location of the document in the database. The second database stores details every time the book is read. This stores the id (taken from the first database) and the logged in username.
I have two queries. The first looks in the second database and stores all the ids with the current user number as an array. (The echo is for testing.) The second looks in the first database and lists all the documents not read but looks for items not like the details found. However, I am stuck with making the second query loop through each id that was found by the first query, so it only searches the first number.
This is my code:
<?php
$connection = mysql_connect("host","database","password") or die("Couldn't make connection.");
$db = mysql_select_db("database", $connection) or die("Couldn't select database.");
$sql = "SELECT * FROM `READ` WHERE `name` = '$user'";
$sql_result = mysql_query($sql,$connection) or die("Couldn't execute query 1.");
while($row1 = mysql_fetch_array($sql_result))
{
echo "<br>".$row1['item'];
$ident = $row1["item"];
}
mysqli_close($connection);
?>
<?php
$connection = mysql_connect("host","database","password") or die("Couldn't make connection.");
$db = mysql_select_db("database", $connection) or die("Couldn't select database.");
$query ="SELECT * FROM UPLOAD WHERE id NOT LIKE '$ident' AND faoGrade LIKE '%$gr%'";
//$ident only searching the first number stored
$query_result = mysql_query($query,$connection) or die("Couldn't execute query 2.");
while($row2 = mysql_fetch_array($query_result))
{
echo "<br>".$row2["title"];
}
mysqli_close($connection);
?>
I am definitely going past my current knowledge and think I need a for i=
, for each id found
or a while
, but I'm not sure how to get it to work. the $gr
and $user
are session variables at the top of the page. I have updated to mysqli, but I'm not to familiar with it yet.