Jump to content


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

#bugs groceryenterprise $crud-where

  • Please log in to reply
6 replies to this topic

#1 the_coders

the_coders

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 21 July 2017 - 04: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

Attached Files



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 21 July 2017 - 05: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 :)



#3 the_coders

the_coders

    Newbie

  • Members
  • Pip
  • 6 posts

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 :)



#4 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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 :)



#5 the_coders

the_coders

    Newbie

  • Members
  • Pip
  • 6 posts

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



#6 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 23 August 2017 - 06: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

 


Posted Image

#7 tomcat

tomcat

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 02 December 2019 - 03: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







Also tagged with one or more of these keywords: #bugs, groceryenterprise, $crud-where

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users