PHP PDF Creation, EZPDF Class: table with just one line and row - php

This code:
$data = array(array('row1'=>'row2'));
$this->ezTable($data, null, '',
array('width'=>'460', 'fontSize'=>'8', 'showLines'=>'1'));
shows a table with 2 rows and one column.
I need a table with just one row and one column, or four borders (top, bottom, right and left) around a text.
How can I do that?

$this->ezTable($data, null, '',
array('width'=>'460', 'fontSize'=>'8', 'showLines'=>'1','showHeadings'=>0));

Related

PhpWord multi-colum layout issue

How can I force PhpWord to write at the begin of the next multi-colum ?
I don't think there is a breaker function (such as addTextBreak() or addPageBreak()) for doing this.
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(array(
'colsNum' => 2,
'colsSpace' => 100,
'breakType' => 'continuous',
));
$table1 = $section->addTable();
//...add rows and cells to table 1
$table2 = $section->addTable();
//...add rows and cells to table 2
As expected, the result of this code snippet is two table stacked on the first multi-colum.
Adding in the code
$section->addPageBreak()
doesn't obviously work.
Any advice on how to solve this problem?
Is it a good option to add some TextBreakers to the bottom of the page for filling the space that remain after the first table?
Thanks!

wpdb->insert in ANY table always in third column inserts 0 instead of submitted string. Same string is inserted OK if submitted to another column

I have three tables defined where always
column 3 is "query", varchar(255) null
column 4 is "tag", varchar(255) null
both columns are the same charset
I submit string $s to column 3 via $wpdb->insert which should do sanitization (but adding extra sanitization to col 3 and col 4 or not adding it does not change anything at all)
function abc($a=null,$tag=null) {
global $wpdb;
$data = array(
'timestamp' => time(),
'query' => sanitize_text_field($a),
'tag' => sanitize_text_field($tag)
);
$format = array('%s','%d');
$wpdb->insert(SS_STATS,$data,$format);
return $wpdb->insert_id;
}
in the template I tried:
abc($s,$s);
abc("$s","$s");
abc("plz save this","$s");
abc("plz save this","plz save this: $s");
In each and every case, column 3 in the db recods 0. In each and every case, column 4 records the correct value just as it is submitted.
Why?
I tried:
changing the name of the column (maybe query is protected)
adding extra sanitization
not adding any sanitization
changing data type to text
changing data type to blob
For every attempt I drop the db and let it recreate.
No change in any case.
How can I save the string in column 3?
The problem was in the format:
$format = array('%s','%d');
$wpdb->insert(SS_STATS,$data,$format);
Removing the formatting solved the issue.
$wpdb->insert(SS_STATS,$data);

Show a text depending on the value of a column MySQL

I would like to know, how can I build a query that shows me an extra column where instead of showing the true value of the original column it shows me the text that i want?
For example, The Column, in this case "inputOutput", save values ​​0 or 1, and I would like to show in a query that if the value is 0 I can see the text "Output" and if it is 1 show "Input" in all the rows.
what function or structure could you use?
This is just an example of the columns that I would like to show:
Select idInventory, date, "text that that replaces 0 or 1 from inputOtput column"
from inventory;
You can use a case expression for this:
select
idInventory,
date,
case inputOutput
when 0 then 'Output'
when 1 then 'Input'
else '???'
end status
from inventory;

Make unique ID using Laravel

I want to generate a unique id in Laravel.
EX: PO-12010001
PO = product,
12 = the month,
01 = the year,
0001 = ID of product.
I have tried googling and the answer is using UUID but could not understand.
Your ID will always be 4 digits at the end, so we can pluck those last four characters using substr(). When you increment that by one, it will lose its padding. So 0001+1=2. We therefor pad it back using str_pad() with a length of four.
$string = 'PO-12010001';
$id = substr($string, -4, 4);
$newID = $id+1;
$newID = str_pad($newID, 4, '0', STR_PAD_LEFT);
echo "PO-1201".$newID;
Live demo at https://3v4l.org/55RTL
Since it is not clear where the last 4 characters (ID of product) come from, there are 2 different outcomes based on their origin, I am assuming that "PO" is a constant in all your products:
1.If you're auto-generating the Product ID:
$id = "PO-".date('my') . substr(uniqid(), 9, 12);
date('my') will return a two-digits form of the current month and a two-digits form of the current year.
uniqid() returns a unique identifier based on the current time in microseconds, the identifier is usually a mix of letters and digits, and it is usually 13 characters long, so we use substr() to only return the last 4 characters of the string.
NOTE: we are using the last characters of uniqid() because they change every millisecond.
2.If you already have a Product ID:
$id = "PO-".date('my') . $product_id;
When like this situation first how you want to make your ID
Item Type
Month
Year
Product ID
Get product type in your controller
if Product = PO /
Service = SE
Create a New Date using PHP
$date2 = date('Y-m-d');
and get date substring with your requirement and get the last id of the product table and concat all the variable and use as Unique ID.
First, I dopn't know. So maybe it has a similar concept. But anyway, user defined+designed unique are most likely not unique.
My recommendation is to let the database create an unique id with the autoincrement feature. This is usually the only way to guarantee unique ideas in a multi tasking environment.
The, in an second step, you can create an human readable id and use it for displaying it at the suer interface. Such query can be something like:
update table set nice_id = concat("prefix-",main_id)
where main_id = $last_inserted_id
... or any other calculation based on counting the the number of same entries since beginning of month.
There are other solutions based on try to create an nice_id, insert it into the database, and if this fails, create the next one .. and loop until successful. But simple integers created by autoincrement are more performant on queries and for keys.
it's called Human code which can be unique identify beside an Id column in db table.
$idColumn = 1;
$dateCode = date('ym');
$newHumanCode = 'PO-'.$dateCode.substr('0000'.$idColumn, -4);
return $newHumanCode;
also you can use randome number instead of use $idColumn,
for example:
$idColumn = mt_rand();
You can use the Laravel ID generator.
First Install it:
composer require haruncpi/laravel-id-generator
Import the class in your controller.
use Haruncpi\LaravelIdGenerator\IdGenerator;
Now simply use it
$prefix = "PO-".date("my");
$id = IdGenerator::generate(['table' => 'your_table_name', 'length' => 11, 'prefix' =>$prefix]);
Output
PO-12010001
PO-12010002
PO-12010003
...

PostgreSQL Update Issue With Quotation('')

I'm using PostgreSQL & Codeigniter. There is a table called folio in the database. It has few columns containing remarks1, remarks2, remarks3 as well. Data for the all the other columns are inserted when the INSERT statement executes for the 1st time.
When I try to execute below UPDATE statement later for the below 3 columns, remarks1 column get updated correctly. But remarks2, remarks3 columns are updated with ''.
UPDATE "folio" SET "remarks1" = 'test remark', "remarks2" = '', "remarks3" = '' WHERE "id" = '51';
Given that remarks1, remarks2, remarks3 columns data type is character varying. I'm using Codeigniter active records. At a time all 3 columns could be updated else single column could be updated depending on the user input.
What could be the issue? How can I fix this? Why columns are updated with ''?
As requested the php array in CI would be below
$data = array(
'remark1' => $this->input->post('remark1'),
'remark2' => $this->input->post('remark1'),
'remark3' => $this->input->post('remark1')
);
Function which saves the data contains below two lines only
$this->db->where('id', $folio_id);
$this->db->update('folio', $data);
Those columns are updated with '' because you tell them to?
Let's take a closer look at the query
UPDATE "folio"
SET
"remarks1" = 'test remark',
"remarks2" = '',
"remarks3" = ''
WHERE
"id" = '51';
First you select the table folio for the update.
Then you tell it to update remarks1 through remarks3 with new values. For remarks2 and remarks3 you specify to set them to an empty string. And that's what's going to happen.
Last but not least, you tell it to only apply this update to rows where id equals 51.
So, in order to only update remarks1 you can simply remove the other columns from your update:
UPDATE "folio"
SET
"remarks1" = 'test remark'
WHERE
"id" = '51';
Update:
I'm by far not a CI expert, but from what I see, I'd change the $data array to only contain information for remark1:
$data = array(
'remark1' => $this->input->post('remark1')
);
And (from my understanding) it should only update this single column.

Categories