1

SOLVED

Is there a manner to echo out each row from an SQL query without calling them with their names?

  $result = mysql_query("SELECT * FROM testtable");
  $res = mysql_fetch_array($result);

  echo "<pre>";
    print_r($res);
  echo "</pre>";

here my solution $query = "SELECT * FROM usr WHERE usr_id = $user_id"; $result = mysql_query($query);
$results = mysql_num_rows($result); for($i=0; $i

 $records=mysql_fetch_assoc($result);
 ?>
 <table class="table table-striped table-responsive">
    <thead>
        <th>Name</th>
        <th>Value</th>
    </thead>
    <tbody><?php


        foreach($records as $item=>$val){
        ?>
            <tr>        
            <?php
            $a = array( "id", 
                                    "first_inlog", 
                                    "last_inlog", 
                                    "reg_date", 
                                    "reg_ip", 
                                    "reg_info");

            echo  '<td>'.$item.'</td>';

            if (in_array($item, $a)){
                        echo '<td> <input class="form-control" type="text" name="fname" value="'.$val.'" disabled></td>';           
            }else{
                echo '<td> <input class="form-control" type="text" name="fname" value="'.$val.'"></td>';            
                }
            ?>
            </tr>
    <?php
        }
    ?>
    </tbody>
 </table>
 <?php
 }
 ?>
  • 2
    Also, [please stop using mysql_ functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They have been removed from PHP – Machavity Aug 27 '16 at 17:44
  • @Machavity. yeah i know about the deprecated mysql. but what i want isn't write down each field name – Yoeri Plovie Aug 27 '16 at 17:53
  • This is not a duplicate of the question linked... OP specifically wants to know how to output all data *without* knowing all field (column) names. – Patrick Moore Aug 27 '16 at 18:36
  • right ^^ @PatrickMoore mayby counting the results in the fetch array ? and then echo them trough an while loop ? – Yoeri Plovie Aug 27 '16 at 18:37
  • The easiest way would be like: `while( $row = mysql_fetch_array( $result ) ){ foreach( $row as $column=>value){ echo "$column : $value" . "\r\n"; } }` which loops through each result in the result set, and for each result, loops through each key/value pair. – Patrick Moore Aug 28 '16 at 03:53

0 Answers0