Hello to all, im a new member here and just starting to learn php.
i would like to ask for help regarding my current problem specifically the output format of my mysql query result, hope someone would be kind enough to help me.
Here is what i want to result display to be,
all data is in one table
Example Output:
Accountant
-----------------------------------------------------------------------------------------------------------
John Peters | 25 | BS in Accountancy | Harvard |
----------------------------------------------------------------------------------------------------------
Charles Lee | 29 | BS in Accountancy | UCLA |
-----------------------------------------------------------------------------------------------------------
Nurse
----------------------------------------------------------------------------------------------------------
Adam Fits | 25 | BS in Nursing | Harvard |
----------------------------------------------------------------------------------------------------------
Mike Dy | 29 | BS in Nursing | UC |
-----------------------------------------------------------------------------------------------------------
So on and so forth......... and a big thanks in advance.
List View Query Result
Moderator: General Moderators
Re: List View Query Result
What have you got so far? Where are you running into problems?
Re: List View Query Result
so far, i can display the result in grid view like this,
---------------------------------------------------------------------------
Accountant | John Peters | 25 | BS in Accountancy | Harvard |
---------------------------------------------------------------------------
Accountant | Charles Lee | 29 | BS in Accountancy | UCLA |
--------------------------------------------------------------------------
Nurse | Adam Fits | 25 | BS in Nursing | Harvard |
--------------------------------------------------------------------------
Nurse | Mike Dy | 29 | BS in Nursing | UC |
--------------------------------------------------------------------------
what i want is that, it's like sorted by profession. im thinking it can be done through looping but i dont exactly know how.
---------------------------------------------------------------------------
Accountant | John Peters | 25 | BS in Accountancy | Harvard |
---------------------------------------------------------------------------
Accountant | Charles Lee | 29 | BS in Accountancy | UCLA |
--------------------------------------------------------------------------
Nurse | Adam Fits | 25 | BS in Nursing | Harvard |
--------------------------------------------------------------------------
Nurse | Mike Dy | 29 | BS in Nursing | UC |
--------------------------------------------------------------------------
what i want is that, it's like sorted by profession. im thinking it can be done through looping but i dont exactly know how.
Re: List View Query Result
Maybe something like this?
Code: Select all
$results = array();
foreach ($row as $r)
{
$results[$r['profession']][] = $r;
}Re: List View Query Result
Here is my actual db table, code and output/result:
------------------------------------------------------------------------------------------------------------
member_id | mship_id | doc_date | name | description | debit_amt | credit_amt
------------------------------------------------------------------------------------------------------------
023 | 023 | 12-12-2010 00:00:00:00 | Burke Matthew | Pastry Product | 140.00 | 00.00 |
------------------------------------------------------------------------------------------------------------
023-A | 023 | 12-09-2010 00:00:00:00 | Burke Ray | Recreations | 45.54 | 00.00 |
------------------------------------------------------------------------------------------------------------
023 | 023 | 12-02-2010 00:00:00:00 | Burke Matthew | Rooms | 80.00 | 00.00 |
------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************************
<?php
include('../includes/db_page.php');
$username = $_SESSION['username'];
$member_id = $_SESSION['member_id'];
$query = "SELECT * FROM ar_stmnt_dt WHERE mship_id = '$member_id' ORDER BY doc_date ASC";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
$s=0;
$count = 1 + $s ;
if ($count == "0") {
echo "No Results Returned";
} else {
?>
<table width="810" border="0" >
<tr>
<td width="65">DATE</td>
<td width="65" >NAME</td>
<td width="289">DESCRIPTION</td>
<td width="92">DEBIT</td>
<td width="103">CREDIT</td>
</tr>
<tr>
<td colspan="2"></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr><?php while ($row= mysql_fetch_array($result)) {?>
<tr>
<td><?php echo $row['doc_date']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['description']?></td>
<td><?php echo $row['debit_amt']?></td>
<td><?php echo $row['credit_amt']?></td>
</tr><?php } ?>
</table>
<?php $count++ ;
}?>
*******************************************************************************************************************************************
<div id="content">
<table width="638" border="0" >
<tr>
<td> </td>
<td > </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="176">DATE</td>
<td width="130" >NAME</td>
<td width="178">DESCRIPTION</td>
<td width="69">DEBIT</td>
<td width="63">CREDIT</td>
</tr>
<tr>
<td>12-12-2010 00:00:00:00 </td>
<td >Burke Matthew </td>
<td>Pastry Product</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>12-09-2010 00:00:00:00</td>
<td >Burke Ray</td>
<td>Recreations</td>
<td>45.54</td>
<td>00.00</td>
</tr>
<tr>
<td>12-02-2010 00:00:00:00</td>
<td >Burke Matthew</td>
<td>Rooms</td>
<td>80.00</td>
<td>00.00</td>
</tr>
<tr>
<td> </td>
<td > </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
*******************************************************************************************************************************************
Now, here is what i want the result or display would be:
<table width="504" border="0" >
<tr>
<td width="176">DATE</td>
<td width="178">DESCRIPTION</td>
<td width="69">DEBIT</td>
<td width="63">CREDIT</td>
</tr>
<tr>
<td>Burke Matthew </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>12-12-2010 00:00:00:00 </td>
<td>Pastry Product</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>12-02-2010 00:00:00:00</td>
<td>Rooms</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>Burke Ray</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>12-09-2010 00:00:00:00</td>
<td>Recreations</td>
<td>45.54</td>
<td>00.00</td>
</tr>
</table>
------------------------------------------------------------------------------------------------------------
member_id | mship_id | doc_date | name | description | debit_amt | credit_amt
------------------------------------------------------------------------------------------------------------
023 | 023 | 12-12-2010 00:00:00:00 | Burke Matthew | Pastry Product | 140.00 | 00.00 |
------------------------------------------------------------------------------------------------------------
023-A | 023 | 12-09-2010 00:00:00:00 | Burke Ray | Recreations | 45.54 | 00.00 |
------------------------------------------------------------------------------------------------------------
023 | 023 | 12-02-2010 00:00:00:00 | Burke Matthew | Rooms | 80.00 | 00.00 |
------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************************
<?php
include('../includes/db_page.php');
$username = $_SESSION['username'];
$member_id = $_SESSION['member_id'];
$query = "SELECT * FROM ar_stmnt_dt WHERE mship_id = '$member_id' ORDER BY doc_date ASC";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
$s=0;
$count = 1 + $s ;
if ($count == "0") {
echo "No Results Returned";
} else {
?>
<table width="810" border="0" >
<tr>
<td width="65">DATE</td>
<td width="65" >NAME</td>
<td width="289">DESCRIPTION</td>
<td width="92">DEBIT</td>
<td width="103">CREDIT</td>
</tr>
<tr>
<td colspan="2"></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr><?php while ($row= mysql_fetch_array($result)) {?>
<tr>
<td><?php echo $row['doc_date']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['description']?></td>
<td><?php echo $row['debit_amt']?></td>
<td><?php echo $row['credit_amt']?></td>
</tr><?php } ?>
</table>
<?php $count++ ;
}?>
*******************************************************************************************************************************************
<div id="content">
<table width="638" border="0" >
<tr>
<td> </td>
<td > </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="176">DATE</td>
<td width="130" >NAME</td>
<td width="178">DESCRIPTION</td>
<td width="69">DEBIT</td>
<td width="63">CREDIT</td>
</tr>
<tr>
<td>12-12-2010 00:00:00:00 </td>
<td >Burke Matthew </td>
<td>Pastry Product</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>12-09-2010 00:00:00:00</td>
<td >Burke Ray</td>
<td>Recreations</td>
<td>45.54</td>
<td>00.00</td>
</tr>
<tr>
<td>12-02-2010 00:00:00:00</td>
<td >Burke Matthew</td>
<td>Rooms</td>
<td>80.00</td>
<td>00.00</td>
</tr>
<tr>
<td> </td>
<td > </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
*******************************************************************************************************************************************
Now, here is what i want the result or display would be:
<table width="504" border="0" >
<tr>
<td width="176">DATE</td>
<td width="178">DESCRIPTION</td>
<td width="69">DEBIT</td>
<td width="63">CREDIT</td>
</tr>
<tr>
<td>Burke Matthew </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>12-12-2010 00:00:00:00 </td>
<td>Pastry Product</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>12-02-2010 00:00:00:00</td>
<td>Rooms</td>
<td>140.00</td>
<td>00.00</td>
</tr>
<tr>
<td>Burke Ray</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>12-09-2010 00:00:00:00</td>
<td>Recreations</td>
<td>45.54</td>
<td>00.00</td>
</tr>
</table>