Jump to content

Do I need a new query for this?


katie77

Recommended Posts

Ok I've got a news system and I'm querying the database to retrieve the last 3 news items like this:

 


$query = 	"SELECT news_id, 
						category, 
						title, 
						text, 
						img_url, 
						linkto, 
						ext_url, 
						DATE_FORMAT(date,'%d %M, %Y') as sd 
			FROM 		$table
			$where_category
			ORDER BY 	date 
			DESC LIMIT 	$start, 3" 

			or DIE ("Can't retrieve");

$result=@mysql_query($query) or die("Error in News");	

 

Now in three different places in my page I'm wanting the news titles to appear.

 

There'll be a main news item with the first, there'll be a sub item (formatted quite differently) with the second and a third at the bottom of the page.

 

As I've already retrieved the above to display news on the page, is there any way I could just ask it to retrieve the title of nth row?

 

ie so in one place I could just have:

<td>".$getNews['title'][2]."</td>

 

to retrieve the title from the second row?

 

As the layouts are so different, it's not something that's easy to put in a loop and I'm keen to make the code as optimised as possible.

 

Many thanks!

Link to comment
Share on other sites

As far as I know and i've searched, you need to iterate through. Therefore as long as you do it in order then its ok, otherwise (slightly more overhead) put it all into an array which can be accessed at any point. Or when you get it, iterate through and generate your blocks there and then, either into string vars or into <divs> which are positioned into place with css...

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.