# Displaying data from database on tables but with different query

**URL:** <https://www.phphelp.com/t/displaying-data-from-database-on-tables-but-with-different-query/19565>\
**Category:** General PHP Help\
**Created:** [February 10, 2013, 8:41am UTC](https://www.phphelp.com/t/displaying-data-from-database-on-tables-but-with-different-query/19565 "2013-02-10T08:41:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanx2cool](https://www.phphelp.com/letter_avatar_proxy/v4/letter/l/848f3c/32.png) [@lanx2cool](https://www.phphelp.com/u/lanx2cool)\
**Post date:** [February 10, 2013, 8:41am UTC](https://www.phphelp.com/t/displaying-data-from-database-on-tables-but-with-different-query/19565/1 "2013-02-10T08:41:15Z")

</div>

hi guys im a student studying php and sql

In my code i am able to display data and add new table for every 2 data.

here is the code:  
[php]$query = “SELECT \* FROM student ORDER BY average DESC”;  
$result = mysql\_query($query);  
$num = mysql\_numrows($result);

echo “

  
”;

$i = 1;  
while($row = mysql\_fetch\_assoc($result)) {  
echo “

”;

```
// end and create a new table every 2 rows
if ($i % 2 === 0) {
	echo "</table>";
	echo "<table cellpadding=2 border=1><tr><td>StudentID</td><td>Name</td><td>average</td><td>date</td></tr><br />";
}
$i++;

```

}

echo “

| StudentID | Name | average | Date |
| ” . $row[‘studentID’] . “ | ” . $row[‘lastname’] . ", " . $row[‘firstname’] . “ | ” . $row[‘average’] . “ | ” . $row[‘date’] . “ |

”;[/php]

here is the output of my code:

StudentID Name average Date  
2 dela cruz, juan 89.56 2013-02-07 05:28:42  
6 dela pena, miggel 88.00 2013-02-09 04:10:10

StudentID Name average date  
5 baltazar, sarah 87.45 2013-02-09 06:15:16  
3 cruz, pedro 86.56 2013-02-09 07:16:26

StudentID Name average date  
4 abanto, nicolas 83.56 2013-02-09 04:10:28  
1 acebuche, joseph lance 80.56 2013-02-09 01:28:33

StudentID Name average date

---

<div class="post-metadata">

**Author:** ![lanx2cool](https://www.phphelp.com/letter_avatar_proxy/v4/letter/l/848f3c/32.png) [@lanx2cool](https://www.phphelp.com/u/lanx2cool)\
**Post date:** [February 10, 2013, 8:47am UTC](https://www.phphelp.com/t/displaying-data-from-database-on-tables-but-with-different-query/19565/2 "2013-02-10T08:47:50Z")

</div>

i accidentally clicked the post

my problem is i want the 2nd and 3rd table to display data order by date on desc.

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [February 10, 2013, 7:09pm UTC](https://www.phphelp.com/t/displaying-data-from-database-on-tables-but-with-different-query/19565/3 "2013-02-10T19:09:51Z")

</div>

Do 2 queries.
