Jump to content

[SOLVED] Check if particular record has been displayed and skip it


cheeseus

Recommended Posts

On the page, a particular record is displayed (full length article) and below it the rest of the articles from the same category are listed by their title. In there, however, the main article's name is repeated. I need to "see" which art_id this is and "tell" the query to skip it. But how?  ::)

This is my main article query:

$article_query = mysql_query("SELECT * FROM az_articles WHERE issue = '$myrow[issue]' AND art_id = '$art_id' LIMIT 1",$connect);
while($rrow = mysql_fetch_array($article_query))
{...echo...
//and here is the query for the rest of the articles
$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' ORDER BY art_id DESC",$connect);
			while($mrow = mysql_fetch_array($more_articles))
			{
			$art_id = $mrow['art_id'];
			echo "<tr><td class=headline><br><a href=ft_online_art.php?art_id=$art_id class=headlines><img src=images/headlines.gif border=0> <b>";
			echo $mrow['art_title'];
			echo "</a></td></tr>"; 
			}

 

I guess I must write something in the LIMIT clause for the "more_articles" query.

This is what I tried (please don't laugh!)

$shown_article = mysql_query("SELECT * FROM az_articles WHERE issue = '$myrow[issue]' AND art_id = '$art_id' ",$connect);
			if($skip_article = $shown_article) 
			{

			$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' ORDER BY art_id DESC LIMIT $skip_article",$connect);
			while($mrow = mysql_fetch_array($more_articles))
			{

Link to comment
Share on other sites

Ahh

 

ok 2 options spring to mind

 

#1, just use random (not ideal)

$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' ORDER BY RAND()",$connect);

 

#2, store the ids in a cookie and use NOT IN (note cookie should be comma delimited)

$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' AND NOT ID in ($COOKIE)  ORDER BY art_id DESC",$connect);

 

it depends on the "rules"

 

what are the "rules" for the more_articles,

ie

only show once!

don't show a link to the current article

etc

Link to comment
Share on other sites

Setting $Cookie is unfortunately beyond my knowledge  ;D

Instead I wrote a check that, if the ID is the same as that of the main article, displays a transparent 1x1 px image. Perhaps very much "newbie" but all I can do. Better ways are welcome and appreciated! :) THANKS!

$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' ORDER BY art_id DESC ",$connect);
			while($mrow = mysql_fetch_array($more_articles))
			{
				if($art_id != $mrow['art_id']) 
				{
				echo "<tr><td class=headline><br><a href=\"ft_online_art.php?art_id=$art_id\" class=headlines><img src=images/headlines.gif border=0> <b>";
				echo $mrow['art_title'];
				echo "</a></td></tr>"; 
				} else { 
				echo "<tr><td class=headline><img src=".$imageurl." border=0></tr>";
				}
			}

Link to comment
Share on other sites

what about

 

 

$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' AND (NOT art_id = $rrow[art_id]) ORDER BY art_id DESC",$connect);

 

or

 

make it random (just an idea), without showing current

$more_articles = mysql_query("SELECT * FROM az_articles WHERE section = '$rrow[section]' AND (NOT art_id = $rrow[art_id]) ORDER BY RAND()",$connect);

 

 

Link to comment
Share on other sites

Thanks, this works too!

However, every of the listed articles gets the same ID as that of the full-length one :(

 

ft_online_art.php?art_id=$art_id\

 

Should be:

 

ft_online_art.php?art_id=$rrow[art_id]\

Link to comment
Share on other sites

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.