note 40576 added to function.mysql-fetch-row

From: Date: Mon, 08 Mar 2004 15:05:16 +0000
Subject: note 40576 added to function.mysql-fetch-row
Groups: php.notes 
Request: Send a blank email to php-notes+get-66436@lists.php.net to get a copy of this message
Here's a little code snipped I used to make dynamic HTML even if the table changed its rows. Hope somebody can use it. <?PHP #Find all columns in the table $sql_a = "select * FROM table_a"; $exc_a = mysql_query($sql_a) or die(mysql_error()); $fields = mysql_list_fields($DBname, $DBTableName); $columns = mysql_num_fields($fields); for ($i = 0; $i < $columns; $i++){ $fieldnames[] = mysql_field_name($exc_a, $i); } #by referencing the values inserting it in the array IF($rst_a = mysql_fetch_array($exc_a)){ $num_fields = count($fieldnames); for ($ii = 0; $aantal_fields > $ii; $ii++){ $fieldValues[$fieldnames[$ii]] = $rst_a[$fieldnames[$ii]]; } } ?> $fieldValues[] = array of column names with their corresponding values, you can even make it multi dimensional by adding $fieldValues[$fieldnames[$ii]][] instead (so if youre wanting to have your complete database table in this array its possible :) ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-row.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40576 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40576&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40576&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66436) next »