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 Like 38 Dislike
Previous forums Next forums
Other forums

PHP and MySQL Question/Help
I have a MySQL db with all my servers and all their details like server name, IP, OS, RAM etc etc 26

PHP4 to PHP5 Conversion
Hi Everyone,

I am working on a site that is built up on PHP4 and each page is being started f

what business processes?
Hi,

A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)

Simple AND question
Hello,

I've got following code:

Code: if(strpos($row[13],"http://")

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

PHP code for a proxy
I was wondering which function I could use to create an online proxy tool. I was thinking cURL would

PHP Captcha Error help - replace the "die" command
Hi All,

I am after a bit of help with a Captcha spam protection box.

The site gave me

can i optmize image to 50% quality before uploading 2 server
Hi there

i have jus written a php program to upload and display images but when i try to uplo

problem in program for counting no of chars using pointers
Hi all, I was trying to make a program which counts number of chars in a string using concpt of poin

PEAR Email Attachment w/ $gpg
I have no issues with this code if I take out the attachement section and include the info in the em

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash