note 69128 added to function.mysql-query

From: Date: Thu, 24 Aug 2006 04:15:46 +0000
Subject: note 69128 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-116247@lists.php.net to get a copy of this message
Here's an easy way to store the column names from a specified table in the array "cnames". $result = mysql_query("SHOW COLUMNS FROM tablename"); $count = 0; while ($row=mysql_fetch_row($result)){ $cnt = 0; foreach ($row as $item){ if ($cnt == 0){ $cnames[$count] = $item; $cnt++; $count++; } } } Then, to display the results comma delimited: foreach($cnames as $c){ echo $c.","; } I hope this helps some people as it took me a while to figure it out. ---- Server IP: 216.194.113.175 Probable Submitter: 141.154.146.17 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/69128 Del: integrated -- https://master.php.net/note/delete/69128/integrated Del: useless -- https://master.php.net/note/delete/69128/useless Del: bad code -- https://master.php.net/note/delete/69128/bad+code Del: spam -- https://master.php.net/note/delete/69128/spam Del: non-english -- https://master.php.net/note/delete/69128/non-english Del: in docs -- https://master.php.net/note/delete/69128/in+docs Del: other reasons-- https://master.php.net/note/delete/69128 Reject -- https://master.php.net/note/reject/69128 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116247) next »