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

Links not updating
I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to ret

Login Functionality Working Different on IE
This is an odd one, I have a site which has an admin section. The admin pages unsurprisingly require

AutoChoosing a CSS file based on URL
Hey everyone,

I have a site that has multiple URLs and CSS files.

Based on the URL tha

moving mouse to display image coordinates
I have an existing MFC application that shows an image in the main window.
I'd like to be able to

get url?
how do i get the url of the page i'm currently on, on my website.. i think its get header.. how do i

natcasesort works on one server but not on another
Hi

I have a problem that I was hoping that someone can help me with.

I'm trying to use

Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi

Breaking results into week blocks
I have a set of dates (and times), which are returned from a mySQL query.

These usually span

Error in Configure System Landscape Directory phase
Hi

We are getting the error in Configure SLD phase ( 41 of 44 phase).

Please f

Simpler method of getting variables from mysql
Hi Guys,

I'm trying to streamline my CMS's code and as I was writing a new page it occured to

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