close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Way to get fields total

Thread began 6/24/2020 9:00 am by wdtp.com | Last modified 6/25/2020 10:30 am by Ray Borduin | 133 views | 10 replies |

wdtp.com

Way to get fields total

Is there a way to get total fields similar to total rows i.e. $Recordset->TotalRows?

I searched in rsobj.php and found mysqli_num_fields but can't figure out how to use it to grab total fields for a Recordset.

Sign in to reply to this post

Ray BorduinWebAssist

You just want a count?

It would be: sizeof($Recordset1->Columns);

Sign in to reply to this post
Did this help? Tips are appreciated...

wdtp.com

I thought that would work but I get an error:

Warning</b>
: sizeof(): Parameter must be an array or an object that implements Countable in /nfs/c03/h02/mnt/51355/domains/test.lizmoore.com/html/test.php on line 133

I'm trying to adapt some the code below to create an xml file from a Recordset. I need it to work with MySQLi.

The line $totalColumns = sizeof($rsHoods->Columns); is where my current problem is. The original line was: $totalColumns=mysql_num_fields($rsHoods);

<?php
if (1==1) {
header("Content-type: text/xml");
header("Pragma: public");
header("Cache-control: private");
header("Expires: -1");
$export_rsHoods="";
if($export_rsHoods=="1"){
header("Content-Disposition: attachment; filename=recordset.xml");
header("Content-Type: application/force-download");
}
echo "";
echo "<recordset total=\"".$rsHoods->TotalRows."\">";
if($rsHoods->TotalRows > 0){
$Start_Record = 0;
$Num_Records = $rsHoods->TotalRows;
$Current_Record = 0;
if(isset($_POST['Start_Record']) && $_POST['Start_Record']!="" && isset($_POST['Num_Records']) && $_POST['Num_Records']!=""){
$Start_Record = $_POST['Start_Record'];
$Num_Records = $_POST['Num_Records'];
}
if(isset($_GET['Start_Record']) && $_GET['Start_Record']!="" && isset($_GET['Num_Records']) && $_GET['Num_Records']!=""){
$Start_Record = $_GET['Start_Record'];
$Num_Records = $_GET['Num_Records'];
}
$totalColumns = sizeof($rsHoods->Columns);
do{
if($Current_Record >= $Start_Record){
echo "<record>";
for ($x=0; $x<$totalColumns; $x++) {
$field = mysqli_fetch_field_direct($rsHoods, $x);
echo "<".$field."><"."![CD"."ATA[".$rsHoods->getColumnVal('$field')."]"."]></".$field.">";
}
echo "</record>";
}
$Current_Record=$Current_Record+1;
if($Current_Record-$Start_Record==$Num_Records){break;}
}while (!$rsHoods->atEnd());
}
echo "</recordset>";
die();
}
?>

Sign in to reply to this post

Ray BorduinWebAssist

What version of rsobj.php are you using?

Sign in to reply to this post
Did this help? Tips are appreciated...

wdtp.com

version 2.27

Sign in to reply to this post

Ray BorduinWebAssist

Try this one. Reinstall the latest version of databridge to use this one automatically in future applications.

Attached Files
rsobj.php
Sign in to reply to this post
Did this help? Tips are appreciated...

wdtp.com

Almost there! What can I use to replace this line to get the current field name?

$field=mysql_field_name($rsHoods, $x);

Sign in to reply to this post

wdtp.com

I think I got that figured out:

$field = $rsHoods->Columns[$x]->name;

Sign in to reply to this post

wdtp.com

Got some questions about the differences between rsobj.php v2.27 and 2.38

$this->Debug = false; WHY FALSE?

$this->Prepared = true; WHY TRUE?

if ($paramValue === "" || $paramValue === NULL) $paramValue = $paramDefault;

What if I want a text variable to allow a blank value to be passed in order to match everything with a "contains" match?

Sign in to reply to this post

Ray BorduinWebAssist

Debug is set to false so that information can't be seen in errors that might include your database username or column names that a hacker could potentially use. It should always be set to false in a live environment and since most people wouldn't know where to change it after finishing development, it is defaulted to false.

Change it to true temporarily when you want to see more information about an error, but it should remain on false whenever in a production environment for security.

Prepared is set to true because it ensures SQL injection protection. There is SQL injection protection that I added when not using parameterized, but it is mine and not the built in MySQLi protection which is more tried and true. Setting it to true is actually probably a bit faster, but probably negligible unless you have a very high load on your server.

You can set a default for what to use when a parameter is blank. It has values like "WA_NULL", "WA_BLANK", "WA_ZERO", "WA_DEFAULT" or you can set it to a string. This just allows you to set a default other than blank when a blank value is entered. If the default is set to "WA_BLANK" then the blank value is maintained.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

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