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']); ?> Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/ 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']); ?> Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519504 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. Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519508 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. Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519514 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. Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519531 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? Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519570 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. Link to comment https://forums.phpfreaks.com/topic/101568-solved-help-with-a-function/#findComment-519578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.