<?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..................

Recommended Answers

pretty obvious that you always get the first record, you never tell your program to take the next record into the $record var :)
try adding LIMIT 5 to your sql statement and then just iterate over the result as you normaly would

Jump to Post

All 3 Replies

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..................

g

pretty obvious that you always get the first record, you never tell your program to take the next record into the $record var :)
try adding LIMIT 5 to your sql statement and then just iterate over the result as you normaly would

You need a pagination script.

Your style will not work since mysql does not know the next record to show.

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.