Display output on webpage

Reply

Join Date: Mar 2005
Posts: 30
Reputation: crestaldin is an unknown quantity at this point 
Solved Threads: 0
crestaldin crestaldin is offline Offline
Light Poster

Display output on webpage

 
0
  #1
Feb 18th, 2007
Hello all,
I'm a PHP newbie and have my apache Server and PHP in place. I have been able to run simple programs that work well. However, since then when I do "http ://localhost/filename.php" I either get 2 messages.
1. An error message if there's an error in my code
2. A blank page if I don't get an error message.

For example, the code below gives a blank screen. Pls help me with this.


  1. <?php
  2. $pictures = array('PixsIMG_0037.jpg','PixsIMG_0038.jpg','PixsIMG_0039.jpg
  3. ','PixsIMG_0040.jpg');
  4.  
  5. shuffle($pictures);
  6. ?>
  7.  
  8.  
  9.  
  10. <html>
  11. <head>
  12. <title>Doe Cafe</title>
  13. </head>
  14. <body>
  15. <center>
  16. <h1>Doe Cafe</h1>
  17. <table width = '100%' >
  18. <tr>
  19.  
  20.  
  21. <?php
  22. for( $i = 0; $i < 3; $i++)
  23. {
  24. echo '<td align="center"><img src =" ';
  25. // echo $pictures[$i];
  26. echo $i;
  27. echo ' "width ="100" height ="100"></td>;
  28. }
  29. <?
  30.  
  31. </tr>
  32. </table>
  33. </center>
  34. </body>
  35. </html>
  36.  
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: Display output on webpage

 
0
  #2
Feb 19th, 2007
There is many errors in your PHP statement thats in the body of your page which I will explain below. Try somthing like this:

  1.  
  2. <?php
  3.  
  4. for( $i = 0; $i < 4; $i++)
  5. {
  6.  
  7. echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
  8.  
  9. }
  10.  
  11. ?>

Your errors were here:

- Your if statment will only display 3 photos while there is 4 in your array. You can either change the number to test for to 4, or change your tester to less than or equal to .... <=.

- You commented out the part that places the picture filename into the image tag. (the // makes PHP ignore it.)

-You put the value of $i in the src part of your image tag.

- You did not close the third echo after the </td> tag

- Your PHP closing tag is backwards. Should be ?>
Last edited by GliderPilot; Feb 19th, 2007 at 5:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 30
Reputation: crestaldin is an unknown quantity at this point 
Solved Threads: 0
crestaldin crestaldin is offline Offline
Light Poster

Re: Display output on webpage

 
0
  #3
Feb 23rd, 2007
Originally Posted by GliderPilot View Post
There is many errors in your PHP statement thats in the body of your page which I will explain below. Try somthing like this:

  1.  
  2. <?php
  3.  
  4. for( $i = 0; $i < 4; $i++)
  5. {
  6.  
  7. echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
  8.  
  9. }
  10.  
  11. ?>

Your errors were here:

- Your if statment will only display 3 photos while there is 4 in your array. You can either change the number to test for to 4, or change your tester to less than or equal to .... <=.

- You commented out the part that places the picture filename into the image tag. (the // makes PHP ignore it.)

-You put the value of $i in the src part of your image tag.

- You did not close the third echo after the </td> tag

- Your PHP closing tag is backwards. Should be ?>
First I want to thank you for pointing out my errors, but I also have a question for you.
How do I see what errors I have with my PHP codes?(I mean is there like something similar to a debug window where errors and / or lines where they are will be displayed for my PHP codes)

Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: Display output on webpage

 
0
  #4
Feb 28th, 2007
Originally Posted by crestaldin View Post
First I want to thank you for pointing out my errors, but I also have a question for you.
How do I see what errors I have with my PHP codes?(I mean is there like something similar to a debug window where errors and / or lines where they are will be displayed for my PHP codes)

Thanks
PHP points the erroneus lines in your code, but you have to understand very well the code in order to debug. E.G. there is a difference between things like echo '$var' and echo "$var".

If you want to see errors, you have to modify your php.ini file to show the errors along with the code on the page, or, you can review the apache error log - it contains all errors occured in the PHP code.
Note errors are similar to this :

Error: Unexpected T_VARIABLE , expecting ',' or ';' on line 65 in "C:\php\my_php_file.php"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC