yahoo5000 yahoo5000 - 5 months ago 8x
PHP Question

Two query at the same time

Hello first of all what i am doing in , i am coding a website for advertise .
Now what do i need is a help to display a lots of data from two tables of database .
What i have done so far u can check at My project you have to login use (Username : test , password : 123456a) to login , so there is everything is okay except an image image are the same on every ads and i do not find the way to make it right .
So i have a "posts" table with an information about ads and an "images" table with a path of an image this is how its looks like : posts table images table

and this is my code :


$userid = $_SESSION["userid"];
$sql = "SELECT * FROM posts WHERE userid='$userid' ";
$res = mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($res)) {
<div id="ads">
<div id="titlepic">
<a href=""><?php echo $row["title"]; ?></a><br>
<a href=""><img src="<?php echo $Photo[0]; ?>" height="100px;"></a>
<div id="managead">
<a href="">Edit</a><br style="margin-bottom: 5px;">
<a href="">Delete</a><br style="margin-bottom: 5px;">
<a href="">Renew</a>
<div id="dates">
<b>Date Added:</b> <?php echo date('m/d/Y', $row["dateadded"]); ?><br>
<b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y', $row["renewdate"]); } ?><br>
<b>Location:</b> <?php echo $row["location"]; ?><br>
<b>Price:</b> <?php echo $row["price"]; ?><br>
<hr width="100%">

so the question is how to extract and images from other table at the same time or how tu run two query at the same time and get an information from them


your SQL statement needs a JOIN in order to include data from two tables in one query.

$sql = "
  FROM posts p
  JOIN images i
    ON = i.postid
  WHERE p.userid='$userid'

this result set will be populated with all columns from both tables. now you can access path1 via:

<?php echo $row["path1"]; ?>