/    Sign up×
Community /Pin to ProfileBookmark

Hi, what i need to do is list the fields within a table. I have used the mysql_list_fields function and that works great for someone who knows how to read it. However I need to show this to a client and all I need is the actual field name and not the type, null, and extra options. Thank you.

Jason

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 28.2005 — You could do something like this, perhaps:
[code=php]
$query = "SELECT * FROM table LIMIT 1";
$result = mysql_query($query);
if($row = mysql_fetch_assoc($result))
{
echo "<p>The fields in the table are:</p>n<ul>n";
foreach($row as $field => $value)
{
echo "<li>$field</li>n";
}
echo "</ul>";
}
else
{
echo "<p>Oops! Query didn't work.</p>n";
}
[/code]
Copy linkTweet thisAlerts:
@grailquester5Apr 28.2005 — Or, if you're looking at actually describing the MySQL table structure to a client and only want the field names:
[code=php]
$qry = "SHOW COLUMNS from Table";
$result = mysql_query($qry);

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$field = $row[0];
echo "The table field name is: $field<br />n";
}

mysql_free_result($result);
[/code]
Copy linkTweet thisAlerts:
@EJMAES1973authorApr 30.2005 — Thank you both. That is what I needed.
×

Success!

Help @EJMAES1973 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...