Jump to content

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


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))
			{

I didn't read the whole thing but..

 

use limit like this

 

LIMIT start, end

 

so

LIMIT 0,5 - displays the first 5

LIMIT 5,5 - displays the next 5 (records 5 to 10)

LIMIT 10,5 - displays the next 5 (records 10 to 15)

etc

 

Please look at this page:

http://www.thefrontiertimes.com/ft_online_art.php?art_id=2

 

First is the full length article, and then come the titles of articles from the same category. But the list of articles I don't want to display the same article.

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

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>";
				}
			}

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);

 

 

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.