pouncer Posted February 27, 2007 Share Posted February 27, 2007 i have a table called 'dvds' can someone show me a loop to echo all the field names and their data type (like INT, VARCHAR etc)? Link to comment https://forums.phpfreaks.com/topic/40412-php-loop/ Share on other sites More sharing options...
Daleeburg Posted February 27, 2007 Share Posted February 27, 2007 untested code, but this may work <?php Require('connect.db'); $query = "SELECT * FROM dvds "; $results = mysql_query($query) OR DIE("Error In DataBase"); $num = mysql_num_fields($results); $i = 0; while ($i < $num) { $type = mysql_field_type($result, $i); $name = mysql_field_name($result, $i); echo $name; echo $type; $i++; }; ?> Link to comment https://forums.phpfreaks.com/topic/40412-php-loop/#findComment-195553 Share on other sites More sharing options...
utexas_pjm Posted February 27, 2007 Share Posted February 27, 2007 <?php $sql = 'DESCRIBE dvds'; ?> Then use `Field` and `Type` as the column names. Patrick Link to comment https://forums.phpfreaks.com/topic/40412-php-loop/#findComment-195557 Share on other sites More sharing options...
pouncer Posted February 27, 2007 Author Share Posted February 27, 2007 <?php $sql = 'DESCRIBE dvds'; ?> Then use `Field` and `Type` as the column names. Patrick hmm mate, do i need a loop or anything? what about the mysql_query ? Link to comment https://forums.phpfreaks.com/topic/40412-php-loop/#findComment-195562 Share on other sites More sharing options...
utexas_pjm Posted February 28, 2007 Share Posted February 28, 2007 hmm mate, do i need a loop or anything? what about the mysql_query ? Of course: <?php $link = mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error()); mysql_select_db('database') or die('Could not select database'); $query = 'DESCRIBE pm_imps'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $line['Field'] . ' '.$line['Type'].'<br />' ; } mysql_free_result($result); mysql_close($link); ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/40412-php-loop/#findComment-195705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.