PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 29th, 2012, 11:53 AM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
Loop question

I need this loop to display the $Year 12 across the page instead of straight down the page as it does now. What am I missing? Thanks in advance for any assistance.


PHP Code:
echo "<tr>";

$space 1;
$Count 1;
$Year 1912;
 while (
$Year<=2019) {
                echo 
'<th>';
                echo 
"$Year";
                echo 
'</th>';
                if (
$Count>11) {   /*Evaluates the number of years/columns for each row*/
                    
echo '</tr>';
                    
$Count=1;
                    echo 
'<tr>';
                }  
// End of if conditional
                
else ++$Count;
                     ++
$Year;
     echo 
"</tr>"

Reply With Quote
  #2  
Old September 29th, 2012, 11:58 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Posts: 2,324 paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 21 h 54 m 4 sec
Reputation Power: 201
you should have a brace } before the final echo </tr>;

Reply With Quote
  #3  
Old September 29th, 2012, 12:04 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
I tried the below and get a syntax error:

PHP Code:
echo "<tr>";

$space 1;
$Count 1;
$Year 1912;
 while (
$Year<=2019) {
                echo 
'<th>';
                echo 
"$Year";
                echo 
'</th>';
                if (
$Count>11) {   /*Evaluates the number of years/columns for each row*/
                    
echo '</tr>';
                    
$Count=1;
                    echo 
'<tr>';
                }  
// End of if conditional
                
else ++$Count;
                     ++
$Year;}
     echo 
"</tr>"

Reply With Quote
  #4  
Old September 29th, 2012, 01:53 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
HI your code has no syntax errors. Just make sure you surround it with the php tags. (also if you get errors it tells you in a more precise manner on what line)

PHP Code:
<?php

echo "<tr>";

$space 1;
$Count 1;
$Year 1912;
while (
$Year <= 2019) {
    echo 
'<th>';
    echo 
"$Year"// <--- these quotes are not needed, but do no harm
    
echo '</th>';
    if (
$Count 11) { /* Evaluates the number of years/columns for each row */
        
echo '</tr>';
        
$Count 1;
        echo 
'<tr>';
    }  
// End of if conditional
    
else
        ++
$Count;
    ++
$Year;
}
echo 
"</tr>";
?>
__________________
PHP Tutorial

Reply With Quote
  #5  
Old September 29th, 2012, 05:06 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
ok i've got this. its still a loop question so i didnt make a new post.

in the following when I execute it, i get this:

Rat /> Ox /> Tiger /> Rabbit />

When I just wnt the name from the array. whats missing?

PHP Code:
// Begin loading zodiac characters names
$zodiacNames = array(
"Rat""Ox""Tiger""Rabbit""Dragon""Snake""Horse""Ram""Monkey""Rooster""Dog""Pig");
// End loading the names array
echo "<table>";
for (
$names 0$names 12; ++$names) {
     echo 
"<td>$zodiacNames[$names] /></td>";
     } 


Thanks for your support. BTW, this is just a snippet of the whole code.

Reply With Quote
  #6  
Old September 29th, 2012, 05:09 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
look closely at your code mate:

what is the difference between:
Code:
echo "<td>$zodiacNames[$names] /></td>";

and
Code:
echo "<td>$zodiacNames[$names]</td>"; 



Careful with those rabbits and tigers btw, they tend to not mix very well

Reply With Quote
  #7  
Old September 29th, 2012, 05:21 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
thanks got it

Reply With Quote
  #8  
Old September 29th, 2012, 05:22 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Quote:
Originally Posted by maineman
thanks got it

NIce!

Reply With Quote
  #9  
Old September 29th, 2012, 07:00 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
Im getting an undefined variable in my echo statement
PHP Code:
// load the zodiac names
$zodiacNames = array(
"Rat""Ox""Tiger""Rabbit""Dragon""Snake""Horse""Ram""Monkey""Rooster""Dog""Pig");
// end loading the names array
echo "<table>";
$names "";
while (
$names 12) {
[
COLOR=Red]echo "<td><$zodiacNames[$names]></td>";[/COLOR]
      
$names++;
      } 


i dont see it.

Reply With Quote
  #10  
Old September 29th, 2012, 07:16 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Hi mate,

this undefined variable-error, is probably more specific. Next time post the complete error.

I can also really recommend that you use a decent editor to write your php in. There are some errors in it that would show up directly in pretty much all decent editors out there.
Install (for instance) Netbeans and use that.

The color tags ([COLOR=Red]) are html elements and should be echoed.
PHP Code:
echo '[/color]'

All HTML should be echoed.

But there is something very wrong with those [color] tags
Read this: http://webdesign.about.com/od/htmltags/a/bltags_deprctag.htm
Burn the book that thought you this stuff, or never visit the website that thought you this. You are learning it the wrong way. Separate functionality, content and styling

Reply With Quote
  #11  
Old September 29th, 2012, 07:21 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
was trying to highlight the line in question in red to make it stand out, so i used the forums color changer and that is what it inserted, not me.

the error $number not being defined as 0. Now the loop runs just doesn't output the names.

Reply With Quote
  #12  
Old September 29th, 2012, 07:30 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Quote:
Originally Posted by maineman
was trying to highlight the line in question in red to make it stand out, so i used the forums color changer and that is what it inserted, not me.

the error $number not being defined as 0. Now the loop runs just doesn't output the names.

AH that explains the use of that stuff, but that is not needed it can only confuse.

Well what is wrong is the index of names.instead of
PHP Code:
 $names ""

make it
PHP Code:
 $names 0// index would be a better name 


Just keep in mind that code wont make anything visible because a <td></td> should be inside of a <tr></tr>

Last edited by aeternus : September 29th, 2012 at 07:32 PM.

Reply With Quote
  #13  
Old September 29th, 2012, 07:33 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
i did that and it outputs nothing. here is the currect code.
PHP Code:
// load the zodiac names
$zodiacNames = array(
"Rat""Ox""Tiger""Rabbit""Dragon""Snake""Horse""Ram""Monkey""Rooster""Dog""Pig");
// end loading the names array
echo "<table>";

$names 0;
echo 
"<tr>";
while (
$names 12) {
echo 
"<td><$zodiacNames[$names]></td>";
      
$names++;
      } 

Reply With Quote
  #14  
Old September 29th, 2012, 07:35 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Quote:
Originally Posted by maineman
i did that and it outputs nothing. here is the currect code.
PHP Code:
// load the zodiac names
$zodiacNames = array(
"Rat""Ox""Tiger""Rabbit""Dragon""Snake""Horse""Ram""Monkey""Rooster""Dog""Pig");
// end loading the names array
echo "<table>";

$names 0;
echo 
"<tr>";
while (
$names 12) {
echo 
"<td><$zodiacNames[$names]></td>";
      
$names++;
      } 


Mate do you look at your own code or are you just posting stuff and hoping for someone else to think. Look WHat is missing.! (hint 2 endtags which ones are they)
P.s. if you dont see stuf in your browser, right click, view source and have a look.

Last edited by aeternus : September 29th, 2012 at 07:39 PM.

Reply With Quote
  #15  
Old September 29th, 2012, 07:46 PM
maineman maineman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 112 maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level)maineman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 27 m 57 sec
Reputation Power: 5
honestly i do not see it. just started trying to learn and havent much experience lately with tags. I know but i am not just throwing code out there and asking for someone to fix it.

if its 2 end tags I am at a loss. Sorry.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Loop question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap