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
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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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:
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.