Result of Mysql Query in a PHP table

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Result of Mysql Query in a PHP table

    Hi,

    I've a problem:

    I want to have the result of my Mysql Query in a Table in my php file.
    Now I've this:


    <?

    mysql_connect("localhost","root")
    or die ("Keine Verbindung moeglich");

    mysql_select_db("datenbank")
    or die ("Die Datenbank existiert nicht");

    $abfrage = "SELECT * FROM tabelle";
    $ergebnis = mysql_query($abfrage);
    while($row = mysql_fetch_object($ergebnis))

    {
    echo $row->Referenznummer;
    }

    ?>


    But I want that the result is in a Table. With the heading "Referenznummer".
    It should be like:


    ---------------
    Referenznummer:
    ---------------
    Result 1
    ---------------
    Result 2
    ......
    ....
    ...


    I searched a long time in google without success, please help me

    Thanks
    Felix

    Btw: sorry for my bad english
    Felix Guest

  2. Similar Questions and Discussions

    1. Deletion based on the result of a 3 table right joins select query (MySQL 3.23)
      I am using MySQL 3.23 I have a relatively complex database with a number of Many to Many relationships (using link tables). I want to delete...
    2. Wierd query result on MySQL 5 system
      I have the following table (complete with sample data). When I run the query below on a mysql 4.1.14 system, the only row returned is row 4 as...
    3. insert mysql query into a history table... ?
      hi guys, i have created a 'history' table and would like to insert the 'bare' sql query into that table just to check who did what on the...
    4. How to display result from two different table
      Hi all Iam in a problem. Anyone plz help me in retreving data into single datagrid from two different queries. Thanks in adavance vasu
    5. Expression result not entered in table
      How do I get the result of an expression entered in a table? I have this expression as the control source: =-- but I need the result of this...
  3. #2

    Default Re: Result of Mysql Query in a PHP table

    Felix wrote:
    > Hi,
    >
    > I've a problem:
    >
    > I want to have the result of my Mysql Query in a Table in my php file.
    > Now I've this:
    >
    >
    > <?
    >
    > mysql_connect("localhost","root")
    > or die ("Keine Verbindung moeglich");
    >
    > mysql_select_db("datenbank")
    > or die ("Die Datenbank existiert nicht");
    >
    echo "<table>";
    echo "<tr><th>Referenznummer</th></tr>";
    > $abfrage = "SELECT * FROM tabelle";
    > $ergebnis = mysql_query($abfrage);
    > while($row = mysql_fetch_object($ergebnis))
    >
    > {
    echo "<tr><td>";
    > echo $row->Referenznummer;
    echo "</td></tr>";
    > }
    echo "</table>";
    >
    > ?>
    >
    >
    > But I want that the result is in a Table. With the heading "Referenznummer".
    > It should be like:
    Kevin Thorpe Guest

  4. #3

    Default Re: Result of Mysql Query in a PHP table

    Felix wrote:
    > mysql_connect("localhost","root")
    > or die ("Keine Verbindung moeglich");
    >
    > mysql_select_db("datenbank")
    > or die ("Die Datenbank existiert nicht");
    >
    > $abfrage = "SELECT * FROM tabelle";
    > $ergebnis = mysql_query($abfrage);
    > But I want that the result is in a Table. With the heading "Referenznummer".
    > It should be like:
    > ---------------
    > Referenznummer:
    > ---------------
    > Result 1
    > ---------------
    > Result 2
    Hi, Felix
    I've written a small utility function that I use for this. It takes a
    MySQL result set as an argument, and returns an HTML table (string)
    containing all the column headers and rows, formatted.

    Here's the function:

    function _mysql_result_all($result, $tableFeatures="") {
    $table .= "<!--Debugging output for SQL query-->\n\n";
    $table .= "<table $tableFeatures>\n\n";
    $noFields = mysql_num_fields($result);
    $table .= "<tr>\n";
    for ($i = 0; $i < $noFields; $i++) {
    $field = mysql_field_name($result, $i);
    $table .= "\t<th>$field</th>\n";
    }
    while ($r = mysql_fetch_row($result)) {
    $table .= "<tr>\n";
    foreach ($r as $column) {
    $table .= "\t<td>$column</td>\n";
    }
    $table .= "</tr>\n";
    }
    $table .= "</table>\n\n";
    $table .= "<!--End debug from SQL query-->\n\n";
    return $table;
    }

    You could use it like this, using your $ergebnis variable:

    print _mysql_result_all($ergebnis);

    That is, copy the function above into your script, and then use the
    preceding line to output the result.

    Enjoy...

    --
    //Marius

    Marius Mathiesen Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139