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.

'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);
}

?>

'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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.