Jump to content

[SOLVED] Retrieving SQL Field Names


renj0806

Recommended Posts

Oh... im sorry. What i meant was if I only want the username and password to be retrieved. Not including the id.

 

Anyways, ive tried the query above and yes, i got all the fields and the details for each field. Now, how am i going to assign a variable to the field name only.

Link to comment
Share on other sites

'SHOW COLUMNS FROM [table name]'

 

will return a result set of info about the table to see the resulst do this...

<?php

$query = 'SHOW COLUMNS FROM [table name]';
$rs = mysql_query($query);

while ($row = mysql_fetch_assoc($rs))
{
print_r($row);
}

?>

 

Yep, I saw the results. What i want now is how to assign a variable for the field name only, not including all those other stuff like the field type.

Link to comment
Share on other sites

just pick out the 'Field' element from the array...

 

<?php

$query = 'SHOW COLUMNS FROM [table name]';
$rs = mysql_query($query);

$field = array();
while ($row = mysql_fetch_assoc($rs))
{
$field[] = $row['Field'];
}

?>

 

that will give you an array of all the fields.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.