ankit.pandeyc012 Posted November 21, 2010 Share Posted November 21, 2010 <?php require_once('upper.php'); require_once('database.php'); if(isset($_COOKIE['LoginIdCookie'])) { echo '<h4>Welcome '.$_COOKIE['LoginIdCookie'].'</h4>'; } else{ echo '<h4>Events</h4>';} $result=mysqli_query($dbc,"select * from events") or die('Not Connected'); echo "<html> <body>"; echo "<form method='post' action='EventParticipator.php'>"; echo "<u><h4>Please tick events in which you want to participate</h4></u>"; /*echo "<table cellspacing='0' cellpadding='15'> <th><b>Event Title:</b></th> <th ><b>Event City:</b></th> <th><b>Content:</b></th> <th><b>Images:</b></th> <th><b>Event Date:</b></th>";*/ //while($row=mysqli_fetch_array($result)) $row=mysqli_fetch_array($result); for($i=0;$i<5;$i++) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<tr><td><img src='$Photo' width='120' height='90'/></td><td>$City</td><td>,</td><td>$Date</td><td>:</td><td>$Title</td></tr> <tr><td>$Content</td></tr> <tr><td><a href='#'>Know more</a></td><td>/</td><td><a href='#'>Click here to participate</a></td></tr>"; } //echo "<tr><td><input type='submit' name='submit' value='Participate'</td>"; if(isset($_COOKIE['LoginIdCookie'])) { echo "<td><a href='log_out.php'>Log out</a></td>"; echo "<td><a href='EditActivity.php'>Edit Your Activities</a></td></tr>"; } echo "</table></form></body></html>"; require_once('lower.php'); ?> Hi friends .......... I write above code to display top 5 rows from the database but it not works properly. It displays first row 5 times which is undesireable. Anyone plz help????????????????? Thx in advance.................. Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/ Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Use LIMIT 5 in your query and put back in your while loop and remove the for loop. Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137376 Share on other sites More sharing options...
ankit.pandeyc012 Posted November 21, 2010 Author Share Posted November 21, 2010 But Now if I update a new row in database. It not update on output. I mean to say as admin update this table, these updation must be shown to user...... Help plz.................. Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137397 Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Put a date stamp on it and show the last 5, or if you use auto numbering, show the last 5 entries. Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137398 Share on other sites More sharing options...
ankit.pandeyc012 Posted November 21, 2010 Author Share Posted November 21, 2010 Frd I have auto increament field named EventId but I don't know the exact syntax how I use it...... Plz Plz Explain....... Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137400 Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 select * from events order by EventId DESC LIMIT 5 Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137401 Share on other sites More sharing options...
ankit.pandeyc012 Posted November 21, 2010 Author Share Posted November 21, 2010 Thxxxxxxx Bro........ It works great.......... Link to comment https://forums.phpfreaks.com/topic/219341-i-want-to-display-just-top-5-rows-from-the-database/#findComment-1137403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.