JSHINER Posted April 17, 2008 Share Posted April 17, 2008 Any ideas why this is not working? <?php function productList($prod_id, $id) { print '<p style="margin-left: 15px; font-size: 14px;"><a href="ticket.php?id='.$id.'&p=prod_3">'.$prod_id.'</a></p>'; } echo productList('2', $_GET['id']); ?> Quote Link to comment Share on other sites More sharing options...
conker87 Posted April 17, 2008 Share Posted April 17, 2008 Try: <?php function productList($prod_id, $id) { return "<p style=\"margin-left: 15px; font-size: 14px;\"><a href=\"ticket.php?id=$id&p=prod_3\">$prod_id</a></p>"; } productList('2', $_GET['id']); ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 17, 2008 Share Posted April 17, 2008 Try this: <?php function productList($prod_id, $id) { $str = '<p style="margin-left: 15px; font-size: 14px;"><a href="ticket.php?id='.$id.'&p=prod_3">'.$prod_id.'</a></p>'; return $str; } echo productList('2', $_GET['id']); ?> All I did was assign what you had printing inside of the function to a variable, and I returned it. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 17, 2008 Share Posted April 17, 2008 It seems to work perfectly fine for me with just the code you provided. Could you perhaps be more specific as to what is not working? Make sure $_GET['id'] has a value. Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 17, 2008 Author Share Posted April 17, 2008 Ok it does work with my code. Figured out the issue is here: When I do: <?php function productList($prod_id, $id) { if($prod_id=="1") { $prod = $page['ticket']['prod_1']; } if($prod_id=="2") { $prod = $page['ticket']['prod_2']; } print '<p style="margin-left: 15px; font-size: 14px;"><a href="ticket.php?id='.$id.'&p=prod_3">'.$prod.'</a></p>'; } echo productList('2', $_GET['id']); ?> It does not work. Assuming $prod is not working. How come? I know $page['ticket']['prod_1'] exists because it's used elsewhere on the page. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 17, 2008 Share Posted April 17, 2008 Please show the code where it is defined and is it before or after the use of the function? Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 17, 2008 Author Share Posted April 17, 2008 Was outside the function. Had the same problem the other day. Need to remember that next time. 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.