Hello all,
I was wondering if anyone knows how to assign a chronoconnectivity variable to a php variable.
For example: I have a database column called 'name'. So in order to display name entries I place {name} in the body.
Now to complicate things a bit, I wish to place say a "|" before the name entries, only if they are not null/empty. So in essence I would write a php if statement or ternary condition. But in order to do so, I need to assign the value of the entry to a php variable.
Any thoughts or suggestions would be greatly appreciated.
Thanks a ton!
-JohnnyMack
I was wondering if anyone knows how to assign a chronoconnectivity variable to a php variable.
For example: I have a database column called 'name'. So in order to display name entries I place {name} in the body.
Now to complicate things a bit, I wish to place say a "|" before the name entries, only if they are not null/empty. So in essence I would write a php if statement or ternary condition. But in order to do so, I need to assign the value of the entry to a php variable.
Any thoughts or suggestions would be greatly appreciated.
Thanks a ton!
-JohnnyMack
Hi JohhnyMack,
The current row data is available as $MyRow. I think it's an array so you should be able to use $MyRow['name']
There are some limits to the scope inside the Body part. You can't execute SQL and you may need to declare global varialbes if you want to carry values from one row to the next - for a running total for example.
Bob
The current row data is available as $MyRow. I think it's an array so you should be able to use $MyRow['name']
There are some limits to the scope inside the Body part. You can't execute SQL and you may need to declare global varialbes if you want to carry values from one row to the next - for a running total for example.
Bob
Hi GreyHead.
Thank you so much for your help. I do sincerely appreciate it.
For some reason $MyRow doesn't seem to work. I keep getting Fatal error: Cannot use object of type stdClass as array in \..\components\com_chronoconnectivity\libraries\connection.php(303) : eval()'d code on line 3;
my statement on line 3 was...
echo $MyRow['name'];
withing php tags of course.
Any thoughts?
Much obliged!
-JohnnyMack
Thank you so much for your help. I do sincerely appreciate it.
For some reason $MyRow doesn't seem to work. I keep getting Fatal error: Cannot use object of type stdClass as array in \..\components\com_chronoconnectivity\libraries\connection.php(303) : eval()'d code on line 3;
my statement on line 3 was...
echo $MyRow['name'];
withing php tags of course.
Any thoughts?
Much obliged!
-JohnnyMack
Hi JohnnyMack,
I was trying to do it from memory (still am). If it isn't an array then it's probably an object (indeed that's what the message says) . . . Try
Bob
I was trying to do it from memory (still am). If it isn't an array then it's probably an object (indeed that's what the message says) . . . Try
echo $MyRow->name;
Bob
Hi GreyHead,
Thank you so much!!!! Your solution worked like a charm.
I remain much obliged to you and the Chronoengine team!
Best,
-JohnnyMack
Thank you so much!!!! Your solution worked like a charm.
I remain much obliged to you and the Chronoengine team!
Best,
-JohnnyMack
Can anyone tell me why you cant assign a variable using the placeholders? ie. $i = "{field}";
Hi innovate.invent,
The sequence in which the code is run doesn't allow it. You can user $MyRow->field to get the same result though.
Bob
The sequence in which the code is run doesn't allow it. You can user $MyRow->field to get the same result though.
$i = $MyRow->field
Bob
Hi Great forum. This is my first post so i apologise if i have missed something. I have created a form which just displays a specific rows data. All of the data comes in fine but i want to manually create a variable which includes specific parts of the data from said row and displays it using php.
I thought just doing this would work:
$MyRow->my_fieldname;
This diplays no data. I have also tried:
echo $MyRow['my_field'];
This gives me a php error.
I would be happy to point you in the direction of the site we are working on if this helps.
Our end goal is to produce a printable pdf certificate based on the said data. Below is the code we have used:
Any help would be much appreciated.
Thanks
I thought just doing this would work:
$MyRow->my_fieldname;
This diplays no data. I have also tried:
echo $MyRow['my_field'];
This gives me a php error.
I would be happy to point you in the direction of the site we are working on if this helps.
Our end goal is to produce a printable pdf certificate based on the said data. Below is the code we have used:
Any help would be much appreciated.
Thanks
<?php
require('libraries/fpdf/fpdf.php');
$vartest = $MyRow->clientaddress1;
//Create PDF
$pdf=new FPDF('P','mm','A4');
$pdf->AddPage();
//Add Logo
$pdf->Image('images/stories/clock.jpg',57,38,42,24);
//Add Box
$pdf->SetLineWidth(0.2);
$pdf->Rect(9,9,92,55,'D');
//Add Address
$pdf->SetXY(11,11);
$pdf->SetFont('Helvetica','',7);
$pdf->MultiCell(35,3,"\nyour_title_here\nyour_phone_no_here\nyour_address_here",0,'L');
//Add Other Text including variables from Database
$pdf->SetXY(10,28);
$pdf->SetFont('Helvetica','B',9);
$pdf->Cell(25,4,'Name:',0,0);
$pdf->SetFont('Helvetica','',9);
$pdf->Cell(65,4,$MyRow->Firstname . ' ' . $MyRow->Surname,0,1);
$pdf->Cell(40,10,$vartest);
// etc.
// etc.
//Save PDF to temporary file in /tmp folder
$file = basename(tempnam('.', 'tmp'));
rename($file, $file.'.pdf');
$file .= '.pdf';
$file = 'tmp/' . $file;
$pdf->Output($file, 'F');
header('Location: '.$file);
//Delete temporary PDF files in /tmp folder over an hour old
$t = time();
$dir='tmp/';
$h = opendir($dir);
while($file=readdir($h))
{
if(substr($file,0,3)=='tmp' && substr($file,-4)=='.pdf')
{
$path = $dir.$file;
if($t-filemtime($path)>3600)
@unlink($path);
}
}
closedir($h);
?>
Hi ctrlmedia,
Where are you trying to put this code? I think that $MyRow is an object so $MyRow->my_field should work if $MyRow is defined.
Bob
Where are you trying to put this code? I think that $MyRow is an object so $MyRow->my_field should work if $MyRow is defined.
Bob
Hi Bob,
Just want to thank you, cause I was struggling with assigning a {} to a variable.
I was trying the following but it didn't work.
But like you said I had to use MyRow-> and now it works.
Thanks for the support.
SaGo
Just want to thank you, cause I was struggling with assigning a {} to a variable.
I was trying the following but it didn't work.
$videoposter='{video_or_poster}';
But like you said I had to use MyRow-> and now it works.
$videoposter=$MyRow->video_or_poster;
Thanks for the support.
SaGo
Hi All,
I am having a problem here to. as I have linked tables in my connection I am using a Model ID for the main table. How do I assign to a php variable if the field is being loaded under a Model ID. ie Model.field
The following doesn't work for me
$MyRow->field.
Any help would be greatly appreciated
Allan
I am having a problem here to. as I have linked tables in my connection I am using a Model ID for the main table. How do I assign to a php variable if the field is being loaded under a Model ID. ie Model.field
The following doesn't work for me
$MyRow->field.
Any help would be greatly appreciated
Allan
Hi Allan,
Please try this:
Please try this:
$MyRow["Model"]["field"];
This topic is locked and no more replies can be posted.