am trying to create a follow like system…I have the follow user id in follow_user table, am trying to get each of the follow user id and use the id to query the products table to get each of the product in that table that belong to each id…I have the script below, the problem is when new product is added it display all the product that match the company id that added the product first before it display any other product.
I want it to display each product order by the added_datetime. if one company add new product 5 days back and add another one today and between that time one company have already added their own product, it should display the new added product first and the other company product before the 5 days old added product. but now the scrpit display the 5 days old product along with it related company added prodct first…Thanks for your help in advance.
include db.php';
$timeL = $pdo->prepare('SELECT user_id FROM follow_user WHERE uid_fk = :uid_fk');
$timeL->bindParam(':uid_fk', $_SESSION['b_user_id'], PDO::PARAM_STR);
$timeL->execute();
foreach ($timeL as $rowL) {
$timeLine[] = array('user_id' => $rowL['user_id'] );
}
if (isset($timeLine)) {
foreach($timeLine as $fID) {
include db.php';
$proL = $pdo->prepare('SELECT * FROM products WHERE company_id = :id ORDER BY `added_datetime` DESC');
$proL->bindParam(':id', $fID['user_id'], PDO::PARAM_STR);
$proL->execute();
foreach ($proL as $rowTL) {
$proTimeLine[] = array('product_id' => $rowTL['product_id'],
'product_name' => $rowTL['product_name'],
'product_price' => $rowTL['product_price'],
'product_description' => $rowTL['product_description'],
'product_image_name' => $rowTL['product_image_name'],
'company_id' => $rowTL['company_id'],
'company_name' => $rowTL['company_name'] );
}
}
}