close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

mysqli and mysql_num_fields

Thread began 3/19/2015 10:12 am by Jediha | Last modified 5/01/2015 2:33 pm by Ray Borduin | 838 views | 6 replies |

Jediha

mysqli and mysql_num_fields

On a page I want to use a mysql recordset. But somewhere in the code I need to know how many columns there are in the database table.
I used to use mysql_num_fields($recordsetname)

What do I need to use know with mysqli - object?
Thanx!

Sign in to reply to this post

Jason ByrnesWebAssist

to write the number of records in a MySQLi recordset to the page, there is a server behavior.

on the Server Behaviors panel, click the Plus button and select WebAssist -> MySQLi -> Display record Count -> MySQLi Display Total Records.

Sign in to reply to this post

Jediha

Hi, thank you for replying, but that was not what I asked.
I need a code to let the script know how many columns there are in the database table and there fieldnames : (c_id | c_titel | c_text | c_date | c_publish) -> makes 5 columns

Sign in to reply to this post

Jason ByrnesWebAssist

Ok, sorry, i misunderstood

use this to writ eh number columns returned from the query:
<?php echo sizeof($recordsetName->Results[0]); ?>

where recordsetName is the name of the recordset.

Sign in to reply to this post

Jediha

Thank you, just one other related question:
When I loop the number of columns inside a loop from a mysqli recordset I want to get the field name(columnname). With the old php mysql it was possible with: 'mysql_field_name'.

Is there a replacement for within the mysqli class?

Thank you!

Sign in to reply to this post

Ray BorduinWebAssist

The column names are the key values of the returned array.

I think you are trying to do something like:

php:
<?php

if (sizeof($Recordset1->Results)>0) {
?>
<table>
<tr>
<?php
  
foreach ($Recordset1->Results[0] as $key=>$val) {
?>
  <th><?php echo($key); ?></th>
<?php  
  
}
?>
</tr>
<?php
  
for ($x=0$x<sizeof($Recordset1->Results); $x++) {
?>
    <tr>
<?php
    
foreach ($Recordset1->Results[$x] as $key=>$val) {
?>
        <td><?php echo($val); ?></td>
<?php  
    
}
?>
    </tr>
<?php
  
}
?>
</table>
<?php
} else {
?>
no results found
<?php
}
?>
Sign in to reply to this post

Jediha

Thank you Ray,

that was what I was looking for. I knew there was an array, just didn't know exactly how to get the data from it.

Thanx!
Hans

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...