redarrow Posted December 25, 2006 Share Posted December 25, 2006 now as you can see from the code you click a link then the function is suppose to show but i keep getting errors strang stuff lol.i wont to for pratice do it this way is it possable with only two pages cheers.so in essance is it possable to get the same result for the members on pages yes if we divided the pages to three or one it will work but what about two.as you can see becouse the link is on the same page as the function it's hard thanks anyway.remeber funtion page and link profile.php[code]<?php session_start();$userid="member_0001";echo "<a href='result.php?userid=$userid'>$userid</a><br>";function member_one(){$name="redarrow";$location="london";$message="have a good xmas and a happy new year";echo "$name <br> $location <br> $message <br>";} $userid="member_0002";echo "<a href='result.php?userid=$userid'>$userid</a><br>";function member_two(){$name="john";$location="london";$message="have a good xmas";echo "$name <br> $location <br> $message <br>";}$userid="member_0003";echo "<a href='result.php?userid=$userid'>$userid</a><br>";function member_three(){$name="petter";$location="london";$message="happy new year";echo "$name <br> $location <br> $message <br>";}?>[/code]result.php[code]<?phpinclude ("profile.php");if($_GET["userid"]=="member_0001"){ member_one()}elseif($_GET["userid"]=="member_0002"){member_two()}elseif($_GET["userid"]=="member_0003"){ member_three() }?>[/code] Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/ Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 You've forgotten to end three statements in result.php with semi-colons.Another way to write result.php would be to use a switch statement:[code]<?phpinclude ("profile.php");switch ($_GET['userid']) { case "member_0001": member_one(); break; case "member_0002": member_two(); break; case "member_0003": member_three(); break; }?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147472 Share on other sites More sharing options...
redarrow Posted December 25, 2006 Author Share Posted December 25, 2006 ken cheersbut now ken how can i get the links not to show on the resulting page even theo the links ae included within the other page.for example there not there whent the results are present can that be done cheers.[code]<?phpinclude ("profile.php");if($_GET["userid"]=="member_0001"){ member_one();}elseif($_GET["userid"]=="member_0002"){member_two();}elseif($_GET["userid"]=="member_0003"){ member_three(); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147474 Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 In profile.php, put this "if" statement[code]<?phpif (!isset($_GET['userid'])) ?>[/code]before each link echo.Actually, you can tighten up the code of profile.php considerably:[code]<?php session_start();for ($i=1;$i<4;$i++) { if (!isset($_GET['userid'])) { $userid='member_' . sprintf("%04d",$i); echo "<a href='result.php?userid=$userid'>$userid</a><br>"; }}function member_one(){$name="redarrow";$location="london";$message="have a good xmas and a happy new year";echo "$name <br> $location <br> $message <br>";}function member_two(){$name="john";$location="london";$message="have a good xmas";echo "$name <br> $location <br> $message <br>";}function member_three(){$name="petter";$location="london";$message="happy new year";echo "$name <br> $location <br> $message <br>";}?>[/code]If you really want tighten your code more, you can do this for profile.php:[code]<?php session_start();for ($i=1;$i<4;$i++) { if (!isset($_GET['userid'])) { $userid='member_' . sprintf("%04d",$i); echo "<a href='result.php?userid=$userid'>$userid</a><br>"; }}function member($uid){switch ($uid) { case 'member_0001': $name="redarrow"; $location="london"; $message="have a good xmas and a happy new year"; break; case 'member_0002': $name="john"; $location="london"; $message="have a good xmas"; break; case 'member_0003': $name="petter"; $location="london"; $message="happy new year"; break;} echo "$name <br> $location <br> $message <br>";}?>[/code]and this for result.php:[code]<?phpinclude ("profile.php");member($_GET['userid']);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147481 Share on other sites More sharing options...
redarrow Posted December 25, 2006 Author Share Posted December 25, 2006 keen want to brake this down ok this is really good code pratice ok hope you can help ok and cheers.[code]for ($i=1;$i<4;$i++) { <<four loop only showing four links// got that if (!isset($_GET['userid'])) { << if the user id is set then show else dont $userid='member_' . sprintf("%04d",$i); <<< what all this please exsplain cheers and thank you. echo "<a href='result.php?userid=$userid'>$userid</a><br>"; }}[/code]my teacher told me you dont need to no swithch statement there not needed what an xxxxx Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147482 Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 The for loop is showing 3 links, not 4.The line[code]<?php$userid='member_' . sprintf("%04d",$i);?>[/code]creates them userids "member_0001", "member_0002", "member_0003" using the function [url=http://www.php.net/sprintf]sprintf()[/url].Ken Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147483 Share on other sites More sharing options...
redarrow Posted December 25, 2006 Author Share Posted December 25, 2006 Thank you going to read have a good xmas and a happy new year.solved Link to comment https://forums.phpfreaks.com/topic/31802-solved-functions-and-if-statement-all-together/#findComment-147484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.