Advice on why a problem has happened

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
ReaCt3Rr
Forum Newbie
Posts: 2
Joined: Wed Jan 27, 2010 10:22 am

Advice on why a problem has happened

Post by ReaCt3Rr »

So im new to php and have been working on differnet tuts for the past few days today tho I hit a snag, and have now a bigger problem!

Can annoyone tell me why I am getting this:

"222.4", "Candle Stick" => "4", "Coffee Table" => "80.6"); echo "

";
printf("%-20s%20s\n", "Name", "Price");
printf("%'-41s\n", " ");
foreach ($products as $key=>$val) {
printf("%-20s%20.2f\n", $key, $val );
}
echo "

"; ?>


instead of what i should be getting from this code:

Code: Select all

      <?php
       $products = array("Green Chair" => "222.4", "Candle Stick" => "4", "Coffee Table" => "80.6");
       echo "<pre>";
       printf("%-20s%20s\n", "Name", "Price");
       printf("%'-41s\n", " ");
       foreach ($products as $key=>$val) {
               printf("%-20s%20.2f\n", $key, $val );
       }
       echo "</pre>";
       ?>
This is happening with each of my files, so I thinking I may have done something in th .ini file by accident...I really hope not though! Any help at all will be appriciated

R
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: Advice on why a problem has happened

Post by timWebUK »

I got this output when using your code:
Name Price
----------------------------------------
Green Chair 222.40
Candle Stick 4.00
Coffee Table 80.60
So for your peace of mind there is nothing wrong with it, however I've no idea what would be causing a problem like the one you're getting.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Advice on why a problem has happened

Post by requinix »

Your script isn't being executed by PHP. Check that you've installed and configured everything properly.
ReaCt3Rr
Forum Newbie
Posts: 2
Joined: Wed Jan 27, 2010 10:22 am

Re: Advice on why a problem has happened

Post by ReaCt3Rr »

thanks guys, after editing the configs i hadnt reloaded apache...new it would be something simple :P ty
Post Reply