⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

now showing data using if using variabel $crud->where()



the_coders

the_coders
  • profile picture
  • Member

Posted 21 July 2017 - 16:58 PM

Hi Grocery Team

 

first i want to say thank you , because grocery i can  make crud more faster, and btw Im just purchase your grocerycrud enterprise, and when im using  i got an weired things when i using  $crud->where() , you can see the attchment for the detail,

 

the point is when i want to find a data from db related to the id using variabel it doenst work ( there is no output)

 

//================================================

 

$get_cat_id  = $this->input->post('category_id'); // category id
 
$crud->setTable('layer2_inv_correlation');
$crud->setSubject('Investor Correlation', 'Investor Correlation');
 
$crud->where(['layer2_inv_correlation.fk_layer2_categoryid' => $get_cat_id  ]); // if using variabel there is no result
 

//================================================

 

but if doesnt use variabel,  is worked  (output show the data)

 

 
$crud->setTable('layer2_inv_correlation');
$crud->setSubject('Investor Correlation', 'Investor Correlation');
$crud->where(['layer2_inv_correlation.fk_layer2_categoryid' => 3  ]); // if not using variabel they show the data

 

//=================================================

 

the question is how i can use variabel to find  a data using $crud->where() in grocery enterprise ?

 

 

thank you

Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 21 July 2017 - 17:51 PM

Well my friend,

 

this is sure to happen. Why ... try and understand the flow of the library. When u started the very 1st time on the controller / method - u called it with the post data. Fine .. that time the data did come along with post. That time - it showed up the listing form 

Next time - to fetch the data - it makes an ajax call again. Now this time there is no category id in post .. the value becomes blank - so now when u call .. it is going to fail.

 

To achieve what you are looking for, a simpler option for you will be ..store the category id from from the post (if available in post) .. into the session. Then when u wana use the same, retrieve the same from session and go ahead and use it.

Now - what you get is filtered data.

 

Happy GCing :)


the_coders

the_coders
  • profile picture
  • Member

Posted 22 July 2017 - 02:37 AM

thank you for your advice, i already try using session but the result is still same, just for refrence my case / flow is just like below 

 

 

         (step 1)                                      (step 2)                                                           (step 3)

user choose category => web direct to other page => user can manage the page related to category that the user choosed ( in same category)

 

 

and the code below using session that you tell me :

 

//===============================================

 

// receive id from step one and get list of data from id step 1

 

$package = array(
'id_category' => $this->input->post('select_category')  // id from (step 1)
);
 
$crud->setTable('layer2_inv_correlation');
$crud->setSubject('Investor Correlation', 'Investor Correlation');
 
$crud->where(['layer2_inv_correlation.fk_layer2_categoryid' => $this->session->userdata('id_category') ]); 
 
$crud->setRelation('fk_layer2_categoryid','layer2_inv_question','inv_question');
$crud->setRelation('fk_layer2_subcategoryid','layer2_inv_answer','answer_name');

.

.

.

---

 

//==============================================

 

and the result still same no data on the list  , even when i open the page in the first time, there is no data show up

 

result expectations

 

after i choose the category (step 1) => i can  get list of data related to the  category that i choosed in ( step 1)

 

is there another way to fix that ?

 

thank you for your help :)


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 22 July 2017 - 02:50 AM

Well, i just wana make sure.. that u storing the same in session only if the category_id is present. 

That's point 1.

 

Second, rather then storing and retrieving the value in and out of session same time, i will recommend - set a field  - $id_category

if passed from post - u use it..

if not passed from post - then retrieve it from session.

 

There are times - that when you set it in session and try use it in function very much nearby .. it fails. I know this dont sound logical but i have faced it in past with PHP .. thats the reason i prefer going on with using the above recommended method then the one you following.

 

Hope this pattern helps u solve your problem.

 

Happy GCing :)


the_coders

the_coders
  • profile picture
  • Member

Posted 22 July 2017 - 04:39 AM

im really sorry im confused for that solution im tried  but still not working :( can you give me a simple  code example please i need help because im stuck almost 2 days

 

Thank you for your help


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 23 August 2017 - 18:29 PM

First of all thanks @Amit Shah for your suggested solution. It is very good solution and it will work :-)

 

On the other hand, I have a simpler solution ;-)

@the_coders I think everything will just work if instead of using POST, to use GET to send the category_id.

 

So for example if you have: your page that will look like that:

 

customers?category_id=12

then Grocery CRUD Enterprise is clever enough to understand it and have all the URLs with this get parameter at the end. Example:


customers?category_id=12&action=edit-form&pk_value=103

So for example in your case you will have:

$category_id = $_GET['category_id'];

Let me know if that worked for you ;-)

 

Regards

Johnny

 


tomcat

tomcat
  • profile picture
  • Member

Posted 02 December 2019 - 15:56 PM

Hello Johnny,

 

we use Grocery CRUD Enterprise and we had a simmilar issue with the $_POST / $_GET method.

After your suggestion we have passed our data using the $_GET method. This works perfect, but it has one disadvantage. All the data are shown in the link. (...project.php?ProjectNo_ID=4010...)

We have also tried to use $_POST and $_SESSION, but these two methods do not work in callbackAddForm or callbackAddField. Variables are in this case empty.

 

Working solution:

$crud->callbackAddForm(function ($data) {
    $data['ProjectNo'] = $_GET['ProjectNo_ID'];
    return $data;
    });

 

Prefered solution (but unfortunately not working):

$crud->callbackAddForm(function ($data) {
    $data['ProjectNo'] = $_POST['ProjectNo_ID'];
    return $data;
    });

 

Is there any way, how to pass the data from a form into AddForm without to show them in the link?

 

Thank you

 

Best regards

Tomas