<

?php
require_once('upper.php');
require_once('database.php');
require_once('LoginStatement.php');
$LoginId=$_COOKIE['LoginIdCookie'];
$query="select * from activity_participation where LoginId='$LoginId'";
$result=mysqli_query($dbc,$query) or die ('Not Connected');
//echo "<div class='search_output_data'>
echo "<table border='0' cellspacing='0' cellpadding='0'>";
while($row=mysqli_fetch_array($result))
{
echo "<tr><th align='left' valign='top'>Activity Title</th>
<th align='left' valign='top'>Date of Participation</th>
</tr>
<tr><td colspan='4' align='left' valign='top'><table align='left' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' valign='top'>".$row['Title']."</td> <td align='left' valign='top'>".$row['Date']."</td> </tr></table>
</td></tr>";
}
echo "</table>";
//echo "</div>";
require_once('lower.php');
?>

In table activity_participation many rows have same values. I want to display only different rows to user not to display same rows again and again.
Or Anybody have idea to prevent the row duplication in database....
Help me please.........
thanks in advance.............

You can purge duplicates from an array by using array_unique.

What I would recommend is start an array which holds the whole table row then before running a loop to display the array, re-set the array by using:

$variable = array_unique($variable);

This should remove any duplicates.

If it's the table headers that are the only things displaying over and over, then you just need to change your code to this:

<?php
require_once('upper.php');
require_once('database.php');
require_once('LoginStatement.php');
$LoginId=$_COOKIE['LoginIdCookie'];
$query="select * from activity_participation where LoginId='$LoginId'";
$result=mysqli_query($dbc,$query) or die ('Not Connected');
//echo "<div class='search_output_data'>
echo "<table border='0' cellspacing='0' cellpadding='0'>
<tr><th align='left' valign='top'>Activity Title</th>
<th align='left' valign='top'>Date of Participation</th>
</tr>";

while($row=mysqli_fetch_array($result))
{
echo "<tr><td align='left' valign='top'>".$row['Title']."</td> <td align='left' valign='top'>".$row['Date']."</td></tr>";
}
echo "</table>";
//echo "</div>";
require_once('lower.php');
?>

I have modified your table code because I didn't see a reason to need a table within a table when the wrapping table has the headers.

If there is multiple entries in the database, use the array_unique(); I mentioned earlier like this:

<?php
require_once('upper.php');
require_once('database.php');
require_once('LoginStatement.php');
$LoginId=$_COOKIE['LoginIdCookie'];
$query="select * from activity_participation where LoginId='$LoginId'";
$result=mysqli_query($dbc,$query) or die ('Not Connected');
//echo "<div class='search_output_data'>
echo "<table border='0' cellspacing='0' cellpadding='0'>
<tr><th align='left' valign='top'>Activity Title</th>
<th align='left' valign='top'>Date of Participation</th>
</tr>";
$tablerow = 1; //Will be used to count the amount of rows in the table and put each row in the relevant part of the array.
while($row=mysqli_fetch_array($result))
{
$tabledata[$tablerow] = "<tr><td align='left' valign='top'>".$row['Title']."</td> <td align='left' valign='top'>".$row['Date']."</td></tr>";

$tablerow++; //Increment so that the previous entry in the array isn't overwritten.
}

$tabledata = array_unique($tabledata); //Remove any duplicates from the array.

$tablerow = count($tabledata); //Recount the amount of entries in the array

/*The following loop is used to display each row of the table stored in the array*/
for($i=1;$i<=$tablerow;$i++)
{
  echo $tabledata[$tablerow];
}

echo "</table>";
//echo "</div>";
require_once('lower.php');
?>

If you need more explanation of the code, feel free to ask and I'll try to explain.

Could you not just add a distinct or group by to the SQL query to only retrieve unique results?

R.

Could you not just add a distinct or group by to the SQL query to only retrieve unique results?

R.

Good point.

Be a part of the DaniWeb community

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