Objects (ID, Object, ObjectInfo)
Reviews (ID, Object, Username,Review)
I know that I can use LEFT JOIN to display data from the tables based on the common columns however it seems that I can’t get LEFT JOIN to work in the query when I use WHERE to get the ID of the Object. Basically I want the Object data to be displayed at the top of the page and the reviews are called in a loop because users can add reviews and I only want to display reviews for that object hense why I have a column in the two tables called Object. Here’s an example of how the code looks so far:
Code: Select all
<?php
include ’header.php’;
$id = $_GET[‘id’];
$sql = mysql_query(“SELECT * FROM Objects WHERE id = $id”);
$row = mysql_fetch_array($sql);
$object = $row[‘object’];
$objectInfo = $row[‘objectInfo’];
echo $object;
echo $objectInfo;
while($row = mysql_fetch_array($sql))
{
// Here I want to display reviews that relate to the ID of the object
}So just below the loop in the above code I use an SMF global to check that the user is logged in by using if($context[‘user’][‘is_guest’]) and if they are I echo an HTML form and I’ve also used SMF globals to get the username and the object by calling $object as set previously in the code. If the user isn’t logged in then there will be a login form displayed at the top of the page as this has been included and it’s all working I’m just trying to give you a clear idea of what I’m trying to do and you can tell me if I’m going about this professionally:
Code: Select all
if($context[‘user’][‘is_guest’])
{
echo “You must be logged in to add a review.”;
}
else
{
echo “<form action=\”insert.php\” method=\”post\”>\n”;
echo “<input type=\”hidden\” name=\”object\” value=\””.$object”\”>\n”;
echo “<input type=\”hidden\” name=\”username\” value=\””.$context[‘user’][‘name’].”\”>\n”;
echo “Review: <input type=\”text\” name=\”review\”>\n”;
echo “<input type=\”submit\” value=\”Submit\” />\n”;
}
include ’footer.php’;
?>Code: Select all
<?php
include ‘db.php’;
$object = $_POST[‘object’];
$username = $_POST[‘username’];
$review = $_POST[‘review’];
mysql_query(“INSERT INTO approvals (object,username,review) VALUES (‘$object’,’$username’,’$review’)”);
?>