Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    58
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help get data from mysql to html form

    sir i have 2 files one billing-admin.php
    PHP Code:
    <?php
    require 'databaseconnect.php';

    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` FROM `cashout`";
    if(
    $result=mysql_query($query))
    {
    while (
    $query_row=mysql_fetch_assoc($result))
    {
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];

    echo 
    $date.'|'.$type.'|'.$processor.'|'.$payout.'|'.$status.'|'.$amount.'<a name="billing-edit" href="billing-edit.php">edit</a><br>';




    }
    }
    else
    {
    echo
    'Database not working..';
    }

    ?>
    when run this file its get all data from mysql and if you see i run this in echo
    like data get this from

    2013-10-11|Cash Out|pz|saunt_al6@gmail.com|Panding|40 edit

    i want when i click on edit[/B] these above data show in form tab
    how to set it.. i create one more php code and link this code to edit link.. but its not specfic data show in this file form but this file form show empty tab second file is

    PHP Code:
    <?php
    require 'billing-admin.php';

    if(isset(
    $_GET['processor'])&& isset($_GET['payoutaccount'])&& isset($_GET['status'])&& isset($_GET['amount']))
    {

    $processor $_GET['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];

    }
    ?>

    <form action="billing-edit" method="get">
    Processor: <input name="<?php if(isset($processor)){echo $processor;} ?>" type="text"><br>
    Payment Account : <input name="payoutaccount" type="text"><br>
    Status : <select name="status">
    <option value="panding">Panding</option>
    <option value="sent">Sent</option>
    </select><br>
    Amount : <input name="amount" type="text"><br>
    <input type="submit" value="update">

    </form>
    please tell me what id..

    thanks

  • #2
    New Coder
    Join Date
    May 2012
    Posts
    58
    Thanks
    1
    Thanked 0 Times in 0 Posts
    now i change some in my code after change i get values in form but when i click any edit id like 3 or 4 or 7 .. its only show result of first 1 data in form how to set it..

    first code
    PHP Code:
    <?php
    require 'databaseconnect.php';

    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` ,`userid` FROM `cashout` ";
    if(
    $result=mysql_query($query))
    {
    while (
    $query_row=mysql_fetch_assoc($result))
    {
    $id=$query_row['id'];
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];
    $userid=$query_row['userid'];

    echo 
    $date.'|'.$type.'|'.$processor.'|'.$payout.'|'.$status.'|'.$amount.'<br>';


    echo 
    '<form action="billing-edit.php" method="get"><input type="submit" name="userrecord" value="'.$id.'"></form>';


    }}


    else
    {
    echo
    'Database not working..';
    }

    ?>
    second

    PHP Code:
    <?php
    require 'databaseconnect.php';

    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` FROM `cashout` ";
    if(
    $result=mysql_query($query))
    {
    if(
    $query_row=mysql_fetch_assoc($result))

        {
    $id=$query_row['id'];
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];

    echo 
    $date.'|'.$type.'|'.$processor.'|'.$payout.'|'.$status.'|'.$amount.'<br>';
    echo 
    '<form action="billing-edit.php" method="get">
    id: <input name="id" type="text" value="'
    .$query_row['id'].'">
    Processor: <input name="processor" type="text" value="'
    .$query_row['processor'].'"><br>
    Payment Account : <input name="payoutaccount" type="text" value="'
    .$query_row['payoutaccount'].'"><br>
    Status : <select name="status">
    <option value="'
    .$query_row['status'].'"></option>
    <option value="panding">Panding</option>
    <option value="sent">Sent</option>
    </select><br>
    Amount : <input name="amount" type="text" value="'
    .$query_row['amount'].'"><br>
    <input type="submit" value="update">

    </form>'
    ;

    }
    }
    else
    {
    echo
    'Database not working..';
    }

    ?>

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    I would use PHP SESSIONS to move things from the first script to the second. See Below.
    I have added javascript to the second (billing-edit.php) script to set the select option to the correct value.
    Lastly (and this is just an opinion) I would use POST not GET to send the forum, because it deals with money and bill status.
    The Main PHP:
    PHP Code:
    <?php
    session_start
    ();
    require 
    'databaseconnect.php';

    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` FROM `cashout`";
    if(
    $result=mysql_query($query))
    {
    while (
    $query_row=mysql_fetch_assoc($result))
    {
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];

    $_SESSION["processor"] = $processor;
    $_SESSION["payout"] = $payout;
    $_SESSION["status"] = $status;
    $_SESSION["amount"] = $amount;

    echo 
    $date.'|'.$type.'|'.$processor.'|'.$payout.'|'.$status.'|'.$amount.'<a name="billing-edit" href="billing-edit.php">edit</a><br>';
    }
    }
    else
    {
    echo
    'Database not working..';
    }
    ?>
    The billing-edit.php:
    PHP Code:
    <?php
    session_start
    ();
    $processor $_SESSION["processor"];echo "HERE " $processor;
    $payout $_SESSION["payout"];echo "<br />HERE " $payout;
    $status $_SESSION["status"];echo "<br />HERE " $status;
    $amount $_SESSION["amount"];echo "<br />HERE " $amount;
    require 
    'billing-admin.php';

    ?>

    <form action="billing-edit" method="get">
    Processor: <input name="<?php if(isset($processor)){echo $processor;} ?>" type="text" value="<?php if(isset($processor)){echo $processor;} ?>"><br>
    Payment Account : <input name="payoutaccount" type="text" value='<?= $payout ?>'><br>
    Status :
    <select name="status">
        <option value="Panding" id="Panding">Panding</option>
        <option value="Sent" id="Sent">Sent</option>
    </select><br>
    Amount : <input name="amount" type="text" value='<?= $amount ?>' ><br>
    <input type="submit" value="update">
    </form>

    <script type="text/javascript">
        document.getElementById('<?= $status ?>').selected=true;
    </script>
    You may need to touch this up a bit. Didn't see your second post until I uploaded this. See if it works and then post again
    Last edited by sunfighter; 10-12-2013 at 05:11 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    58
    Thanks
    1
    Thanked 0 Times in 0 Posts
    now its get last record of database if i connect any record its show last record on billing-edit.php form

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Sorry about that. Only used a single $query_row[] to check it.
    Try these:
    PHP Code:
    <?php
    session_start
    ();
    session_unset();
    require 
    'databaseconnect.php';

    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` FROM `cashout`";
    if(
    $result=mysql_query($query))
    {
        
    $rownum 1;
        while (
    $query_row=mysql_fetch_assoc($result))
        {
            
    $date $query_row['date'];
            
    $type $query_row['type'];
            
    $processor $query_row['processor'];
            
    $payout $query_row['payoutaccount'];
            
    $status $query_row['status'];
            
    $amount $query_row['amount'];

            
    $_SESSION["MyArray".$rownum] = [$query_row['processor'],$query_row['payoutaccount'],$query_row['status'],$query_row['amount']];
            echo 
    $date.'|'.$type.'|'.$processor.'|'.$payout.'|'.$status.'|'.$amount.'<a name="billing-edit" href="billing-edit.php?num='.$rownum.'">edit</a><br>';
            
    $rownum++;
        }
    }else{
        echo
    'Database not working..';
    }
    ?>
    And:

    PHP Code:
    <?php
    session_start
    ();
    $an_array = [];
    $an_array $_SESSION["MyArray".$_GET['num']];

    $processor $an_array[0];
    $payout $an_array[1];
    $status $an_array[2];
    $amount $an_array[3];
    require 
    'billing-admin.php';

    ?>

    <form action="billing-edit" method="get">
    Processor: <input name="<?php if(isset($processor)){echo $processor;} ?>" type="text" value="<?php if(isset($processor)){echo $processor;} ?>"><br>
    Payment Account : <input name="payoutaccount" type="text" value='<?= $payout ?>'><br>
    Status :
    <select name="status">
        <option value="Panding" id="Panding">Panding</option>
        <option value="Sent" id="Sent">Sent</option>
    </select><br>
    Amount : <input name="amount" type="text" value='<?= $amount ?>' ><br>
    <input type="submit" value="update">
    </form>

    <script type="text/javascript">
        document.getElementById('<?= $status ?>').selected=true;
    </script>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #6
    New Coder
    Join Date
    May 2012
    Posts
    58
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks workinf fine can you please tell me what problem in this code
    i have 4 record in mysql data base when i add echo $reault_form; in php code its show all records
    but when i add <?php echo $reault_form; ?> in html table show only one record please tell me where i add loop its show all record in html table where i add this code <?php echo $reault_form; ?>

    PHP Code:
    <?php
    require'core.php';
    require 
    'databaseconnect.php';
    require 
    'login-code.php';
    if(isset(
    $_SESSION['user_id']))
    {
    $query"SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` ,`userid` FROM `cashout`";
    if(
    $result=mysql_query($query))
    {
    while (
    $query_row=mysql_fetch_assoc($result))
    {
    $id=$query_row['id'];
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];
    $userid=$query_row['userid'];
    $userids=$_SESSION['user_id'];

    if(
    $userid==$userids)
     {
     
    $reault_form=  '<tbody><tr><td><b>'.$id.'</b></td>
                <td>'
    .$date.'</td>
                <td>'
    .$type.'</td>
                <td><img src="" style="margin-bottom: -0.36em;" alt="PayPal" /> <b>'
    .$processor.'</b></td>
                <td><strong class="hg-green">'
    .$status.'</strong></td>
                <td><b>$'
    .$amount.'</b></td></tr></tbody> ';
     }

     else{

    }
    }
    }
    else
    {
    echo
    'Database not working..';
    }
    }
    ?>

                          <div class="grid740">
                            
                                    <div class="st-tinytitle">
                                        <h3>Transaction History</h3>
                                    </div>
                                    <table id="transactions" class="ctablesorter"> 
                                        <thead> 
                                            <tr> 
                                                <th>ID</th> 
                                                <th>Date</th> 
                                                <th>Type</th>
                                                <th>Processor</th>
                                                <th>Status</th> 
                                                <th>Amount</th> 
                                            </tr> 
                                        </thead> 
                                        
                                      <?php  echo $reault_form?>
                                    </table>

                                
                                
                            </div>
    Last edited by blacktiger786; 10-13-2013 at 01:57 PM.

  • #7
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    It depends on where you echo $reault_form in the PHP. You made the same mistake I made in the first code I sent. You pull a row of data from the DB and set your variables equal to that row's information. You then call another row and reset all the variables to that row's information, $reault_form included. If the echo is within the WHILE loop you will echo each row,
    BUT if you echo after the loop, like you do in the HTML, you only get the last row's data.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #8
    New Coder
    Join Date
    May 2012
    Posts
    58
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok thanks for reply now change this code show all row thanks again
    [PHP]<?php
    require'core.php';
    require 'databaseconnect.php';
    require 'login-code.php';

    ?>


    <div class="grid740">

    <div class="st-tinytitle">
    <h3>Transaction History</h3>
    </div>
    <table id="transactions" class="ctablesorter">
    <thead>
    <tr>
    <th>ID</th>
    <th>Date</th>
    <th>Type</th>
    <th>Processor</th>
    <th>Status</th>
    <th>Amount</th>
    </tr>
    </thead>

    <?php

    if(isset($_SESSION['user_id']))
    {
    $query= "SELECT `id`, `date`, `type`, `processor`, `payoutaccount`, `status`, `amount` ,`userid` FROM `cashout`";
    if($result=mysql_query($query))
    {
    while ($query_row=mysql_fetch_assoc($result))
    {
    $id=$query_row['id'];
    $date=$query_row['date'];
    $type=$query_row['type'];
    $processor = $query_row['processor'];
    $payout=$query_row['payoutaccount'];
    $status=$query_row['status'];
    $amount=$query_row['amount'];
    $userid=$query_row['userid'];
    $userids=$_SESSION['user_id'];

    if($userid==$userids)
    {

    $reault_form= '<tbody><tr><td><b>'.$id.'</b></td>
    <td>'.$date.'</td>
    <td>'.$type.'</td>
    <td><img src="img/paypal.png" style="margin-bottom: -0.36em;" alt="PayPal" /> <b>'.$processor.'</b></td>
    <td><strong class="hg-green">'.$status.'</strong></td>
    <td><b>$'.$amount.'</b></td></tr></tbody> ';
    echo $reault_form;
    }

    else{

    }
    }
    }
    else
    {
    echo'Database not working..';
    }
    }?>
    </table>



    </div>
    <!-- END TABLE -->

    [PHP]

  • #9
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Quote Originally Posted by blacktiger786 View Post
    ok thanks for reply now change this code show all row thanks again
    NO!
    This is not a free coding service. I have shown you enough that you should be able to do it yourself.

    And learn to say PLEASE.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •