0

normally to get my items from mysql to an array i use this code

while($row=mysqli_fetch_array($result))
{
$array[] = array('id' => $row['id'] ect...)
}

anyway I am using some OOP in my code so now I don't know what the row names from mysql are named to use in the while loop so how do I get the row names and then put them in the while loop array.

3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by diafol
0

I assume that with "row names" you mean the column names.
You can get them with the functions mysql_field_name and mysql_field_count:

while ($object = mysql_fetch_object($result) {
  for ($i = 0; $i < mysql_field_count($result); $i++) {
    $field_name = mysql_field_name($result, $i);
    $field = $object->$field_name;
    ...
  }
}

Edited by smantscheff: n/a

0

Depends which library you're using. Some have their own custom methods and properties for mysql. You using PDO or something else?

0

so that would get all my field names and I could then use them? how then could I export that array into my code to use?

0

mysqli stands for mysql improved its just a better way to connect to mysql with php that's all

0

Quite right, Ignore a senile old codger. :) I got it mixed up with something else. ANyway, can you post your code here? Even if you've oop-ified it.

0

Been racking my brains - Got it at last -SQLite was the darned thing I wthought you were using. Feeling stupid now. Mental block. Anyway, haven't used mysqli before, will have a look at it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.