[help] how to show all data

Results 1 to 11 of 11
  1. #1
    Hardcore Member DarkMaster69 is offline
    MemberRank
    Sep 2005 Join Date
    DarkLandLocation
    125Posts

    [help] how to show all data


    RaGEZONE Recommends

    RaGEZONE Recommends

    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 Code:
    <?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
    Dont afraid to ask,

    DarkMaster69


  2. #2
    Newbie Davweiss is offline
    MemberRank
    Dec 2016 Join Date
    4Posts

    Re: [help] how to show all data

    Try something like this:

    for a better Code i need an example of $result
    PHP Code:
    <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>

  3. #3
    Registered Delight is offline
    MemberRank
    May 2017 Join Date
    24Posts

    Re: [help] how to show all data

    First of all, I wouldn't even trust a service that is using non prepared statements.
    You should definitely switch to PDO.

  4. #4
    "(still lacks brains)" NoBrain is online now
    ModeratorRank
    Sep 2011 Join Date
    United KingdomLocation
    2,703Posts

    Re: [help] how to show all data

    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: https://paste.ofcode.org/8v39GeNVZeW3Zm2n3CCTRq

  5. #5
    Hardcore Member DarkMaster69 is offline
    MemberRank
    Sep 2005 Join Date
    DarkLandLocation
    125Posts

    Re: [help] how to show all data

    Quote Originally Posted by Davweiss View Post
    Try something like this:

    for a better Code i need an example of $result
    PHP Code:
    <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.





    Quote Originally Posted by NoBrain View Post
    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: https://paste.ofcode.org/8v39GeNVZeW3Zm2n3CCTRq

    same result didnt appear.



    (im basic in php/Mssql)) thank you for the help.
    Dont afraid to ask,

    DarkMaster69

  6. #6
    "(still lacks brains)" NoBrain is online now
    ModeratorRank
    Sep 2011 Join Date
    United KingdomLocation
    2,703Posts

    Re: [help] how to show all data

    Quote Originally Posted by DarkMaster69 View Post
    same result didnt appear.
    Then you're doing something wrong, is it showing any error messages?

  7. #7
    Hardcore Member DarkMaster69 is offline
    MemberRank
    Sep 2005 Join Date
    DarkLandLocation
    125Posts

    Re: [help] how to show all data

    Quote Originally Posted by NoBrain View Post
    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>









    Dont afraid to ask,

    DarkMaster69

  8. #8
    "(still lacks brains)" NoBrain is online now
    ModeratorRank
    Sep 2011 Join Date
    United KingdomLocation
    2,703Posts

    Re: [help] how to show all data

    Quote Originally Posted by DarkMaster69 View Post
    no error only the data not appear.
    Put the following after the query:


    print_r($result);


    And put the results in pastebin.

  9. #9
    Hardcore Member DarkMaster69 is offline
    MemberRank
    Sep 2005 Join Date
    DarkLandLocation
    125Posts

    Re: [help] how to show all data

    Quote Originally Posted by NoBrain View Post
    Put the following after the query:


    print_r($result);


    And put the results in pastebin.
    hello sir sorry but cant follow your instruction. im newbie in PHP and i cant figure out where is the right place to put the code.
    Dont afraid to ask,

    DarkMaster69

  10. #10
    Newbie Davweiss is offline
    MemberRank
    Dec 2016 Join Date
    4Posts

    Re: [help] how to show all data

    Post please your output from this:

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

  11. #11
    Moderator GigaToni is offline
    ModeratorRank
    Aug 2009 Join Date
    GER / FRLocation
    2,007Posts

    Re: [help] how to show all data

    fetchrow does exactly what it says on the box. It fetches ONE row. You've to keep fetching it.
    More here: PHP: mssql_fetch_row - Manual

    But you really should switch to PDO.

    (Pseudo code):
    PHP Code:
    while($row mssql_fetch_row($query))
    {
        
    print_r($row);





Advertisement