note 12542 deleted from function.mysql-fetch-array by didou

From: Date: Tue, 29 Jul 2003 07:34:50 +0000
Subject: note 12542 deleted from function.mysql-fetch-array by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52884@lists.php.net to get a copy of this message
Note Submitter: Jean.Francois.Panico@jfpconsulting.net ---- In a database with hundreds of columns per table, it would be useful having a tool to populate PHP variables. Let's suppose we have such a table: +---+----+-------+ |KEY|name|address| +---+----+-------+ | 1 |nick|jo@i.it| | 2 |mike|mi@i.it| +---+----+-------+ and so on. It would be great having $KEY=1, $name=nick, $address=jo@i.it instead of using mysql_fetch_array() and access the variables through $myarray["KEY"], $myarray["name"] and so on. Here where my little snatch of code comes in help: ------------------------------ $query="SHOW COLUMNS FROM tablename;"; $recordset1=mysql_query($query,$handler) or die(mysql_error()); $numero_colonne=0; // number of columns in table while (list ($colonna, $uno, $due, $tre, $quattro, $cinque, $sei)=mysql_fetch_array($recordset1)) { $colonne[$numero_colonne]=$colonna; $numero_colonne++; } $query="SELECT * FROM tablename;"; $result = mysql_query($query,$handler) or die(mysql_error()); for ($j=0; $j<=mysql_num_rows($result); $j++) { $matrice=mysql_fetch_array($result); for ($i=0; $i<=$numero_colonne; $i++) $$colonne[$i]=$matrice[$colonne[$i]]; // At this point every column generated a variable with // the same name. // Place your row-handling code here! } ------------------------- Hope it helps just as PHP helps me everyday! Greetings from Italy.

« previous php.notes (#52884) next »