Jump to content

Want to sql my own table in a callback function - how?

sql database own table callback query own table

  • Please log in to reply
2 replies to this topic

#1 Hoergold2



  • Members
  • Pip
  • 3 posts
  • LocationBerlin

Posted 19 September 2012 - 03:05 PM

Hi there,

I found this CRUD tool it is awsome, great, superb - what everyone waited for some years and someone finally did it! Thanky!

As I am quite acquainted with PHP but totally new to Codeigniter (that is needed by GroceryCRUD I do not get the idea how I can query the databse (using Codigniter-Helpers in a Callback function. What I want to do is to check a (German) postal code that is typed in in a form and lookup the state where it is located. The needed data sits in an own table.

What I tried:


and then:

   function plz_code($post_array)
    $plz = $post_array['plz'];	 // $plz = $this->db->escape_str($post_array['plz']);
    $ort = $post_array['ort'];	  // $ort = $this->db->escape_str($post_array[ort]);
    $query = $this->db->query("SELECT plz, ort, land from orte WHERE PLZ = $plz and ort = $ort ");
    if (count($query->row_array() > 0 )) {
	    $result = $query->row_array();
		 $plz_code = $result['Land'];
    } else {
	 $plz_code = 'XXX';
    $post_array['b_land'] = $plz_code;
    return $post_array;

I hope - though it is more a Codeigniter problem (that I am totally new with) - you might help with some lines? I would appreciate it very much!

Thanks in advance,

#2 victor


    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 21 September 2012 - 10:06 AM

function plz_code($post_array)
	 $search_criteria = array('PLZ' => $post_array['plz'],'ort'=>$post_array['ort']);
	 $result = $this->db->get_where('orte', $search_criteria)->row_array();
     $post_array['b_land'] = $result['Land']?$result['Land']:'XXX';
	 return $post_array;

Edited by victor, 21 September 2012 - 10:10 AM.

#3 José Sánchez Córdoba

José Sánchez Córdoba


  • Members
  • Pip
  • 4 posts

Posted 21 September 2012 - 10:21 AM

For good code. The functions for db insert in MODEL best that in CONTROLLER. Sorry my english. Good day.

Also tagged with one or more of these keywords: sql, database, own table, callback, query own table

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users