Reputation: 117
I have two tables as follows: activity_base (holds basic activity info along with activity_type) activity_email (holds specific details on email activities)
ALL tables have the activity_id that references activity_base.
An example: I am trying to output data for an email activity that gets data from other tables based on activity type.
The query will reference the activity_base to get the basic info about the activity and then if the activity_type is email, I need it to get more data from the activity_email table by running function email_activity_details.
The issue is: I cannot get $activity_details to show up comes back as undefined variable. Here is the query: Email activity Info:
function email_activity_details($activity_id){
global $connection;
$email_activity = "SELECT * FROM activity_email WHERE activity_id ='$activity_id'"
or die("Error: ".mysqli_error($connection));
$query_email_activity = mysqli_query($connection, $email_activity);
return $query_email_activity;
}
Activity Details: Which calls email_activity_details():
function view_full_activity($activity_field){
global $connection;
$contact_id = $_REQUEST['contact_id'];
$activity_id = $_REQUEST['activity_id'];
$get = "SELECT * FROM activity_base WHERE activity_id = '$activity_id' "
or die("Error: ".mysqli_error($connection));
$query = mysqli_query($connection, $get);
//Get activity base information
while ($activity = mysqli_fetch_array($query)){
$activity_related_to_id = $activity ['activity_related_to_id'];
$activity_id = $activity['activity_id'];
$activity_type_id = $activity['activity_type_id'];
}
//Get detailed activity information
//If activity is Email
if ($activity_type_id == "1") {
$email_details = email_activity_details('$activity_id');
while ( $email = mysqli_fetch_assoc($email_details)) {
$activity_details = $email['email_message'];
}
}
switch ($activity_field) {
case 'activity_id':
return $activity_id;
break;
case 'activity_title':
return $activity_title;
break;
default:
# code...
break;
}
}
Hope I am able to explain well. Thank you.
Upvotes: 1
Views: 50
Reputation: 1966
Change this line
$email_details = email_activity_details('$activity_id');
to this
$email_details = email_activity_details($activity_id);
Explanation: Dollar signs inside of single-quotes are treated literally.
From the PHP manual:
variables and escape sequences for special characters will not be expanded when they occur in single quoted strings
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single
Upvotes: 1