Results 1 to 2 of 2

Thread: MySQL Column Count in PHP

  1. #1
    Join Date
    Aug 2008

    MySQL Column Count in PHP

    Hi guys,

    Ive been tasked to create a website for an electrical engineers company and need a bit of help and advice on a problem.

    The sites going to be database driven and so far runs on three pages.

    The problem I have at the moment is I need to called the database columns on a page, but they are different for each product.

    My idea was to use the mysqli_fetch($r, MYSQLI_NUM) and then loop through number 0 to the last one called back.

    This is where I get stumpted could anyone tell me a good way or loop to do this?
    Is there a command that can count the number of columns called so I can use this in the loop?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    If using MySQLi, the result's $field_count property is all you need to get the number of fields.

    However, if your intent is just to loop through all of them, there's really no need since you can just use a foreach loop:
    PHP Code:
    while($row $result->fetch_row())
    $row as $value)

    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center