Custom mysql coding to get data

QuestionsCustom mysql coding to get data
Hafiz asked 6 years ago

Hello Abu,

Is there any way to do something like this using phpgrid?

Reference : https://imgur.com/a/IcxHn7m

The 2nd column is generated by subtraction of 2 mysql commands and the 4th column is generated by subtraction of 2nd and 3rd column..

Thanks in advance.

4 Answers
Abu Ghufran Staff answered 6 years ago

You can perform such calculation in SQL query of select_command and map them as grid column.

e.g.

$g->select_command = “SELECT col1, (colx-coly) as col2, col3, col3-(colx-coly) as col4 FROM table”;

As they are calculated fields and not exist in table, add, edit on col2, col4 will not be doable.

Sorting and Searching is possible by dbname property. For e.g col2
$col[“name”] = “col2”;
$col[“dbname”] = “(colx-coly)”;

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Hafiz answered 6 years ago

Its not like that,

What i’m trying to do is, as i said, the 2nd column is subtraction of 2 mysql command, they also from separate table. The command is something like this

$sqlcom = mysqli_query($conn,”SELECT sum(kg) as kg FROM table1 WHERE size='”.$i.”‘”); //$i is loop
$fetch = mysqli_fetch_assoc($sqlcom);
$kg= $fetch[‘kg’];

$sqlcom2 = mysqli_query($conn,”SELECT sum(kg) as kg FROM table2 WHERE size='”.$i.”‘”); //$i is loop
$fetch2 = mysqli_fetch_assoc($sqlcom2);
$kg2= $fetch2[‘kg’];

$kgs = $kg-$kg2;
echo ‘<td>’.$kgs.'</td>’;

then the 3rd column also from a different table (table3)

So it is like i’m collecting data from 4 separate tables with only using parameter from the loop.

Is it possible?

Thanks again.

Abu Ghufran Staff answered 6 years ago

If you want to have a read only view, then you can populate an 2d array (see link) with your custom business logic and pass to grid input.

demo: http://phpgrid.org/demo/demos/loading/load-array.php

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Hafiz answered 6 years ago

Okay,

Thanks so much for helping.

Your Answer

11 + 12 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?