I am trying to execute this mySQL query in PHP.
$sql = "SELECT * FROM Property
WHERE CONCAT(name, '',
contact_number , '',
hostel_address,'',
renter_name,'',
other_details,'',
date_posted,'') LIKE '%".$var."'
ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
An I am getting following error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y') ASC' at line 1
Any help here :(
may try this:
$sql = "SELECT * FROM Property WHERE CONCAT(name, '',contact_number , '', hostel_address,'',renter_name,'',other_details,'',date_posted,'') LIKE '%".$var."' ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
Note that there should be an ending single quote before ORDER BY
Related
How Do I Concatenate PHP variable in SQL Query Then Concatenate Additional SQL Queries
$query = 'SELECT * FROM news_posts WHERE status ="approved" AND user_id='.$user_id.'ORDER BY news_id DESC';
I got an error:
check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BY news_id DESC' at line 132
$query = 'SELECT * FROM news_posts WHERE status ="approved" AND
user_id='.$user_id.' ORDER BY news_id DESC';
try add a space before "ORDER"
Trying to write an MySQL Query to search on users based on two columns :
first_name
surname
I'd like to Concatenate first_name and surname as name and then write a search query based on that.
I've currently written some PHP code, But I keep getting the error :
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '%?%' at line
1 (SQL: select users.* from users where CONCAT(first_name, ' ',
surname) LIKE %Stu%)
My current PHP code is as follows :
// Search Based on Q..
$q = $request->input('q');
$results = User::select('users.*')->WhereRaw("CONCAT(`first_name`, ' ', `surname`) LIKE %?%", [$q])->get();
I suspect I'm just getting the syntax wrong, But any help would be appreciated.
Thank You!
Move % to parameter:
$results = User::select('users.*')
->WhereRaw("CONCAT(`first_name`, ' ', `surname`) LIKE ?", ['%' . $q . '%'])
->get();
two errors in your query first as fullname not mention and second like operator.. i have fix these errors
$q = $request->input('q');
$results = User::select('users.*')
->WhereRaw("CONCAT(`first_name`, ' ', `surname`) as fullname
LIKE ?", ['%' . $q . '%'])->get();
SELECT `id`, `name_person`, `person_content`, `datetime`
FROM (`achievers_unverified`)
WHERE ` name_person LIKE '%ved%'
OR ` person_content LIKE '%ved%' LIMIT 10
This is the sql query i am trying to use where ved is the search term.
i am gettin a 1064 error.
the codeigniter code generating it is.
$this->db->select($select)
->from($table)
->like($str[1], $query, 'both')
->or_like($str[2], $query, 'both')
->limit($offset+10, $offset);
this is the error :
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 'person_content LIKE '%ved%' LIMIT 10' at line 3.
$str = explode(",", $select);
where $select = id, name_person, person_content, datetime
found the solution use trim($str[0]) and trim($str[1]) the sapce was creating the problem.
I'm having a problem regarding these 3 queries:
select count(*) as rec_count from test_history inner join
test_detail on test_history.history_id = test_detail.test_history_id
where test_history.history_id in ({$_SESSION['history_ids']})
and test_history.user_id = $userID
and
select count(*) as correct_answers from test_history inner join test_detail
on test_history.history_id = test_detail.test_history_id
where test_history.history_id in ({$_SESSION['history_ids']}) and
test_history.user_id = $userID and is_correct = 1
and this one
select * from test_topics inner join
test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
where test_topics_link.test_id in ({$_SESSION['ids_tests']}) and percentage > 0
I'm always getting this error:
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 ') and
test_history.user_id = 82' at line 3
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 ') and
test_history.user_id = 82 and is_correct = 1' at line 2
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 ')' at line 1
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 ') and percentage > 0' at
line 3
Since $_SESSION['ids_tests'], I suppose, is an array, you should write implode(',',$_SESSION['ids_test']), e.g. in PHP it should be:
$query = "select * from test_topics inner join
test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
where test_topics_link.test_id in (".
implode(',',$_SESSION['ids_tests']).") and percentage > 0";
I have this query, running from a PHP page:
$feed_sql = "SELECT id, title, description, rssDate
FROM feed
WHERE MATCH (title) AGAINST ('" . $rows['suburb'] . "')
AND NOT EXISTS(SELECT feed_id, recipient_id, issent
FROM tracking_table
WHERE tracking_table.feed_id = $feed_id
AND tracking_table.recipient_id = $recipient_id
AND tracking_table.issent = 'Y')
GROUP BY pubDate
ORDER BY pubDate DESC
LIMIT 1";
However, it returns the following errors upon running it:
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 'AND tracking_table.recipient_id =
AND tracki' at line 7
Line 7 being this:
AND tracking_table.recipient_id = $recipient_id
Some server information:
PHP Version 5.2.6-1+lenny9
MySQL Version 5.0.51a
Thanks :-)
As you can see here:
'AND tracking_table.recipient_id = AND tracki'
// value missing here --^
the value of $recipient_id seems to be empty and generates invalid syntax.
Perhaps $recipient_id is an empty string. Please check it