www.webdeveloper.com
Results 1 to 2 of 2

Thread: MySQL Column Count in PHP

  1. #1
    Join Date
    Aug 2008
    Posts
    1

    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.
    Regards
    Ryan

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,936
    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())
    {
       echo 
    "<tr>";
       foreach(
    $row as $value)
       {
          echo 
    "<td>".$value."</td>";
       }
       echo 
    "</tr>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles