CodeIgniter Forums
Database Error!! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Database Error!! (/thread-28203.html)

Pages: 1 2


Database Error!! - El Forum - 03-04-2010

[eluser]Shaileen[/eluser]
I am getting the following error..


A Database Error Occurred

Error Number:

ERROR: syntax error at or near "t1_eu" LINE 5: AND "t1_eu"."seqid" = t1_admin.refid ^

SELECT "mydsl_auth"."username", "t1_admin"."refid", "t1_admin"."admin_date_sent", "t1_eu"."eu_company", "t1_eu"."eu_contact", "t1_admin"."admin_order_sent", "t1_admin"."admin_deleted", "t1_admin"."admin_cancelled", "t1_admin"."admin_active", "t1_admin"."quote_id", "t1_order"."bandwidth_id" FROM "mydsl_auth", "t1_admin", "t1_eu" WHERE "t1_eu"."seqid" like '%searchText%' AND " IS NULL AND "t1_eu"."seqid" = t1_admin.refid AND "mydsl_auth"."user_id" = t1_admin.salesperson AND "t1_admin"."admin_order_sent" = 1 AND "t1_admin"."admin_active" != 0 AND "t1_order"."refid" = t1_admin.refid ORDER BY "t1_admin"."admin_active" desc



and heres my query..Can you please help me fix it?

function query3($user_id, $inyc_limit, $field, $order, $searchField, $searchText, $groupSearch )
{

$this->db->select(array('mydsl_auth.username', 't1_admin.refid', 't1_admin.admin_date_sent', 't1_eu.eu_company', 't1_eu.eu_contact', 't1_admin.admin_order_sent', 't1_admin.admin_deleted', 't1_admin.admin_cancelled', 't1_admin.admin_active', 't1_admin.quote_id', 't1_order.bandwidth_id'));
$this->db->from(array('mydsl_auth', 't1_admin', 't1_eu'));
$this->db->where("$searchField like", "%searchText%");
$this->db->where("$groupSearch");
$this->db->where('t1_eu.seqid = t1_admin.refid');
$this->db->where('mydsl_auth.user_id = t1_admin.salesperson');
$this->db->where('t1_admin.admin_order_sent', 1);
$this->db->where('t1_admin.admin_active !=', 0);
$this->db->where('t1_order.refid = t1_admin.refid');

if (isset($inyc_limit))
{
$this->db->where("$inyc_limit");
}
$this->db->order_by($field, $order);
$query = $this->db->get();
return $query->result();
}


Database Error!! - El Forum - 03-04-2010

[eluser]danmontgomery[/eluser]
Quote:AND ” IS NULL

Code:
$this->db->where(”$groupSearch”);



Database Error!! - El Forum - 03-04-2010

[eluser]Shaileen[/eluser]
yep..that is what i wrote in my query...


Database Error!! - El Forum - 03-04-2010

[eluser]danmontgomery[/eluser]
... I didn't post it to point out that you had written it, I posted it because that's what the error is


Database Error!! - El Forum - 03-04-2010

[eluser]Shaileen[/eluser]
i knw..so what could be the possible solution!!


Database Error!! - El Forum - 03-04-2010

[eluser]danmontgomery[/eluser]
Pick any of the following.

Code:
$this->db->where($groupSearch, NULL);
$this->db->where($groupSearch, 6);
$this->db->where($groupSearch, 'november');
$this->db->where($groupSearch . '> t1_admin.admin_order_sent);
$this->db->where($groupSearch, $searchField);
$this->db->where($groupSearch, FALSE);
$this->db->where($groupSearch);

An actual answer would of course depend on what the value of $groupSearch is, and what it is you're trying to accomplish... Neither of which you've provided Tongue


Database Error!! - El Forum - 03-04-2010

[eluser]Shaileen[/eluser]
there are the values for groupSearch in my controller..

case 1: $groupSearch = " AND t1_admin.admin_order_sent = 0";
break;
Case 2: $groupSearch = " AND t1_admin.admin_order_sent = 1 AND t1_admin.admin_active = 0";
break;
Case 3: $groupSearch = " AND t1_admin.admin_active = 1 AND t1_admin.admin_order_sent = 1";
break;
Case 4: $groupSearch = "";
break;


Database Error!! - El Forum - 03-04-2010

[eluser]danmontgomery[/eluser]
So you're passing an empty to string to where(), that's your problem. You need to check for a value before you include it in the active record chain.


Database Error!! - El Forum - 03-05-2010

[eluser]Shaileen[/eluser]
ok now i m geting a different error!!


A Database Error Occurred

Error Number:

ERROR: column "4" does not exist

SELECT "mydsl_auth"."username", "t1_admin"."refid", "t1_admin"."admin_date_sent", "t1_eu"."eu_company", "t1_eu"."eu_contact", "t1_admin"."admin_order_sent", "t1_admin"."admin_deleted", "t1_admin"."admin_cancelled", "t1_admin"."admin_active", "t1_admin"."quote_id", "t1_order"."bandwidth_id" FROM "mydsl_auth", "t1_admin", "t1_eu" WHERE "t1_eu"."eu_address" like '%searchText%' AND "4" IS NULL AND "t1_eu"."seqid" = t1_admin.refid AND "mydsl_auth"."user_id" = t1_admin.salesperson AND "t1_admin"."admin_order_sent" = 1 AND "t1_admin"."admin_active" != 0 AND "t1_order"."refid" = t1_admin.refid ORDER BY "t1_admin"."admin_active" desc

and this is my controller!!

switch($searchGroup)
{
case 'unsent': $searchGroup = 1;
break;
Case 'sent': $searchGroup= 2;
break;
Case 'active': $searchGroup = 3;
break;
Case 'all': $searchGroup = 4;
break;
}


switch($searchGroup)
{
case 1: $groupSearch = " t1_admin.admin_order_sent = 0";
break;
Case 2: $groupSearch = " t1_admin.admin_order_sent = 1 AND t1_admin.admin_active = 0";
break;
Case 3: $groupSearch = " t1_admin.admin_active = 1 AND t1_admin.admin_order_sent = 1";
break;
Case 4: $groupSearch = "";
break;
}


Database Error!! - El Forum - 03-05-2010

[eluser]danmontgomery[/eluser]
Code:
AND “4” IS NULL

Have you read the userguide? You don't really seem to be getting any closer, just making guesses.

If you're only passing one argument to where(), it has to be a valid MySQL argument, ie:

Code:
$this->db->where("some_field = 3");

Or an array, structured like $field => $value:

Code:
$this->db->where( array( "some_field" => 3 ) );

Otherwise, you have to pass it at least two parameters, with a field as the first and the value as the second:

Code:
$this->db->where('some_field', 3);

From the looks of it, you're just passing it "4" now

Code:
$this->db->where(4);

Or, it I'm guessing it looks like:

Code:
$this->db->where($searchGroup, $groupSearch);