Edit php string - php

I have a string that makes a function from my order status. I wan´t to have it to trigger with 2 order status´
Is that posible?
$query = "SELECT * FROM #__redshop_orders where order_payment_status ='Paid' and order_status = 'RD2'";
So insted of just trigger with status RD2 it should trigger with RD1+RD2
Plus - I wan´t to remove the order_payment_status function, so it only triggers for order status.
How will the string look like after editting?
Thank you.

It would be something like this:
$query = "SELECT * FROM #__redshop_orders WHERE order_status = 'RD1' OR order_status = 'RD2'";
You should try to learn MySQL, a simple google search would give you plenty of example and tutorials.
EDIT:
I made some tests since I posted my answer, and the benchmarks show that a much faster solution would be:
$query = "SELECT * FROM #__redshop_orders WHERE order_status IN ('RD1', 'RD2')";

$query = "SELECT * FROM #__redshop_orders WHERE order_status IN ('RD1', 'RD2')";

$query = "SELECT * FROM #__redshop_orders where order_status IN('RD1','RD2')";
//You want this

Related

SELECT query inside PHP class

I am trying to run a simple SELECT query inside of a PHP class, using the GET variable.
$this->Token = $_GET['Token'] ?? null;
function getRows(){
$query = $this->db->query("SELECT * FROM store_product_images WHERE token = ".$this->Token." ORDER BY display_order ASC");
When I run this, nothing shows, if I remove the WHERE it works fine
you missed the quote
$query = $this->db->query("SELECT * FROM store_product_images WHERE `token`= '".$this->Token."' ORDER BY display_order ASC");

PHP Mysql refusing to work with integers

OK so I am having trouble figuring out how to retrieve data from mysql using php where i have a variable as an integer.
in database time is (int)11
in phpmyadmin my query is and i get the correct results
SELECT * FROM `transactions` WHERE (`sender` = "f3a8ce96-bfb9-410a-81fb-9deffb7305b2" OR `receiver` = "f3a8ce96-bfb9-410a-81fb-9deffb7305b2") AND `time` >= 1437249470
in php i have
$past = "1437249470";
$user = "f3a8ce96-bfb9-410a-81fb-9deffb7305b2";
$sql = "SELECT * FROM transactions WHERE (sender = '".$user."' OR receiver = '".$user."') AND FROM_UNIXTIME(time) >= $past LIMIT 10";
in php it gives me random and not relevant results
How do i get this to work correctly in php like it does in phpmyyadmin?
example output
phpymadmin:
Quill Littlefeather Josh Piper $275 07/24/15 Object Buy 7/24/2015 7:57:50 AM
php:
Quill Littlefeather Josh Piper $275 04/16/15 Object Buy 4/16/2015 3:41:12 AM
Makes no sence the results should be the same in php as it would be in phpmyadmin.
and yes i know this is not pdo style but pdo is a pain and overly complicated.
The answer to this issue was that i had
$sql = "SELECT * FROM transactions WHERE (sender = '".$user."' OR receiver = '".$user."') AND FROM_UNIXTIME(time) >= $past LIMIT 10";
should be
$sql = "SELECT * FROM transactions WHERE (sender = '".$user."' OR receiver = '".$user."') AND time >= '".$past."' LIMIT 10";

display more that one category from mysql

When I put an item in the database I can chose different "Used" categories .
For example I have Used, Barely Used, Rough. I am wanting all them to display on the same page.
Right now I have this code
$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `condition`='Used' $SQLCat $Limit";
Is there a way to do that?
...where (`condition`='Used' OR `condition`='Barely Used' OR `condition`='Rough')...
Try this..
$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `condition` LIKE '%Used' OR `condition` LIKE '%Barely Used%' OR `condition` LIKE '%Rough%' $SQLCat $Limit";
Check this link you simply use OR condition it will help you
$SQL_GetEquipment = "SELECT * FROM new_equip WHERE condition='Used' or condition='Barely Used' OR condition='Rough' $SQLCat $Limit";

Select percentage of rows from SQL table?

I've got a site with a PHP script, this script has an SQL query inside returning data that is accessed by a JavaScript file. The data is a huge list of flight data, and I need to be able to select (let's say) a random 40% of the total flights for any given day specified. For arguments sake lets put it like this:
$query = "SELECT * FROM `Flight_Data` WHERE DepDateTimeUTC LIKE '%1/1/14%' ";
I understand that to get a random number of rows you simply use ORDER BY RAND() LIMIT 40' and ideally I want to say LIMIT 40% but that doesn't work.
EDIT:
$query = "SELECT * FROM `Flight_Data` WHERE DepDateTimeUTC LIKE '%1/1/14%' ";
$row = mysqli_fetch_row($result);
$total = $row[0];
$percent = $total * 0.40;
$query = "SELECT * FROM `Flight_Data` WHERE DepDateTimeUTC LIKE '%1/1/14%' LIMIT . $percent ";
You can COUNT all records and then calculate the % you need like this:
$query = "SELECT COUNT(*) FROM `Flight_Data` WHERE DepDateTimeUTC LIKE '%1/1/14%' ";
$result = mysqli_query($connection,$query);
$row = mysqli_fetch_row($result));
$total = $row[0];
$percent = intval($total * 0.40);
$query = "SELECT * FROM `Flight_Data` WHERE DepDateTimeUTC LIKE '%1/1/14%' LIMIT ". $percent;
//execute your query....
Since you are using a php script you should be able to achieve what you want. What you can do is, get the total no of rows in the table, which goes like:
SELECT count(*) AS Total FROM Flight_Data
With php you can calculate the 40% of that total.
Lets say $myPercent contains the calculated 40% of total. You can use the value of $myPercent in the limit as
$query = "SELECT * FROM `Flight_Data`
WHERE DepDateTimeUTC LIKE '%1/1/14%'
LIMIT ".$myPercent;
Here, we escape the php variable from the mysql query string which is a good practice.
In mysql, % is used as wildcard, so it cannot be used like you thought you could in limit.
Hope this has helped you.

LIKE command in Mysql

My query:
$sel = mysql_query("select * from categorydetails where productname LIKE '%$commonsearch%' ");
Where product name = tvs apache rtr:
commonsearch = rtr
but it's not working
is there a way to use like command when mysql column contain more than one word?
$sel = mysql_query("select * from categorydetails where productname LIKE '%___rtr%' ");
see the example
SELECT * FROM certificates where csr REGEXP 'tvs'
your query
$sel = mysql_query("select * from categorydetails where productname REGEXP '$commonsearch' ");
Please use below query this is working on single word and multipe string like "test is test"
$sel = mysql_query("select * from categorydetails where productname LIKE '%rtr%' or productname LIKE '%rtr' or productname LIKE 'rtr%' ");
Use this
LIKE '%".$commonsearch."%

Categories