Displaying Column Names
Posted on
16th Feb 2014 07:03 pm by
admin
I have a question regarding the ability to show the column names from my table/query.
What I'm looking to do is to be able to have my users enter their own query via a builder (Which I haven't built yet).
I've found a little test script from the net but it shows them in an array.
Did you know?Explore Trending and Topic pages for more stories like this.
My code is
Code: [Select]<?php
include('includes/inc.conn.php');
mysql_select_db("discover_messaging");
$result = mysql_query("SHOW COLUMNS FROM `messages`");
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
}
?>
Which outputs
QuoteArray ( [Field] => msg_id [Type] => int(11) [Null] => NO [Key] => PRI [Default] => [Extra] => auto_increment ) Array ( [Field] => msg_to [Type] => varchar(99) [Null] => NO [Key] => [Default] => [Extra] => ) Array ( [Field] => msg_from [Type] => varchar(99) [Null] => NO [Key] => [Default] => [Extra] => ) Array ( [Field] => msg_subject [Type] => varchar(255) [Null] => NO [Key] => [Default] => [Extra] => ) Array ( [Field] => msg_body [Type] => text [Null] => NO [Key] => [Default] => [Extra] => ) Array ( [Field] => read_flg [Type] => varchar(3) [Null] => NO [Key] => [Default] => off [Extra] => ) Array ( [Field] => sent_date [Type] => varchar(255) [Null] => NO [Key] => [Default] => [Extra] => )
Is there a way to have the field names come out of the array so that I can do something like?
Code: [Select]<table>
<tr>
<td>msg_id</td>
<td>msg_to</td>
etc ...
Thanks all.
No comments posted yet
Your Answer:
Login to answer
337
38
Other forums
Mysterious Timeouts
I've deployed a few simple AJAX-enabled web page to a local server that is accessed through the Inte
Do While statement
hi guys,
This may sound trivial but im new to php and as part of an assignmenti have to const
Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what th
Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi
Required to login help
I'm trying to set up my site so users have to be logged into the forum to access the site.I've been
DOMDocument parsing
Hello, I am parsing an xml file from an API which I have converted into a DOMDocument in php. This i
Shuffle Array
Hi,
I am writing a script for a game that needs players to randomly be assigned a target (ano
Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va
Sendmail.php - heading error following check_input
Hi,
I would greatly appreciate some help? I am brand new to PHP and have been searching and e
Retreiving objects from Sessions
Hi all,
I am getting really frustrated with storing and retreiving objects from a session. Bu