473,683 Members | 3,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

testing for no data in a string

How do I test for no data in a string? I tried if !(isset($data)) and
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.

$data .= $header;
if ($data == "") {
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?

tia,

------------

this is the function for $data

function makexcldata($xc lfields, $result){

$str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";

while($row = mysql_fetch_row ($result)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value )) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"' , '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n ";
}

$data = str_replace("\r ","",$data) ;
$data .= $str1;

return $data;
}
Sep 18 '08 #1
6 1325
AqD
On Sep 18, 8:56*am, JRough <jlro...@yahoo. comwrote:
How do I test for no data in a string? *I tried if !(isset($data)) and
$data =="" *and neither one returns the message when there are no
records found. *Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? *The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data === "" or strlen($data) == 0 should work for you; isset is only
to check if the variable exists (set by you).

But there seems to be a problem in your design. If the page queries
and displays records from DB and provides a button to export excel,
usually the export action should do the queries again (un-optimized
method).
>
$data .= *$header;
* * * * if ($data == "") {
* * * * * * * * * * * * $data = "\n(0) Records Found!\n";}
* * * * header("Content-type: application/xmsdownload");
* * * * header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
* * * * header("Pragma: no-cache");
* * * * header("Expires ; 0");
* * * * print "$header\n$data ";

the other question is how do I get it to print the date on the
filename in excel?
you need to use date() with custom format. Don't rely on the default
date/time format, even if it works for now.
>
tia,

------------

this is the function for $data

function makexcldata($xc lfields, $result){

* * * * * *$str1 = '';
* * * * * * * * for($i=0; $i < sizeof($xclfiel ds); $i++){
* * * * * * * * * * * * $str1 .= $xclfields[$i];
* * * * * * * * * * * * $str1 .= "\t";
* * * * * * * * * * * * }
* * * * $str1 .= "\n";

while($row = mysql_fetch_row ($result)) {
* * $line = '';
* * foreach($row as $value)
{
* * * * if ((!isset($value )) OR ($value == "")) {
* * * * * * $value = "\t";
* * * * } else {
* * * * * * $value = str_replace('"' , '""', $value);
* * * * * * $value = '"' . $value . '"' . "\t";
* * * * }
* * * * $line .= $value;
* * }
* * $data .= trim($line)."\n ";

}

$data = str_replace("\r ","",$data) ;
$data .= $str1;

return $data;

}
Sep 18 '08 #2
JRough wrote:
How do I test for no data in a string? I tried if !(isset($data)) and
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.

$data .= $header;
if ($data == "") {
Just

if (!$data) {

will suffice. It's better to test for empty vars specifically with:

empty($var);
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?

tia,

------------

this is the function for $data

function makexcldata($xc lfields, $result){
At this point, check how many records exist in result set, if any:

if ( !mysql_num_rows ) {
return false;
}
$str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";

while($row = mysql_fetch_row ($result)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value )) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"' , '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n ";
}

$data = str_replace("\r ","",$data) ;
$data .= $str1;

return $data;
}
--
Curtis
Sep 18 '08 #3
Curtis wrote:
JRough wrote:
>How do I test for no data in a string? I tried if !(isset($data)) and
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.

$data .= $header;
if ($data == "") {

Just

if (!$data) {

will suffice. It's better to test for empty vars specifically with:

empty($var);
> $data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.=no w().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?

tia,

------------

this is the function for $data

function makexcldata($xc lfields, $result){

At this point, check how many records exist in result set, if any:

if ( !mysql_num_rows ) {
return false;
}
Sorry, brain fart.

if ( !mysql_num_rows ($result) ) {
return false;
}
> $str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";

while($row = mysql_fetch_row ($result)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value )) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"' , '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n ";
}

$data = str_replace("\r ","",$data) ;
$data .= $str1;

return $data;
}

--
Curtis
Sep 18 '08 #4
On Sep 17, 6:39*pm, Curtis <dye...@gmail.c omwrote:
Curtis wrote:
JRough wrote:
How do I test for no data in a string? *I tried if !(isset($data)) and
$data =="" *and neither one returns the message when there are no
records found. *Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? *The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data .= *$header;
* * if ($data == "") {
Just
if (!$data) {
will suffice. It's better to test for empty vars specifically with:
empty($var);
* * * * * * $data = "\n(0) Records Found!\n";}
* * header("Content-type: application/xmsdownload");
* * header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
* * header("Pragma: no-cache");
* * header("Expires ; 0");
* * print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?
tia,
------------
this is the function for $data
function makexcldata($xc lfields, $result){
At this point, check how many records exist in result set, if any:
if ( !mysql_num_rows ) {
* *return false;
}

Sorry, brain fart.

if ( !mysql_num_rows ($result) ) {
* * return false;

}
* * * *$str1 = '';
* * * * for($i=0; $i < sizeof($xclfiel ds); $i++){
* * * * * * $str1 .= $xclfields[$i];
* * * * * * $str1 .= "\t";
* * * * * * }
* * $str1 .= "\n";
while($row = mysql_fetch_row ($result)) {
* * $line = '';
* * foreach($row as $value)
{
* * * * if ((!isset($value )) OR ($value == "")) {
* * * * * * $value = "\t";
* * * * } else {
* * * * * * $value = str_replace('"' , '""', $value);
* * * * * * $value = '"' . $value . '"' . "\t";
* * * * }
* * * * $line .= $value;
* * }
* * $data .= trim($line)."\n ";
}
$data = str_replace("\r ","",$data) ;
$data .= $str1;
return $data;
}

--
Curtis
thanks for your answers. Are you saying check for the empty variable
and if it is empty then check if (!mysql_num_row s) is false
Doing both or only one or the other?

Sep 18 '08 #5
On Sep 17, 6:39*pm, Curtis <dye...@gmail.c omwrote:
Curtis wrote:
JRough wrote:
How do I test for no data in a string? *I tried if !(isset($data)) and
$data =="" *and neither one returns the message when there are no
records found. *Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? *The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data .= *$header;
* * if ($data == "") {
Just
if (!$data) {
will suffice. It's better to test for empty vars specifically with:
empty($var);
* * * * * * $data = "\n(0) Records Found!\n";}
* * header("Content-type: application/xmsdownload");
* * header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
* * header("Pragma: no-cache");
* * header("Expires ; 0");
* * print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?
tia,
------------
this is the function for $data
function makexcldata($xc lfields, $result){
At this point, check how many records exist in result set, if any:
if ( !mysql_num_rows ) {
* *return false;
}

Sorry, brain fart.

if ( !mysql_num_rows ($result) ) {
* * return false;

}
* * * *$str1 = '';
* * * * for($i=0; $i < sizeof($xclfiel ds); $i++){
* * * * * * $str1 .= $xclfields[$i];
* * * * * * $str1 .= "\t";
* * * * * * }
* * $str1 .= "\n";
while($row = mysql_fetch_row ($result)) {
* * $line = '';
* * foreach($row as $value)
{
* * * * if ((!isset($value )) OR ($value == "")) {
* * * * * * $value = "\t";
* * * * } else {
* * * * * * $value = str_replace('"' , '""', $value);
* * * * * * $value = '"' . $value . '"' . "\t";
* * * * }
* * * * $line .= $value;
* * }
* * $data .= trim($line)."\n ";
}
$data = str_replace("\r ","",$data) ;
$data .= $str1;
return $data;
}

--
Curtis
thanks for your answers it was helpful.
By the way, I did the queries twice once for the html part and once
for the part where the excel button is sent.
the code was really long so I didn't include it.
Are you saying check for the empty variable empty($var);
and if it is empty then do the check if (!mysql_num_row s) is false?
Doing both or only one or the other? Or is that mysql_num_rows check
for if I redid the queries? tia,
Sep 18 '08 #6
JRough wrote:
On Sep 17, 6:39 pm, Curtis <dye...@gmail.c omwrote:
>Curtis wrote:
>>JRough wrote:
How do I test for no data in a string? I tried if !(isset($data)) and
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data .= $header;
if ($data == "") {
Just
if (!$data) {
will suffice. It's better to test for empty vars specifically with:
empty($var) ;
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.= now().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?
tia,
------------
this is the function for $data
function makexcldata($xc lfields, $result){
At this point, check how many records exist in result set, if any:
if ( !mysql_num_rows ) {
return false;
}
Sorry, brain fart.

if ( !mysql_num_rows ($result) ) {
return false;

}
>>> $str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";
while($row = mysql_fetch_row ($result)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value )) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"' , '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n ";
}
$data = str_replace("\r ","",$data) ;
$data .= $str1;
return $data;
}
--
Curtis
thanks for your answers it was helpful.
By the way, I did the queries twice once for the html part and once
for the part where the excel button is sent.
the code was really long so I didn't include it.
Are you saying check for the empty variable empty($var);
and if it is empty then do the check if (!mysql_num_row s) is false?
Doing both or only one or the other? Or is that mysql_num_rows check
for if I redid the queries? tia,
I was just explaining what empty did, it's not really necessary for
this specific case. mysql_num_rows( ) should be used in your function
that returns $headers. If the amount of rows in the result set from
your query is 0, or it returned false, then we just return false in
the function. You should test $headers, and if it evaluates to false,
then you don't have any results.

--
Curtis
Sep 18 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5805
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is held in memory and therefore fast, without risk of damaging real files, and with none of the messiness of leftover files after testing. Googling the archives and the web suggests that only I and Remy Blank have done much along these lines. I...
3
2303
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be stubbed" in mind is great, so in many cases dropped. I would appreciate if anyone interested in this...
4
510
by: Nathon Dalton | last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples For string I use this If Not abc.text Is Nothing AndAlso Not abc.text = "" The ' Some Cod End I For datetime's I'm currently using something like this If Not abc.ToShortDateString = "01/01/0001" The ' Some Cod
6
3249
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start erroring out. I see two different errors. One is a "Object reference not set to an instance of an object." error, which appears to always contain the same information, and the other is a "There is no row at position X.", where X is a number. Is this...
0
377
by: Mairead O' Donovan | last post by:
From: davidkeaveny@gmail.com (CtrlAltDel) Newsgroups: microsoft.public.dotnet.datatools Subject: Unit-testing applications that use the Microsoft.Patterns.EnterpriseLibrary.Data Date: 15 Apr 2005 08:06:31 -0700 I've written a web application that uses the M.P.E.D namespace to do all of its data layer tasks (and a nifty bit of code M.P.E.D is too!). However, unit-testing is proving a bit of a problem, as the database factory complains...
7
2147
by: Filips Benoit | last post by:
Hi, TBL_CONTACT_PERSON CNTP_ID (auto) CNTP_LAST_NAME (required = yes) CNTP_FUNCTION (required = no) CNTP_..... (all required = no) FRM_CONTACT_PERSON_ADD_NEW Property DATA ENTRY = YES
5
2731
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the puck moving around. I want the puck is bounce when it hits a border (specified by the hitlines). Retreieved some info on hit testing lines from Bob Powell's GDI+ FAQ (very useful!) but i'm fairly new at the idea of hit testing and am
72
5244
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
1
1367
by: iLL | last post by:
If I have a collection of polymorphic objects, is there a way to test exactly what data type an element of that collection is? I’ve though of two workarounds: 1. Type casting and testing thought exception handling. 2. Adding a String to the root class that represents the data type. But if there is a conventional way of testing this, I would rather use that. I’ve tried doing a Google search on polymorphism data type testing, but it...
2
1673
by: Luc The Perverse | last post by:
Hello! I am trying to find a way to deal with Windows' case insensitivity without just forcing everything lowercase. While I am open to criticism on my method - my question relates to the fourth to bottom line (not including curly braces) on the bottom - testing to see if the Comparer is not StringComparer.OrdinalIgnoreCase My concern is eventually when I decide to serialize these to files, to store persistant data, that somehow -...
0
8568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8753
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6429
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.