Jump to content

Recommended Posts

Hi there.

 

I have a PHP Function like so:

 

 <?php function JomSocial_field($fieldcode) {
$database=& JFactory::getDBO();
  $user =& JFactory::getUser();
  $userId = $user->get( 'id' );
  $sql = "SELECT (id) FROM #__community_fields WHERE fieldcode= '$fieldcode'";
  $database->setQuery( $sql );
  $fieldID = $database->loadResult();
  $sql = "SELECT (value) FROM #__community_fields_values WHERE field_id= {$fieldID} && user_id= {$userId}";
  $database->setQuery( $sql );
  echo $database->loadResult();
}

?>

 

I can then insert the results into form inputs like so: 

<input type="hidden" id="enrolment_year" name="enrolment_year" value="<?php JomSocial_field("enrolment_year"); ?>" />

 

However, I now want to use the result in a variable like so

 

 <?php $filename1 = "folder/".print(JomSocial_field("enrolment_year"))."/file.zip";

 

but it doesn't work...it just actually prints the result as text on the page. The echo command doesn't work either.  If it were an item that has been posted, I could get it using the $_POST["enrolment_year"], but the trouble is, I want to get the value on first page load, not after a post.

 

Can anyone help me please?

That function doesn't return any data.  If you'd like to use the return value of a function...return something.

 

Also, stop printing things if you want to put them in a variable.  You've taken a function that prints information and attempted to print it again when you're trying to assign it.

Hi there

 

Thanks for pointing this out!!!  You mean a like...

 

 

<?php function JomSocial_field($fieldcode) {

$database=& JFactory::getDBO();

  $user =& JFactory::getUser();

  $userId = $user->get( 'id' );

  $sql = "SELECT (id) FROM #__community_fields WHERE fieldcode= '$fieldcode'";

  $database->setQuery( $sql );

  $fieldID = $database->loadResult();

  $sql = "SELECT (value) FROM #__community_fields_values WHERE field_id= {$fieldID} && user_id= {$userId}";

  $database->setQuery( $sql );

  return $database->loadResult();

}

 

?>

 

Setting a variable from this like: 

 

$enrolment_year = JomSocial_field("enrolment_year");

 

And then using it like

 

 

 

<?php $filename1 = "folder/"$enrolment_year."/file.zip";

 

 

?

 

Thanks for any further guidance you can give

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.