Jump to content

help with displaying query but omit last row


Guber-X

Recommended Posts

for how i have my webpage set up, I have the news array displayed in 2 different ways on the front page. I need it to display the latest news in one box, then display the rest in the other box. It sounds easy, but i guess im just a noob with this haha. can anyone help me out? Ive been trying to figure this out for a few days now  :-\

 

here is how my code is written:

<table cellpadding="0" cellspacing="0" border="0" width="420">
      <tr>
        <td colspan="3"><img src="images/news.jpg" /></td>
      </tr>
      <tr>
        <td background="images/left-news.jpg" width="14"><img src="images/left-news.jpg" /></td>
        <td background="images/color.jpg" width="398" height="100%">
        
        <?

	$result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 1");
	if (!$result) {
	   die("query failed: " . msql_error());
	}

	while ($row = mysql_fetch_array($result)) {
	list($id,  $date, $name, $news) = $row;
	$news = nl2br($news);

	print('		
	<b>'.$date.':</b><br><br>'.
		$news.'<br>'
		);
		}
	?>

        </td>
        <td background="images/right.jpg" width="8"><img src="images/right.jpg" /></td>
      </tr>
      <tr>
        <td colspan="3"><img src="images/news-bottom.jpg" /></td>
      </tr>
    </table>

	<?

	$result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 5");
	if (!$result) {
	   die("query failed: " . msql_error());
	}

	while ($row = mysql_fetch_array($result)) {
	list($id,  $date, $name, $news) = $row;
	$news = nl2br($news);

	print('	

    <table cellpadding="0" cellspacing="0" border="0" width="420">
      <tr>
        <td width="16"><img src="images/box/Top-left.jpg" /></td>
        <td background="images/box/Top-center.jpg" width="398"><img src="images/box/Top-center.jpg" /></td>
        <td width="8"><img src="images/box/Top-right.jpg" /></td>
      </tr>
      <tr>
        <td background="images/box/left.jpg" width="16"><img src="images/box/left.jpg" /></td>
        <td background="images/box/color.jpg" width="398">

	<b>'.$date.':</b><br><br>'.
		$news.'<br>

	</td>
        <td background="images/box/right.jpg" width="8"><img src="images/box/right.jpg" /></td>
      </tr>
      <tr>
        <td width="16"><img src="images/box/Bottom-left.jpg" /></td>
        <td background="images/box/Bottom-center.jpg" width="398"><img src="images/box/Bottom-center.jpg" /></td>
        <td width="8"><img src="images/box/Bottom-right.jpg" /></td>
      </tr>
    </table>

		');
		}
	?>

Link to comment
Share on other sites

What you could do is set the id's of your two latest rows into an array, then use a simple if to make sure they aren't in the array so they wont be shown in your other box.

 

<table cellpadding="0" cellspacing="0" border="0" width="420">
      <tr>
        <td colspan="3"><img src="images/news.jpg" /></td>
      </tr>
      <tr>
        <td background="images/left-news.jpg" width="14"><img src="images/left-news.jpg" /></td>
        <td background="images/color.jpg" width="398" height="100%">
        
        <?

	$result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 1");
	if (!$result) {
	   die("query failed: " . msql_error());
	}

	while ($row = mysql_fetch_array($result)) {
	list($id,  $date, $name, $news) = $row;
	$news = nl2br($news);
	$newsArray[] = $id;

	print('		
	<b>'.$date.':</b><br /><br />'.
		$news.'<br>'
		);
		}
	?>

        </td>
        <td background="images/right.jpg" width="8"><img src="images/right.jpg" /></td>
      </tr>
      <tr>
        <td colspan="3"><img src="images/news-bottom.jpg" /></td>
      </tr>
    </table>

	<?

	$result = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 7");
	if (!$result) {
	   die("query failed: " . msql_error());
	}

	while ($row = mysql_fetch_array($result)) {
	list($id,  $date, $name, $news) = $row;
                      if( !in_array("$id", $newsArray) )
                      {
	$news = nl2br($news);

	print('	

    <table cellpadding="0" cellspacing="0" border="0" width="420">
      <tr>
        <td width="16"><img src="images/box/Top-left.jpg" /></td>
        <td background="images/box/Top-center.jpg" width="398"><img src="images/box/Top-center.jpg" /></td>
        <td width="8"><img src="images/box/Top-right.jpg" /></td>
      </tr>
      <tr>
        <td background="images/box/left.jpg" width="16"><img src="images/box/left.jpg" /></td>
        <td background="images/box/color.jpg" width="398">

	<b>'.$date.':</b><br><br>'.
		$news.'<br>

	</td>
        <td background="images/box/right.jpg" width="8"><img src="images/box/right.jpg" /></td>
      </tr>
      <tr>
        <td width="16"><img src="images/box/Bottom-left.jpg" /></td>
        <td background="images/box/Bottom-center.jpg" width="398"><img src="images/box/Bottom-center.jpg" /></td>
        <td width="8"><img src="images/box/Bottom-right.jpg" /></td>
      </tr>
    </table>

		');
                                   }
		}
	?>

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.