Jump to content

Output db field names using loop


mc136

Recommended Posts

Hi guys

brand new to php. Ive created a mysql database containing fields e.g. name, description etc.
Question is how can I display these fields using loop system. Currently using :
foreach (array("name", "description") as $v) {
    echo "$v\n";
}
would much prefer to query the database and pull back this info.

Rgds
mc136
Link to comment
https://forums.phpfreaks.com/topic/27719-output-db-field-names-using-loop/
Share on other sites

[code]
$cn=@mysql_connect("host","username","password");
@mysql_select_db("name".$cn);
$result=@mysql_query("SELECT * FROM `table`",$cn);

$row=mysql_fetch_array(result);
for($count=0;$count<mysql_num_rows($result);$count++)
{
echo $row[$count];
echo "<br>";
}
@mysql_close($cn);
[/code]
thanks for the input. when trying this it pulls back what is in the row (nice to know) but i need something simpler to pull back the field names first i.e.
Date:  Name
then to pull back the rows under each column (thanks).

cheers
mc136

will check out your site also andlet you know
note to self:
To do this, you should use mysql_fetch_array, or in many cases, mysql_fetch_assoc.  The first one obtains an array where you can either use the column name, or a row number.  Since I don't think in numbers, I use the second one, which only obtains an array of the column names.  More info:
[quote author=jsladek link=topic=115481.msg470228#msg470228 date=1163887525]
Since your brand new, help me out and give this a try.  http://www.iobe.net/proj/

Hopefully you have a few tables in your database.

I'm just looking for feedback and a newbie is a good tester.

-John
[/quote]

Install fails

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.