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)? Quote Link to comment 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++; }; ?> Quote Link to comment 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 Quote Link to comment 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 ? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.