I want to get the first field name ONLY

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gpong
Forum Newbie
Posts: 16
Joined: Sun Aug 06, 2006 8:49 am

I want to get the first field name ONLY

Post by gpong »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have a problem with my table. 

here is my code:

Code: Select all

<?
  	$str="show tables from $DBname";
	$query=mysql_query($str) or die(mysql_error());
	while(list($table)=mysql_fetch_row($query))
	{
		$strfield="show fields from $table";
		$queryfield=mysql_query($strfield) or die(mysql_error());
		
		while(list($Name) = mysql_fetch_row($queryfield))
		{
			echo $Name;
			
		}
	}
?>
I want to get the first field name ONLY. is there any mysql command to do that?? help me please :)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Code: Select all

<?
$str="show tables from $DBname";
$query=mysql_query($str) or die(mysql_error());
while(list($table)=mysql_fetch_row($query))
{
$strfield="show fields from $table";
$queryfield=mysql_query($strfield) or die(mysql_error());

$fields_array = mysql_fetch_row($queryfield);

echo "The first field is: ".$fields_array[0];
}
?>
Post Reply