note 87859 added to function.mysql-fetch-assoc

From: Date: Sat, 27 Dec 2008 11:40:32 +0000
Subject: note 87859 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-148556@lists.php.net to get a copy of this message
Here's a nifty function to copy a whole table to another table. Takes as its arguments $z -> the result of a SQL query with columns matching the table you're copying into. $toTable -> string name of the table to copy into. $link_identifier -> the db resource of the table you're copying into. If anyone can find a faster way to do this, I'd be glad to know about it... function mysql_multirow_copy($z,$toTable,$link_identifier) { $fields = ""; for ($i=0;$i<mysql_num_fields($z);$i++) { if ($i>0) { $fields .= ","; } $fields .= mysql_field_name($z,$i); } $q = "INSERT INTO $toTable ($fields) VALUES"; $c = 0; mysql_data_seek($z,0); //critical reset in case $z has been parsed beforehand. ! while ($a = mysql_fetch_assoc($z)) { foreach ($a as $as) { $a[key($a)] = addslashes($as); next ($a); } if ($c>0) { $q .= ","; } $q .= "('".implode(array_values($a),"','")."')"; $c++; } $q .= ";"; $z = mysql_query($q,$link_identifier); return ($q); } ---- Server IP: 203.171.30.250 Probable Submitter: 118.69.225.202 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit -- https://master.php.net/note/edit/87859 Del: integrated -- https://master.php.net/note/delete/87859/integrated Del: useless -- https://master.php.net/note/delete/87859/useless Del: bad code -- https://master.php.net/note/delete/87859/bad+code Del: spam -- https://master.php.net/note/delete/87859/spam Del: non-english -- https://master.php.net/note/delete/87859/non-english Del: in docs -- https://master.php.net/note/delete/87859/in+docs Del: other reasons-- https://master.php.net/note/delete/87859 Reject -- https://master.php.net/note/reject/87859 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148556) next »