Jump to content

[SOLVED] easy way to do this row select?


delphi123

Recommended Posts

hi there,

 

I'm calling an array that I've pulled from a mySQL table and I'm just wondering if there's a trick to this?

 

echo '<li>'.$row['title'].'</li>';

 

I'm wanting to manually select that it'll show the title from the first row of this array - is there a quick way to do this, ie something like:

 

echo '<li>'.$row['title',1].'</li>';

 

Or something - otherwise I'll have to create a variable for each and then query the database each time, which seems longwinded!

 

(ps I can't use a loop - that's what I currently have, but I want to just select certain rows)

Link to comment
https://forums.phpfreaks.com/topic/78996-solved-easy-way-to-do-this-row-select/
Share on other sites

Hi folks,

 

Sorry should have been clearer - I've got a news page that's automatically pulling and listing the top five posts from several categories in a database - it's just loading the whole lot in one go as below:

 

$query = "SELECT news_id, title, img_url, linkto, DATE_FORMAT(date,'%d %M, %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 5";

 

Now in different places on the page I'm wanting to also have a highlights section that'll use same data, but arranged differently and these will always show the 1st, 2nd and 3rd articles (but in different places in the html).

 

I could manually do it like you describe, but I was just wondering if this was how you guys would do it, as for me that'd mean four database queries instead of potentially just one (particularly as the $query array has the exact data I require already!)

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.