Jump to content

Ok need help with tring to pass a variable to the same page


xtrax

Recommended Posts

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 :-[

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.

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  :D

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

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.

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.  :cry:

 

Did we run the OP off with all this technical mumbo-jumbo?  :confused:

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.