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
https://forums.phpfreaks.com/topic/85809-do-i-need-a-new-query-for-this/
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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.