yujikaido Posted February 14, 2010 Share Posted February 14, 2010 Hi I am new to Php and learning it, I am stuck and can't figure out how to get started with this assignment. This is what I have so far. I am not looking for someone to do it for me but looking for some explanations that will help me finish it myself. I have tried looking in my book for my class and online and after 2 days I am still without a clue how to get it started to code it in php.I know it I have to use an array but don't any idea how to code it. <head> <title>VD Poem: 3</title> <META HTTP-EQUIV='refresh' CONTENT='3; URL=poem.php?n=1'> </head> <body bgcolor='#FFCC66'> <p> <br> <table width=50% align=center bgcolor=#FFFFCC border=1> <tr><td align=center><font color=#996600><h1 align=center>Until you come and<br> sit awhile with me.</text> </font></td> </tr> <?php $poem = array n=0('When I am down and, oh my soul, so weary;', n=1 'When troubles come and my heart burdened be;', n=3 'Then, I am still and wait here in the silence,', n=4 'Until you come and sit awhile with me.', n=5 'You raise me up, so I can stand on mountains;', n=6 'You raise me up, to walk on stormy seas;', n=7 'I am strong, when I am on your shoulders;', n=8 'You raise me up: To more than I can be.', n=9 'Thanks... Happy Valentine\'s Day!'); ?php> </body> </html> This is what is apart of the php program called poem.php. I would appreciate any help as I am at my end and its already late. Set up initial values and the $poem array Send out the tags to open a HTML header If a particular line of the poem is being requested retrieve that text line if not at the end of the poem set up a request to get the next line of the poem else retrieve the first line of the poem set up a request to get the second line of the poem Output the tags to close the HTML header Output the HTML body tags Output the text line of interest formatted as an <h1> tag Output the HTML tags for closing the body and the HTML Hint: The line of code that requests the fifth line of the poem should look something like this: <META HTTP-EQUIV="refresh" CONTENT="3; URL=http://localhost/poem.php?n=4"> Here is an example of it in action. http://www.cs.iusb.edu/~rbatzing/a340/poem.php Thank you Link to comment https://forums.phpfreaks.com/topic/192076-php-assignment-help/ Share on other sites More sharing options...
zeeshan_haider000 Posted February 15, 2010 Share Posted February 15, 2010 Hi, well here is an alternative: <head> <META HTTP-EQUIV='refresh' CONTENT='3; URL=index.php?n= <? if (!isset ($_GET['n'])) { $n = 0; } else { $n = $_GET['n']; } if ($n == {$n = 0; } /* Reset the loop */ else {$n = $n + 1;} echo $n; ?>'> <title>VD Poem: <? echo $n; ?></title> </head> <?php $poem = array (0 => 'When I am down and, oh my soul, so weary;', 1 => 'When troubles come and my heart burdened be;', 2 => 'Then, I am still and wait here in the silence,', 3 => 'Until you come and sit awhile with me.', 4 => 'You raise me up, so I can stand on mountains;', 5 => 'You raise me up, to walk on stormy seas;', 6 => 'I am strong, when I am on your shoulders;', 7 => 'You raise me up: To more than I can be.', 8 => 'Thanks... Happy Valentine\'s Day!'); ?> <body bgcolor='#FFCC66'> <p> <br> <table width=50% align=center bgcolor=#FFFFCC border=1> <tr><td align=center><font color=#996600><h1 align=center><? echo $poem[$n]; ?></text> </font></td> </tr> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192076-php-assignment-help/#findComment-1012359 Share on other sites More sharing options...
yujikaido Posted February 15, 2010 Author Share Posted February 15, 2010 Thanks for the help but I still can't get to work, I spent over hour messing around with it. So all the php goes it in the header. Does php code work outside the <?php ?> code? I am completely lost. I was never any good atC++ programming I thought this class might be easier but no such luck. I can get the poem to output but its outside the box and its look like it does in my php code. I would appreciate any more that anyone can give me thanks <html> <head> <META HTTP-EQUIV='refresh' CONTENT='3; URL=poem.php?n= <? if (!isset ($_GET['n'])) { $n = 0; } else { $n = $_GET['n']; } if ($n = {$n = 0; } /* Reset the loop */ else {$n = $n + 1;} echo $n; ?>'> <title>VD Poem: <? echo $n; ?></title> </head> <body> <? $poem = array (0 => 'When I am down and, oh my soul, so weary;', 1 => 'When troubles come and my heart burdened be;', 2 => 'Then, I am still and wait here in the silence,', 3 => 'Until you come and sit awhile with me.', 4 => 'You raise me up, so I can stand on mountains;', 5 => 'You raise me up, to walk on stormy seas;', 6 => 'I am strong, when I am on your shoulders;', 7 => 'You raise me up: To more than I can be.', 8 => 'Thanks... Happy Valentine\'s Day!'); <body bgcolor='#FFCC66'> <p> <br> <table width=50% align=center bgcolor=#FFFFCC border=1> <tr><td align=center><font color=#996600><h1 align=center><?echo $poem[$n]; ?> ></text> </font></td> </tr> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192076-php-assignment-help/#findComment-1012389 Share on other sites More sharing options...
yujikaido Posted February 15, 2010 Author Share Posted February 15, 2010 I am thinking the all php code needs to go into the header because in the example page I can't view the php code in the view source code option. Also the only text i get to show in my text box is the: ? echo $poem.";[$n]; > ?> so I am thinking something is not right with my array. Anybody have any Idea what I am doing wrong or point me in the right direction please. <html> <head> <META HTTP-EQUIV='refresh' CONTENT='3; URL=poemt.php?n= <?php if (!isset ($_GET['n'])) { $n = 0; } else { $n = $_GET['n']; } if ($n == {$n = 0; } /* Reset the loop */ else {$n = $n + 1;} echo $n; $poem = array (0 => 'When I am down and, oh my soul, so weary;', 1 => 'When troubles come and my heart burdened be;', 2 => 'Then, I am still and wait here in the silence,', 3 => 'Until you come and sit awhile with me.', 4 => 'You raise me up, so I can stand on mountains;', 5 => 'You raise me up, to walk on stormy seas;', 6 => 'I am strong, when I am on your shoulders;', 7 => 'You raise me up: To more than I can be.', 8 => 'Thanks... Happy Valentine\'s Day!'); ?> <body bgcolor='#FFCC66'> <p> <br> <table width=50% align=center bgcolor=#FFFFCC border=1> <tr><td align=center><font color=#996600><h1 align=center>? echo $poem.";[$n]; ></text> ?> <title>VD Poem: < echo $n; ></title> </head> <body bgcolor='#FFCC66'> <p> <br> </html> Link to comment https://forums.phpfreaks.com/topic/192076-php-assignment-help/#findComment-1012413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.