<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
<title>Plum List</title>
</head>
<body>
<div id ="wrapper">
<div id="header">
<h1>Plum List</h1>
</div>
<?php
require_once 'core/init.php';
include 'navBar.php';
$user = new User();
if(!$user->isLoggedIn()) {
Redirect::to('index.php');
}
function __toString(){
return $this->User();
}
try{
$db = new PDO("mysql:host=localhost;dbname=serverside", 'root', '');
$db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
echo $e->getMessage();
die();
}
$premListing = $db->prepare("
SELECT img_upload.img_id, img_upload.img_path, img_upload.img_id
FROM img_upload
INNER JOIN ads
ON img_upload.img_id=ads.ad_id
WHERE adList = 3
LIMIT 4;
");
$premListing->execute();
$premListing = $premListing->fetchAll(PDO::FETCH_ASSOC);
?>
<div id="premHeader">
<h1>Most popular</h1>
</div>
<div id ="premWrapper">
<?php
foreach($premListing as $premItem):
?>
<ul class="displayPrem">
<li><img src="<?php echo $premItem['img_path']; ?>" alt="Business listings"></li>
</ul>
<?php endforeach;?>
</div>
<div id ="search">
<h1>My requests</h1>
</div>
<br />
<div id ="adsForm">
<div id ="imgHolder">
<?php
$user = new User();
if($user->isLoggedIn()){
?>
</div>
<?php
$eventsListing = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS ads.ad_id, ads.adList, ads.adCost,
ads.ad_id, ads.adName, img_upload.img_id, img_upload.img_path, exm.address_id, userId.id, admin.status_note
FROM ads
INNER JOIN admin
ON admin.admin_id=ads.ad_id
INNER JOIN img_upload
ON img_upload.img_id=admin.admin_id
LEFT JOIN address
ON ads.ad_id=admin.admin_id
LEFT JOIN(SELECT address.address_id FROM address GROUP BY address.address_id) as exm
ON ads.ad_id=address.address_id
LEFT JOIN users
ON users.id=admin.admin_id
LEFT JOIN(SELECT users.id FROM users GROUP BY users.id) as userId
ON ads.ad_id=address.address_id
WHERE userId.id = 'User()' AND admin.status_note ='Pending'
GROUP BY admin.admin_id
");
$eventsListing->execute( array ( $_GET["user"]) );
while($r =$eventsListing->fetch()){
?>
Ad name: <?php echo $r['adName']; ?> <br />
Ad type: <?php echo $r['adCost']; ?> <br />
Ad type: <?php echo $r['status_note']; ?> <br />
Status:<?php echo $r['status_note']; ?><br />
<br />
<?php } $resultlist = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS ads.ad_id, ads.adList, ads.adCost,
ads.ad_id, ads.adName, img_upload.img_id, img_upload.img_path, exm.address_id, userId.id, admin.status_note
FROM ads
INNER JOIN admin
ON admin.admin_id=ads.ad_id
INNER JOIN img_upload
ON img_upload.img_id=admin.admin_id
LEFT JOIN address
ON ads.ad_id=admin.admin_id
LEFT JOIN(SELECT address.address_id FROM address GROUP BY address.address_id) as exm
ON ads.ad_id=address.address_id
LEFT JOIN users
ON users.id=admin.admin_id
LEFT JOIN(SELECT users.id FROM users GROUP BY users.id) as userId
ON ads.ad_id=address.address_id
WHERE userId.id = ? AND (admin.status_note ='Refused' OR admin.status_note ='Accepted')
GROUP BY admin.admin_id
");
while($r =$resultlist->fetch()){
?>
Ad name: <?php echo $r['adName']; ?> <br />
Ad type: <?php echo $r['adCost']; ?> <br />
Ad type: <?php echo $r['status_note']; ?> <br />
Status:<?php echo $r['status_note']; ?><br />
<br />
<?php
}
?>
</div>
</div>
<div id="search">
<?php } ?>
</div>
</body>
</html>
Initially I had done,
[code=php] WHERE userId.id = '$user' AND admin.status_note ='Pending' [/code]
But I was getting the error message
Object of class User could not be converted to string
With the changes none of my queries are shown, not sure what the problem is, advice on a solution to either or would be great.