473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

list out field names in a mysql table

Hi,
I have created a site with php-mysql. In this project , I require to list out field names (not values) of a table using php code. Is there any sql statement to integrate php code ?

Thanks in advance
Benoy
Oct 20 '07 #1
1 1979
ak1dnar
1,584 Expert 1GB
Try like this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. $link = @mysql_connect('localhost', 'root', 'dba');
  4. if (!$link) {
  5.     die('Could not connect to MySQL server: ' . mysql_error());
  6. }
  7. $dbname = 'test';
  8. $db_selected = mysql_select_db($dbname, $link);
  9. if (!$db_selected) {
  10.     die("Could not set $dbname: " . mysql_error());
  11. }
  12. $SQLquery = "SELECT * FROM books";
  13. $res = mysql_query($SQLquery, $link);
  14. $numOfCols = mysql_num_fields($res);
  15.  
  16. for($i=0;$i<=($numOfCols-1);$i++){ 
  17. echo mysql_field_name($res, $i) . "<br>";
  18. }
  19. ?>
  20.  
  21.  
Oct 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Matt Fletcher | last post by:
Hi guys, I am trying to allow the models in a mysql database to be ordered by the site owner. I was thinking along the lines of a <SELECT> list containing the model names and Up and Down...
1
by: Neil Zanella | last post by:
Hello, Consider the following PostgreSQL or Oracle SQL DDL code: CREATE TABLE fooTable ( foo INTEGER, PRIMARY KEY (foo) ); CREATE TABLE barTable (
8
by: Ward B | last post by:
Greetings all. I'm getting the following error message... Unknown column 'icaodesc' in 'field list' when I try to update a table from a PHP form. What 'field list' is it referring to? My...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
3
by: Mark V. | last post by:
Here's what I have and I'm stumped. I have a table that has several thousand names and addresses. I only want to send to one address in a household. So what I would like to do is create a new...
13
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
8
by: Jonathan LaRosa | last post by:
Hi all, I have a list box that is populated with enough records such that there are scroll bars and a user will have to scroll through the box to see all of the records. I want to add...
11
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and...
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.