PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
naeem1984
Forum Newbie
Posts: 10 Joined: Thu Feb 26, 2009 3:55 am
Post
by naeem1984 » Fri Feb 27, 2009 5:14 am
i retrieve the data from database using following code
Code: Select all
while ($row = (mysql_fetch_array($result1)))
{
echo $row["auto#"]."<br>";
echo $row["name"]."<br>";
echo $row["email"]."<br>";
}
but i want to retrieve the database fields name from database which are
auto#,
name,
email
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Fri Feb 27, 2009 5:51 am
I don't really understand why you'd need to do this. Is it dynamic query generation or something? You could just use
array_keys() on $row inside the while loop.
Maybe a
DESCRIBE query is what you're after.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Feb 27, 2009 5:52 am
Code: Select all
while ($row = (mysql_fetch_array($result1)))
foreach ($row as $key => $value)
echo $key . " = " . $value . "<br />";
PS:
jayshields is right - you need to clarify your question.
There are 10 types of people in this world, those who understand binary and those who don't
naeem1984
Forum Newbie
Posts: 10 Joined: Thu Feb 26, 2009 3:55 am
Post
by naeem1984 » Fri Feb 27, 2009 7:00 am
how avoid indexes which shows with keys and values
Code: Select all
foreach ($row as $key => $value)
{
echo "<td>".$key ."</td>";
}
it shows the field name with indexes
e.g
0 auto#
1 name
2 email
3 person
how avoid indexes
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Feb 27, 2009 8:57 am
mysql_fetch_assoc()
There are 10 types of people in this world, those who understand binary and those who don't