delphi123 Posted November 26, 2007 Share Posted November 26, 2007 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) Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 26, 2007 Share Posted November 26, 2007 When selecting the data from the database, put LIMIT 1 at the end.. example SELECT * FROM table WHERE data="value" LIMIT 1 Then it will only select the first row from the table. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 26, 2007 Share Posted November 26, 2007 First row of an array? <?php $data = mysql_fetch_array(mysql_query("SELECT * FROM table WHERE irow = "value" LIMIT 1")); ?> Quote Link to comment Share on other sites More sharing options...
delphi123 Posted November 26, 2007 Author Share Posted November 26, 2007 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!) Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 26, 2007 Share Posted November 26, 2007 You would have to use different queries for different SELECT statements. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.