Jump to content

Recommended Posts

Hi there,

 

I have some code that selects and displays latest adverts from a directory. It also selects featured adverts.

 

However, I want to display ONLY the featured ads.

 

This is my code:

 

<?php
$sql = "SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp, SIGN(feat.featuredtill-NOW()) AS isfeat,
			COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname, scat.catid, cat.catname
		FROM $t_ads a
			INNER JOIN $t_cities ct ON a.cityid = ct.cityid
			INNER JOIN $t_subcats scat ON a.subcatid = scat.subcatid
			INNER JOIN $t_cats cat ON scat.catid = cat.catid
			LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '0'
			LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'A'
		WHERE $visibility_condn
			$loc_condn
		GROUP BY a.adid
		ORDER BY a.createdon DESC
		LIMIT $latestads_count";
$res_latest = mysql_query($sql) or die($sql.mysql_error());

while($row = mysql_fetch_array($res_latest))
{

	$catname_inurl = RemoveBadURLChars($row['catname']);
	$subcatname_inurl = RemoveBadURLChars($row['subcatname']);

	if($sef_urls) $url = "{$vbasedir}$xcityid/posts/{$row[catid]}_{$catname_inurl}/{$row[subcatid]}_{$subcatname_inurl}/$row[adid]_" . RemoveBadURLChars($row['adtitle']) . ".html";
	else $url = "?view=showad&adid=$row[adid]&cityid=$xcityid&lang=$xlang{$link_extra}";

?>

	<?php 
	if($row['isfeat']) 
	{
		$feat_class = "class=\"featured\"";
		$feat_img = "<img src=\"images/featured.gif\" align=\"absmiddle\">";
	} 
	else 
	{ 
		$feat_class = "";
		$feat_img = "";
	}
	?>

 

If anyone could help me with this, I would very much appriciate it.

 

I have had a look and I think this is the part that displays the featured adverts:

 

if($row['isfeat']) 
	{
		$feat_class = "class=\"featured\"";
		$feat_img = "<img src=\"images/featured.gif\" align=\"absmiddle\">";
	} 

Link to comment
https://forums.phpfreaks.com/topic/190959-database-select-help/
Share on other sites

Thanks for the reply.

 

I tried that, but It seems to echo the following:

 

 

Featured Adverts: SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp, SIGN(feat.featuredtill-NOW()) AS isfeat, COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname, scat.catid, cat.catname FROM clf_ads a INNER JOIN clf_cities ct ON a.cityid = ct.cityid INNER JOIN clf_subcats scat ON a.subcatid = scat.subcatid INNER JOIN clf_cats cat ON scat.catid = cat.catid LEFT OUTER JOIN clf_adpics p ON a.adid = p.adid AND p.isevent = '0' LEFT OUTER JOIN clf_featured feat ON a.adid = feat.adid AND feat.adtype = 'A' WHERE a.enabled = '1' AND a.verified = '1' AND a.expireson >= NOW() AND isFeat = 1 AND a.cityid = 2 GROUP BY a.adid ORDER BY a.createdon DESC LIMIT 4Unknown column 'isFeat' in 'where clause'

 

Any ideas what is wrong?

Thanks. I tried that, but now nothing displays.

 

This is what I changed it to:

 

$sql = "SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp, (@isfeat:=SIGN(feat.featuredtill-NOW())) AS isfeat,
			COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname, scat.catid, cat.catname
		FROM $t_ads a
			INNER JOIN $t_cities ct ON a.cityid = ct.cityid
			INNER JOIN $t_subcats scat ON a.subcatid = scat.subcatid
			INNER JOIN $t_cats cat ON scat.catid = cat.catid
			LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '0'
			LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'A'
		WHERE @isfeat = 1
			$loc_condn
		GROUP BY a.adid
		ORDER BY a.createdon DESC
		LIMIT $latestads_count";

 

 

Hi,

 

I now have:

 

$sql = "SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp, (@isfeat:=SIGN(feat.featuredtill-NOW())) AS isfeat,
			COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname, scat.catid, cat.catname
		FROM $t_ads a
			INNER JOIN $t_cities ct ON a.cityid = ct.cityid
			INNER JOIN $t_subcats scat ON a.subcatid = scat.subcatid
			INNER JOIN $t_cats cat ON scat.catid = cat.catid
			LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '0'
			LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'A'
		WHERE @isfeat = 1
			$loc_condn" . "echo $sql" .

		"GROUP BY a.adid
		ORDER BY a.createdon DESC
		LIMIT $latestads_count";

 

 

but it is displaying this again:

 

SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp, (@isfeat:=SIGN(feat.featuredtill-NOW())) AS isfeat, COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname, scat.catid, cat.catname FROM clf_ads a INNER JOIN clf_cities ct ON a.cityid = ct.cityid INNER JOIN clf_subcats scat ON a.subcatid = scat.subcatid INNER JOIN clf_cats cat ON scat.catid = cat.catid LEFT OUTER JOIN clf_adpics p ON a.adid = p.adid AND p.isevent = '0' LEFT OUTER JOIN clf_featured feat ON a.adid = feat.adid AND feat.adtype = 'A' WHERE @isfeat = 1 AND a.cityid = 2echo SELECT areaname FROM clf_areas WHERE cityid = 2GROUP BY a.adid ORDER BY a.createdon DESC LIMIT 5You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT areaname FROM clf_areas WHERE cityid = 2GROUP BY a.adid ORDER BY a.cre' at line 10

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.