I'm attempting to run the following SQL statement, but I can't quite get it right.
This is what works on the iSeries within STRSQL, and also works within my PHP program. But I don't see the (mbmrxl * mbndtr) result as I do on the iSeries.
That column is blank.
SELECT SURNME, ODLBNM, ODOBNM, MBMXRL, MBNRCD, MBNDTR, (mbmxrl * mbndtr), objrnk
FROM mytable WHERE surnme = 'STP_ROLL' ORDER BY (mbmxrl * mbndtr) desc
I need to perform this calculation and place it in a new field called TOTRANK:
MBMRXL * MBNDTR
This is the php query I'm trying:
$query = "SELECT SURNME, ODLBNM, ODOBNM, MBMXRL, MBNRCD, MBNDTR, TOTRANK, objrnk FROM (select mbmrxl * mbndtr as TOTRANK, from mytable)
WHERE surnme = 'STP_ROLL' ORDER BY TOTRANK desc";
When run the above code, I get this message:
SQL statement failed Token . was not valid. Valid tokens: , FROM INTO.
SQLCODE=-104
How do I debug this?
SELECT SURNME, ODLBNM, ODOBNM, MBMXRL, MBNRCD, MBNDTR, objrnk
, mbmrxl * mbndtr as TOTRANK
FROM mytable
WHERE surnme = 'STP_ROLL'
ORDER BY mbmrxl * mbndtr desc
Your SQL select statement should be changed to the above.
Related
I want try to execute my query in PHP 7
$sql ="SELECT * from order_details where order_id = '".$order_number."'
AND product_id=".$pro['pruduct_id'].";
$select = mysqli_query($connection,trim($sql)) or die("Query(Get Shipments) is not executed.");
I got following type of string at the start of SQL query and my sql query is not execute due to added that kind of string. I have also used trim() and string replace function but SQL query is not execute.
That is becuase you have syntax error there
try this :
$sql ="SELECT * from order_details where order_id = '".$order_number."' AND product_id='".$pro['pruduct_id']."'";
$select = mysqli_query($connection, trim($sql)) or die("Query(Get Shipments) is not executed.");
I want to use multiple ANDs in WHERE clause but unable to execute the query. The filtering is as:
Select * from startstopdata WHERE date(start_work) BETWEEN '".$date1."' and '".$date2."'
The date in MySQL is DATETIME type and I want to apply search only on date
Select * from startstopdata WHERE name='".$name."
Select * from startstopdata WHERE start_mac!=stop_mac
Select * from startstopdata WHERE start_location!=stop_location
I want to combine all these queries using AND but somehow I'm unable to fetch the desired result.
Thanks in advance! :)
if I understand right , you just have to make your query like this
Select * from startstopdata WHERE (date(start_work) BETWEEN '".$date1."' and '".$date2."') and name='".$name."' and start_mac!=stop_mac and start_location!=stop_location
EDIT:
try this:
Select * from startstopdata WHERE (date(start_work) BETWEEN '".$date1."' and '".$date2."') and name='".$name."'
Select * from ".$database.".`startstopdata` where Emp_name='".$name."' AND (date(start_work) BETWEEN '".$fromDate."' AND '".$toDate."') AND (Location!= Stop_location AND MacAddress != Stop_mac);
My requirement is when user will type letter inside text box at front end it will auto search from database and give the result accordingly. I have written some query but it gave me the following error.
Error: #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 '%P%) ORDER BY member_id DESC LIMIT 0, 30' at line 1
My code is given below.
$searchKey=$_GET['searchKey'];
$keyword = '%'.$searchKey.'%';
$sql =mysqli_query($connect,"SELECT * FROM db_restaurant_basic WHERE rest_name LIKE (:keyword) ORDER BY member_id DESC ");
My first search keyword was p.
You want
$sql =mysqli_query($connect,"SELECT * FROM db_restaurant_basic WHERE rest_name LIKE '$keyword' ORDER BY member_id DESC ");
or also you could do
$sql =mysqli_query($connect,"SELECT * FROM db_restaurant_basic WHERE rest_name LIKE '" . $keyword . "' ORDER BY member_id DESC ");
(:keyword) is not going to pull in the variable for your keyword into the SQL syntax and also (:keyword) is not valid mysql
Another approach,
$sql =mysqli_query($connect,"SELECT * FROM db_restaurant_basic WHERE rest_name LIKE '".$keyword."' ORDER BY member_id DESC ");
It's better to use single quotes inside double quotes in relevant places when executing SQL queries.Sometimes you'll need to put single quotes for table name as well.Like this,
$sql =mysqli_query($connect,"SELECT * FROM `db_restaurant_basic` WHERE rest_name LIKE '".$keyword."' ORDER BY member_id DESC ");
i have following sql query, everything works fine but when i put "and posted_date<>$datetime" its not retrieving data as per given command.
$datetime="0000-00-00";
$data = mysql_query("SELECT * FROM product_table where category_id=$cat1 or
pid=$par or gpid=$gpar and posted_date<>$datetime
ORDER BY autoid desc limit $no2,$cacount")
or die(mysql_error());
please check is that line is ok maybe i am doing mistake somewhere where category_id=$cat1 or pid=$par or gpid=$gpar and posted_date<>$datetime
maybe i need two where one for or and another for and...
Thanks
Try to group your condition and use DATE()
SELECT *
FROM product_table
where (category_id=$cat1 or
pid=$par or gpid=$gpar) AND DATE(posted_date) <> DATE($datetime)
ORDER BY autoid desc
LIMIT $no2, $cacount
I can't get a variable to work in SQL statement. I can get it to work when I replace (username = $user) with (ID = 11) which is another column from database and a specific row (11), but I want to include a specific row matching $user from column 'username', along with other random results with a limit of $sn.
When using var_dump($user) I know that the variable has a value, but can't see why it doesn't work in SQL statement.
$photo=mysql_query("SELECT A. * FROM (
SELECT DISTINCT * FROM profile_images
WHERE approved='N'
ORDER BY (username = $user) DESC, RAND()
LIMIT $sn)
as A ORDER BY RAND()");
Getting error message: 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 '#googlemail.com) DESC, RAND() LIMIT 9) as A ORDER BY RAND()' at line 4
Any help appreciated.
Assuming $sn holds integer value and don't require escaping,
$photo=mysql_query("SELECT A. * FROM (
SELECT DISTINCT * FROM profile_images
WHERE approved='N'
ORDER BY (username = '".mysql_real_escape_string($user)."') DESC, RAND()
LIMIT $sn)
as A ORDER BY RAND()");
In general, consider using PDO and bind parameters.