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.
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
Accessing Infotype data in dialog program
Hi All
In Dialog programs attributes I didn't see any logical database field. How can I access
Place specific image in html page when specific name is typed.
Hello,
Fairly new to PHP and was curious if someone might know how to solve a fairly simple r
PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see
DELETE rows based on content
I have a link in my rows
$bit="http://bit.ly/abcd";
$query = mysql_query("D
dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but i
retrieving images from mysql database using php
So I've been trying to figure out how to store images in a mysql database, and as far as i can tell
PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by
adding 0 to numbers
Hey guys i need to create a 00001 number in a loop. Is there a better way of forcing a 5 digit numbe
Expandable Post Code
Hi,
Hope you can help. Which currently I haven't upgraded to connect to a mysql server, so i
Adding meta tags under Zend FW
Hello there, recently has come to my hands the FTP of a website which is running under Zend, I would