Jump to content

[SOLVED] Help with a Function


JSHINER

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.