Page 1 of 1

Structured Programming Trouble

Posted: Wed Jul 01, 2009 12:51 pm
by hwmetzger
I'm not sure it it's doing this because of some quark of PHP but when I run the code below it will show values in the first table generated but not the second. There are values in the database I double and triple checked that it did. Any help would be greatly appreciate it.

Code: Select all

if(isset($store_number['store1'])) //Checks to see if the user has a store number associated with them.
{
$store = $store_number['store1'];
?>
<h3>Store: <?= $store?> <a href="graph/graph.php?id=<?=$store?>" target="_blank" align="center">Graph</a></h3>
<?
        $numbers['week'] = get_week($store_number['store1']); //Each of these functions are located in a seperate fuctions.php file
        $numbers['retail'] = "$".get_retail($store_number['store1']);
        $numbers['service'] = "$".get_service($store_number['store1']);
        $numbers['netsales'] = "$".get_netsales($store_number['store1']);
        $numbers['clients'] = get_clients($store_number['store1']);
        $numbers['serviceavg'] = "$".get_serviceavg($store_number['store1']);
        $numbers['natserviceavg'] = "$".get_natserviceavg($store_number['store1']);
        $numbers['retailavg'] = "$".get_retailavg($store_number['store1']);
        $numbers['natretailavg'] = "$".get_natretailavg($store_number['store1']);
        $numbers['floorhrs'] = get_floorhrs($store_number['store1']);
        include('table.php'); //Generates a table to display the values.
        
}
if(isset($store_number['store2']))
{
$store = $store_number['store2'];
?>
<h3>Store: <?= $store?> <a href="graph/graph.php?id=<?=$store?>" target="_blank" align="center">Graph</a></h3>
<?
        $numbers['week'] = get_week1($store_number['store2']); 
        $numbers['retail'] = "$".get_retail($store_number['store2']);
        $numbers['service'] = "$".get_service($store_number['store2']);
        $numbers['netsales'] = "$".get_netsales($store_number['store2']);
        $numbers['clients'] = get_clients($store_number['store2']);
        $numbers['serviceavg'] = "$".get_serviceavg($store_number['store2']);
        $numbers['natserviceavg'] = "$".get_natserviceavg($store_number['store2']);
        $numbers['retailavg'] = "$".get_retailavg($store_number['store2']);
        $numbers['natretailavg'] = "$".get_natretailavg($store_number['store2']);
        $numbers['floorhrs'] = get_floorhrs($store_number['store2']);
        include('table.php');
        
 
}
 


I know this can be done with a loop, I am just trying to get the program working right now. The program generates the tables but only displays values for the first table and for the second on it only puts the "$" that I appended to the strings. If there is anything that is unclear let me know and I will elaborate.

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 1:21 pm
by requinix
What does print_r($store_number) say?

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 1:38 pm
by hwmetzger
Array ( [0] => store1 [1] => store2 [2] => store3 [3] => store4 [4] => store5 [5] => store6 [6] => store7 [7] => store8 [8] => store9 [9] => store10 [store1] => TX201 [store2] => TX202 [store3] => TX203 [store4] => TX204 [store5] => TX205 [store6] => TX206 [store7] => TX207 [store8] => TX208 [store9] => TX209 [store10] => TX210 )

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 1:57 pm
by hwmetzger
I did a print_r for the $numbers arrays. The first table has values, the second one looks like there arn't any values assigned to the array.

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 2:15 pm
by hwmetzger
I went into the database and ran a manual qurey. I was looking right at the row with all the information in it. When I ran the qurey I got this back:

MySQL returned an empty result set (i.e. zero rows). (Query took 0.0002 sec)

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 2:52 pm
by BornForCode
So if there are no values returned why this should be a problem? The scripts runs well.

If you are sure that there are values then maybe you should post the sql script, perhaps there is the problem.

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 3:49 pm
by hwmetzger
Thats the thing, there is data in the database, but when I run the query it says: MySQL returned an empty result set (i.e. zero rows). (Query took 0.0002 sec)

Re: Structured Programming Trouble

Posted: Wed Jul 01, 2009 4:46 pm
by Christopher
Did you check to see if there was an error after your query? No result sometimes indicates that an error occurred.

Re: Structured Programming Trouble

Posted: Thu Jul 02, 2009 1:46 pm
by hwmetzger
Well, I'm thinking I may have set the database up wrong. But that still wouldn't account for the program working with the first row but not any of the subsequent rows.

In my database I have this:
Table: reports
number= TX201 varchar(32)
weekending = 6/20/2009 varchar(32)
clients = 254 int(32)
etc...

When I try to run:
"SELECT weekending FROM reports WHERE number = 'TX201'"

I get back:weekending = 6/20/2009

Now the second entry in the table is this

number = TX202 varchar(32)
weekending = 6/20/2009 varchar(32)
clients = 337 int(32)
etc...

I do the exact same query just with a different number:
"SELECT weekending FROM reports WHERE number = 'TX202'"

I get back: MySQL returned an empty result set (i.e. zero rows). (Query took 0.0003 sec)

Re: Structured Programming Trouble

Posted: Thu Jul 02, 2009 2:37 pm
by Christopher
Is number in the database " TX202" or "TX202 " perhaps?

Re: Structured Programming Trouble

Posted: Fri Jul 03, 2009 9:02 am
by hwmetzger
arborint wrote:Is number in the database " TX202" or "TX202 " perhaps?
No, it's just 'TX202' I tried ' TX202' and ' TX202 ' also.

Re: Structured Programming Trouble

Posted: Fri Jul 03, 2009 11:08 am
by Christopher
But you say you get a record when you do "SELECT weekending FROM reports WHERE number = 'TX201'", but not when you do "SELECT weekending FROM reports WHERE number = 'TX202'" That seems to indicate that there is no 'TX202' in the number column. My examples where just examples, you need to find out the exact value. Maybe try "SELECT weekending FROM reports WHERE number LIKE '%TX202%'".