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

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.