Structured Programming Trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Structured Programming Trouble

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Structured Programming Trouble

Post by requinix »

What does print_r($store_number) say?
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post 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 )
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post 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.
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post 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)
BornForCode
Forum Contributor
Posts: 147
Joined: Mon Feb 11, 2008 1:56 am

Re: Structured Programming Trouble

Post 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.
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post 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)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Structured Programming Trouble

Post by Christopher »

Did you check to see if there was an error after your query? No result sometimes indicates that an error occurred.
(#10850)
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post 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)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Structured Programming Trouble

Post by Christopher »

Is number in the database " TX202" or "TX202 " perhaps?
(#10850)
hwmetzger
Forum Commoner
Posts: 25
Joined: Fri Jun 12, 2009 1:11 pm

Re: Structured Programming Trouble

Post by hwmetzger »

arborint wrote:Is number in the database " TX202" or "TX202 " perhaps?
No, it's just 'TX202' I tried ' TX202' and ' TX202 ' also.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Structured Programming Trouble

Post 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%'".
(#10850)
Post Reply