 |
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
 | This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 30th, 2012, 11:10 AM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Getting error message while trying to checking field using operators in active field
Dear Sir/ Madam,
I am getting error message while trying to checking field using operators in active field (page-83). I have tried in different way but failed,
shows "Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`!=` '6' ORDER BY `category_id` desc LIMIT 100' at line 4
SELECT `id`, `name`, `thumbnail`, `category_id` FROM (`products`) WHERE `status` = 'active' AND `id` `!=` '6' ORDER BY `category_id` desc LIMIT 100".
Can anyone help me ?
Thanks in advance
Jobayer
|
|

August 30th, 2012, 11:46 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
If the string your using is the one above then you should not have != wrapped in back ticks, single or double quotes.
|
|
The Following User Says Thank You to UseLess For This Useful Post:
|
|
|

August 30th, 2012, 08:03 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Dear Sir,
Thanks for your message. I have used db->where('id !=', '6') then it produces this query. Can you please suggest me how can I use operators for checking (I want to check where id!=6)?
Thanks in advance
Jobayer
|
|

September 11th, 2012, 07:44 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Please post your code
Even though you are pointing to page 83, please post the code you have used, and the version of MySQL you are using.
There are several ways to debug this.
You can also try $this->db->query(PUT QUERY HERE) and see if that returns what is expected. If that works, then go back to $this->db->where and use <> instead of !=
|
|
The Following User Says Thank You to plavalle For This Useful Post:
|
|
|

September 11th, 2012, 10:43 AM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Thanks for your feedback. Actually when I have found error for the first time, I have managed it using direct sql query.
I want to use operator for it and failed in every way. I have used <> too, but I have found same error message. I am using MySQL version 5.0.45. Can you please specify the MySQL Version ?
Thanks
Jobayer
|
|

September 11th, 2012, 11:53 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Quote:
Originally Posted by jobayer_34
Thanks for your feedback. Actually when I have found error for the first time, I have managed it using direct sql query.
I want to use operator for it and failed in every way. I have used <> too, but I have found same error message. I am using MySQL version 5.0.45. Can you please specify the MySQL Version ?
Thanks
Jobayer
|
Please post your actual code, not just the single line, and let me know what else you have tried. My version of MySQL is 5.5.16 but that should not be an issue.
Did you change any settings in the site config, sql or php?
This is my final code:
Code:
function getRandomProducts($limit,$skip) {
$data = array();
$temp = array();
if ($limit == 0) {
$limit = 3;
}
$this->db->select("id,name,thumbnail,category_id");
$this->db->where('id !=', id_clean($skip));
$this->db->where('status','active');
$this->db->order_by('category_id', 'asc');
$this->db->limit(100);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0) {
foreach ($Q->result_array() as $row) {
$temp[$row['category_id']] = array(
"id" => $row['id'],
"name" => $row['name'],
"thumbnail" => $row['thumbnail']
);
}
}
shuffle($temp);
if (count($temp)) {
for ($i=1;$i<=$limit;$i++) {
$data[] = array_shift($temp);
}
}
$Q->free_result();
return $data;
}/* end getRandomProducts */
Where you are using this:
Code:
db->where('id !=', '6')
Did you try this:
Code:
db->where('id !=', 6)
Notice there are no quotes around the number 6
Let me know what happens.
Paul
|
|
The Following User Says Thank You to plavalle For This Useful Post:
|
|
|

September 11th, 2012, 11:02 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Dear Sir,
I have used this below code:
function getRandomProducts($limit,$skip){
$data = array();
$temp = array();
if($limit == 0){
//echo $limit;
$limit=3;
}
//$sql = "select id,name,thumbnail,category_id from products where status='active' and id <> '$skip' order by category_id asc limit 100";
//$Q = $this->db->query($sql);
/*$this->db->select("id,name,thumbnail,category_id");
$array = array('id <>' => $skip, 'status' => 'active');
$this->db->where($array); */
$this->db->where('status', 'active');
$this->db->where('id !=', $skip);
$this->db->order_by("category_id", "desc");
$this->db->limit(100);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0){
foreach($Q->result_array() as $row){
$temp[$row['category_id']] = array(
"id" => $row['id'],
"name" => $row['name'],
"thumbnail" => $row['thumbnail']
);
}
}
and it produces this message:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`!=` '7' ORDER BY `category_id` desc LIMIT 100' at line 4
SELECT * FROM (`products`) WHERE `status` = 'active' AND `id` `!=` '7' ORDER BY `category_id` desc LIMIT 100
Filename: C:\wamp\www\CodeIgniter_2.1.1\system\database\DB_d river.php
Line Number: 330
I have also tried it using db->where('id !=', 6), but found error message. Please let me know what's wrong with it.
Thanks
Jobayer
|
|

September 12th, 2012, 04:42 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Where's SELECT
I noticed you had the select statement commented out. Did you un-comment that and try again?
|
|
The Following User Says Thank You to plavalle For This Useful Post:
|
|
|

September 12th, 2012, 08:57 AM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Yes, I have mentioned it in my previous reply. I have managed my program to run properly using the commented code, it's nothing but a straight sql query.
I want to run it using operators and using codeignitor's convention like the above code, if there is any solution. Otherwise, I will use straight sql query like above commented code.
Let me know your opinion.
Thanks
Jobayer
|
|
 |