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
str_replace help
Hey there,
I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean
help removing unwanted graphic
How do I remove the small elongated rectangular shape between the "Latest post" and "
Default TimeZone
The server I'm working with is hosted in America so all times inserted into the database are coming
login box shows up again after logging in 2nd login works
Hello,
I am having trouble on my site Lockerz.rack111.com where when you login the login box
how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass
IF Statement & Two Tables With Different Echoes
I'm retrieving two tables in a single query using UNION ALL, like so:
Code: $query = "SE
How to make a input/output field with multiple lines
Hello.
I put a input/output field on the screen but I could not change height of it. I need to
Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?
Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system
adding up might be solved tell us cheers.
i think i finally solved this anybody.
last time i was getting the wrong results.
Code