Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mysqli prepared statements - store field names in array

Codes here !

Moderators: macek, egami, gesf

mysqli prepared statements - store field names in array

Postby geno11x11 » Sat Jun 01, 2013 11:37 am

In the short snippet below, $columnNames[] contains field names in the top while loop prior to the bind statement, and then contains values after the bind statement. How do I place the field names in a separate array prior to the bind? Every effort to do so has broken the foreach loop.

Code: Select all
while ( $field = $meta->fetch_field() )
   {
   $columnNames[] = $field->name;
   }

   $x = call_user_func_array(array(&$stmt, 'bind_result'), &$columnNames);
   if (false === $x) {die('bind_param()error :' . $mysqli->error);}

   while ( $stmt->fetch() )
   { 
   foreach( $columnNames as $key=>$val)
      { 
         echo "val=",$val,"<br />";
      } 
 
   } 
geno11x11
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jan 30, 2013 5:27 pm

Re: mysqli prepared statements - store field names in array

Postby johnj » Tue Jun 04, 2013 12:59 am

copy columnNames and create another array variable.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.