creatives Posted March 18, 2010 Share Posted March 18, 2010 Hi guys, I have a mysql database consisting of the following tables and fields:- Table name: People Fields: ID, name, profileurl I want to display on my homepage the 10 most recent people I add, but as clickable links ie showing name linking to profile url. With the most recent at the top of the list. I also have another table: updates Fields: title, url I also want to show the last 25 updates displaying title as clickable link to the url If anyone can give me a php code to display this, that would be great, thanks so much! Quote Link to comment Share on other sites More sharing options...
creatives Posted March 23, 2010 Author Share Posted March 23, 2010 Bump....can anyone help me with this? Quote Link to comment Share on other sites More sharing options...
ignace Posted March 23, 2010 Share Posted March 23, 2010 SELECT field, field, .. FROM table WHERE field = value ORDER BY id DESC LIMIT 10 Quote Link to comment Share on other sites More sharing options...
creatives Posted March 25, 2010 Author Share Posted March 25, 2010 thanks for that! But I am still unsure of what to do exactly to get the list to show on my homepage. Is there any chance you could type the full code, how I use it etc. My homepage where I want the small list to appear is a html page, will I have to save this as a php file? And what exactly do I need to put into the hompage code, to show the list? I presume I need to use the connect to database first? Do I use an additional snippet code before this code, or is this read from another file? I presume I just put this bit of code where I want the list:- <? php SELECT field, field, .. FROM table WHERE field = value ORDER BY id DESC LIMIT 10 ?> Sorry for all the questions, I am totally new to php stuff. Quote Link to comment Share on other sites More sharing options...
creatives Posted March 28, 2010 Author Share Posted March 28, 2010 bump please help Quote Link to comment Share on other sites More sharing options...
GetPutDelete Posted March 28, 2010 Share Posted March 28, 2010 <?php $res = mysql_query("select * from People order by ID desc limit 0, 10"); while($row = mysql_fetch_array($res)) { echo '<a href="' . $row['profileurl'] . '">' . $row['name'] . '</a><br />'; } ?> That should get you started, there is a ton of documentation about mysql select in PHP which is newbie friendly, give W3 Schools a go, it's a good starting point. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted March 28, 2010 Share Posted March 28, 2010 seems as though you're jumping in head first. there are millions of basic tutorials on the net that show you exactly, step-by-step, how to connect to a database and display its contents on a page. i recommend getting familiar with that before trying to take on too much else. check this out: http://www.phpfreaks.com/tutorial/php-basic-database-handling Quote Link to comment Share on other sites More sharing options...
ignace Posted March 28, 2010 Share Posted March 28, 2010 My homepage where I want the small list to appear is a html page, will I have to save this as a php file? I presume I need to use the connect to database first? I presume I just put this bit of code where I want the list? Yes³. Do I use an additional snippet code before this code, or is this read from another file? No. 1. Add a field signup_date (DATETIME) to your people table 2. function get_latest_signups($number = 10, $db = null) { $number = intval($number); $number = 0 === $number ? 10 : $number; $latest_registrations = array(); $query = "SELECT name, profileurl FROM people ORDER BY signup_date DESC LIMIT $number"; $result = mysql_query($query, $db); if ($result && mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $latest_registrations[] = $row; } } return $latest_registrations; } $latest_signups = get_latest_signups(); foreach ($latest_signups as $user) { echo '<a href="', $user['profileurl'], '">', $user['username'], '</a>'; } 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.