Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 30th, 2012, 12:10 PM
Registered User
Points: 39, Level: 1
Points: 39, Level: 1 Points: 39, Level: 1 Points: 39, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old August 30th, 2012, 12:46 PM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

If the string your using is the one above then you should not have != wrapped in back ticks, single or double quotes.
Reply With Quote
The Following User Says Thank You to UseLess For This Useful Post:
jobayer_34 (August 30th, 2012)
  #3 (permalink)  
Old August 30th, 2012, 09:03 PM
Registered User
Points: 39, Level: 1
Points: 39, Level: 1 Points: 39, Level: 1 Points: 39, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old September 11th, 2012, 08:44 AM
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
Default 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 !=
Reply With Quote
The Following User Says Thank You to plavalle For This Useful Post:
jobayer_34 (September 11th, 2012)
  #5 (permalink)  
Old September 11th, 2012, 11:43 AM
Registered User
Points: 39, Level: 1
Points: 39, Level: 1 Points: 39, Level: 1 Points: 39, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old September 11th, 2012, 12:53 PM
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by jobayer_34 View Post
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
Reply With Quote
The Following User Says Thank You to plavalle For This Useful Post:
jobayer_34 (September 11th, 2012)
  #7 (permalink)  
Old September 12th, 2012, 12:02 AM
Registered User
Points: 39, Level: 1
Points: 39, Level: 1 Points: 39, Level: 1 Points: 39, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old September 12th, 2012, 05:42 AM
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
Default Where's SELECT

I noticed you had the select statement commented out. Did you un-comment that and try again?
Reply With Quote
The Following User Says Thank You to plavalle For This Useful Post:
jobayer_34 (September 12th, 2012)
  #9 (permalink)  
Old September 12th, 2012, 09:57 AM
Registered User
Points: 39, Level: 1
Points: 39, Level: 1 Points: 39, Level: 1 Points: 39, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy previous field record if next field is null ecampos Access VBA 6 June 23rd, 2006 01:55 PM
CDO.Message form field crmpicco Classic ASP Basics 0 March 15th, 2005 01:08 PM
Active Search Field Tachyophan Access VBA 1 January 30th, 2005 01:00 PM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 11:30 PM



All times are GMT -4. The time now is 01:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.