xtrax Posted July 24, 2012 Share Posted July 24, 2012 Ok I am working on something right now that I am passing the $ID of a table row off in the url and I am trying to get that ID to then go into the other function to display the results on the same page... This is what I got so far the default page which works perfectly... if($_GET['page']==''){ my Mysql inquery the my link echo "<a href=\"sample.php?page=".$ID."\">Page $ID</a> } Then I am tryning to capture the variable page= and have it go to my next function $ID = $_REQUEST['page']; if($_GET['page']=='$ID'){ $mysql = "SELECT intId, varname, var_desc FROM tcountry WHERE intId = '$ID' LIMIT 0, 1"; $result_mysql = $d->fetch($mysql); if($result_mysql){ foreach($result_mysql as $sel_op){ $Desc = stripslashes($sel_$sel_op['var_desc']); echo "$Desc.''.$ID\n"; } } } but nothing is working ...I tried GET and still nutttin Any help would be appreciated! xtrax Quote Link to comment Share on other sites More sharing options...
.josh Posted July 24, 2012 Share Posted July 24, 2012 did you echo out $ID to see if it has the expected value? If so, one thing I see is in your condition: if($_GET['page']=='$ID'){ You are using single quotes around $ID. Single quotes do not parse variables, you have to use double quotes. But you don't even need quotes around your variable in the first place. Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 24, 2012 Author Share Posted July 24, 2012 Ok let me try that and report back Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 24, 2012 Author Share Posted July 24, 2012 Ok I changed the following and now its working... if($_GET['page']==$ID){ some code here } Those darn ' quotes got me again.... I thought it was something I was overlooking..... Thank you for your time its much appreciated Xtrax Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 27, 2012 Author Share Posted July 27, 2012 Ok I am back, however I cant seem to get wwhat I want from this php page... The above post was working however its no suffecient enough for what I need, so I tried the following but its not working What I am trying to do is load everything in one php page! So I read up and it says to use a switch and then create functions for the pages so this is what I did First I created the main function function main() { mysql code and out put here..... which generates a link using the id I pull from the table, so next I want to create another function that once the link is clicked it loads the decsiption of the link selected } My second function just below the first one is called function viewdesc() { which has the mysql and pulls the data no problem } Then I used a switch with the following switch($page) { default: main(); break; case "viewdesc"; viewdesc($id); break; } However I feel I must be missing something as the page isnt loading... Need a little help noob trying to learn PHP.... xtrax Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 27, 2012 Share Posted July 27, 2012 Default should be the last case in the switch. Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 27, 2012 Author Share Posted July 27, 2012 Ok I switched it to the last section however its not reporting any errors and the page isnt loading all the way ... I added this to the top of the page ini_set('display_errors',1); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 27, 2012 Author Share Posted July 27, 2012 in other words before I added the functions it use to display the data from the database no it doesnt display anything.... Quote Link to comment Share on other sites More sharing options...
peipst9lker Posted July 27, 2012 Share Posted July 27, 2012 viewdesc() doesn't has any parameters but you're trying to pass one inside your switch Edit: Also you have a syntax error in your switch-code case "viewdesc"; Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 27, 2012 Share Posted July 27, 2012 We're only seeing bits of code here, so we have to guess. In your original post, you grabbed the requested page as $ID now you are switching on $page. Where did that come from, and does it contain what you expect? Just before the switch, you might try var_dump($page); to see what is happening with it. @jesirose: Just FYI, the default does not have to be the last entry in a switch. I sometimes put it first; when doing so more clearly documents the purpose of the switch. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 27, 2012 Share Posted July 27, 2012 I stand corrected, I thought it had to be last. Thanks. Quote Link to comment Share on other sites More sharing options...
.josh Posted July 27, 2012 Share Posted July 27, 2012 I always put it as last. IMO it makes it more clear. Kinda same principle/order as [pre] if // case else if // case else if // case else // default [/pre] Quote Link to comment Share on other sites More sharing options...
Barand Posted July 27, 2012 Share Posted July 27, 2012 I agree. When all else fails, do this. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 28, 2012 Share Posted July 28, 2012 Well, it appears I agree. I can't, for the life of me, think of a single scenario where it makes sense. But I remember doing it once, and it made sense then. I posted a similar comment back in January 2011. I just scanned through most of my code base and found 3 cases where I did it, but none of them seemed significant enough to break tradition. I guess the code has been archived. Or maybe I'm just getting old. Did we run the OP off with all this technical mumbo-jumbo? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.