Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[help] how to show all data

Newbie Spellweaver
Joined
Sep 10, 2005
Messages
51
Reaction score
2
i need help. how to display all data from database table
the code show only the first incode record.

table name = record
column name =
Sender
Credit
Debit
Date
Total
Remarks




PHP:
<?php
$query = mssql_query("SELECT sender, debit, credit,date, remarks,total from record");
$result = mssql_fetch_row($query);?>

    
<article class="rankingWrap">
<ul class="shadowz" style="width:200px;">
<li class="du">Server Funds/Expenses</li></ul>
<table width="100%" class="rankTable" align="center">
        <thead>
            <tr>
            <th width="20%"><b>Sender</b></th>
	    
            <th width="15%"><b>Debit</b><rth>
            
	    <th width="15%"><b>Credit</b></th>

	    <th width="20%"><b>Date</b></th>
            <th width="20%"><b>Remarks</b></th>
	        <th width="15%"><b>total</b></th>
            </tr>
        </thead>       
        <tbody>
        

<h1 align="center" class="heading">Server Funds </h1>

<?php
 echo'
<tr align="center">
<td>'.$result[0].'</td>
<td>'.$result[1].'</td>
<td>'.$result[2].'</td>
<td>'.$result[3].'</td>
<td>'.$result[4].'</td>
<td>'.$result[5].'</td>
</tbody></table></article>         
</tr>'; ?>


Thank you for Advance
 
Initiate Mage
Joined
Dec 14, 2016
Messages
4
Reaction score
0
Try something like this:

for a better Code i need an example of $result
PHP:
<table>
<thead>
<tr>
<th width="20%"><b>Sender</b></th>
<th width="15%"><b>Debit</b><th>
<th width="15%"><b>Credit</b></th>
<th width="20%"><b>Date</b></th>
<th width="20%"><b>Remarks</b></th>
<th width="15%"><b>total</b></th>
</tr>
</thead> 
<tbody>
<h1 align="center" class="heading">Server Funds </h1>
<?php
foreach($result as $data){
echo "<tr>
<td>$data->Sender</td>
<td>$data->Credit</td>
<td>$data->Debit</td>
<td>$data->Date</td>
<td>$data->Total</td>
<td>$data->Remarks</td>
</tr>"; 
}
?>
</tbody>
</table>
 
Newbie Spellweaver
Joined
May 30, 2017
Messages
36
Reaction score
10
First of all, I wouldn't even trust a service that is using non prepared statements.
You should definitely switch to PDO.
 
"(still lacks brains)"
Loyal Member
Joined
Sep 2, 2011
Messages
2,371
Reaction score
1,361
It is only displaying one because you are not looping through the rows you called using your query. You need to use foreach to loop through the data to display on a table or whatever else you need to do.

This should fix it:
 
Newbie Spellweaver
Joined
Sep 10, 2005
Messages
51
Reaction score
2
Try something like this:

for a better Code i need an example of $result
PHP:
<table>
<thead>
<tr>
<th width="20%"><b>Sender</b></th>
<th width="15%"><b>Debit</b><th>
<th width="15%"><b>Credit</b></th>
<th width="20%"><b>Date</b></th>
<th width="20%"><b>Remarks</b></th>
<th width="15%"><b>total</b></th>
</tr>
</thead> 
<tbody>
<h1 align="center" class="heading">Server Funds </h1>
<?php
foreach($result as $data){
echo "<tr>
<td>$data->Sender</td>
<td>$data->Credit</td>
<td>$data->Debit</td>
<td>$data->Date</td>
<td>$data->Total</td>
<td>$data->Remarks</td>
</tr>"; 
}
?>
</tbody>
</table>



when i try your code it seems no data showing at all.





It is only displaying one because you are not looping through the rows you called using your query. You need to use foreach to loop through the data to display on a table or whatever else you need to do.

This should fix it:


same result didnt appear.



(im basic in php/Mssql)) thank you for the help.
 
Newbie Spellweaver
Joined
Sep 10, 2005
Messages
51
Reaction score
2
Then you're doing something wrong, is it showing any error messages?
no error only the data not appear.
<?php
$query = mssql_query("SELECT sender, debit, credit,date, remarks,total from records");
$result = mssql_fetch_row($query);?>


<article class="rankingWrap">
<ul class="shadowz" style="width:200px;">
<li class="du">Server Funds/Expenses</li></ul>




<table>
<thead>
<tr>
<th width="20%"><b>Sender</b></th>
<th width="15%"><b>Debit</b><th>
<th width="15%"><b>Credit</b></th>
<th width="20%"><b>Date</b></th>
<th width="20%"><b>Remarks</b></th>
<th width="15%"><b>total</b></th>
</tr>
</thead>
<tbody>
<h1 align="center" class="heading">Server Funds </h1>

<?php foreach ($result as $item): ?>
<tr align="center">
<td><?php $item['Sender']; ?></td>
<td><?php $item['Debit']; ?></td>
<td><?php $item['Credit']; ?></td>
<td><?php $item['Date']; ?></td>
<td><?php $item['Remarks']; ?></td>
<td><?php $item['Total']; ?></td>
</tr>
<?php endforeach; ?>


</tbody>
</table>
 
Initiate Mage
Joined
Dec 14, 2016
Messages
4
Reaction score
0
Post please your output from this:

PHP:
<?php$query = mssql_query("SELECT sender, debit, credit,date, remarks,total from records");$result = mssql_fetch_row($query);print_r($result);?>
 
Joined
Aug 14, 2009
Messages
2,304
Reaction score
1,189
fetchrow does exactly what it says on the box. It fetches ONE row. You've to keep fetching it.
More here:

But you really should switch to PDO.

(Pseudo code):
PHP:
while($row = mssql_fetch_row($query))
{
    print_r($row);
}
 
Back
Top