display more that one category from mysql - php

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";

Related

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."%

SQL Select latest row where value matches

I'm trying to return the row from my database, with the highest UID, where the URL column matches http://urltocheck.com.
I've tried all manner of things I can think of, and this is the closest I can get, but I'm getting an SQL syntax error.
My Table is called Adam, and I have the columns... UID (unique), URL (plus loads more). I'm trying to access the MySQL databse via PHP.
$query = "SELECT * FROM `Adam`
WHERE URL='http://urltocheck.com'
ORDER BY `UID` ASC;
LIMIT 1;";
Can anyone help please?
You shoul use order DESC and remove the ";" after ASC
$query = "SELECT * FROM `Adam`
WHERE URL='http://urltocheck.com'
ORDER BY `UID` DESC
LIMIT 1";
Try like this. Also, remove ; at this line ORDER BY UID ASC; (didn't noticed that earlier) because of which limit 1 not coming to picture.
SELECT * FROM `Adam`
WHERE URL='http://urltocheck.com'
and `UID` = (select max(`uid`) from `Adam`)
with the highest UID
You should order by UID desc and limit to 1.
You can also ORDER BY MAX ID.
<?php
$query = "SELECT * FROM `Adam`
WHERE URL='http://urltocheck.com'
ORDER BY MAX(`UID`) DESC;";
This is executed faster.
$query = "SELECT * FROM `Adam`
WHERE URL='http://urltocheck.com'
ORDER BY MAX(`UID`);";
?>

Edit php string

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

MySQL LIKE and LIMIT

I am trying to select stuff from a database with the LIKE statement, but I would also like to LIMIT the amount of records I get out of it.
$query = mysqli_query($connect,
"SELECT * FROM proizvodi WHERE `naziv` LIKE %127% ".
"AND LIMIT $start, $per_page");
The code I have is a boolean, and is not working. How to fix this?
The LIMIT requires quotation marks and cannot be joined with AND.
SELECT * FROM proizvodi WHERE `naziv` LIKE '%127%' LIMIT $start, $per_page
Look at the documentation for the SELECT statement, you don't need to use AND to join your WHERE and LIMIT sections.
See: http://dev.mysql.com/doc/refman/5.7/en/select.html
SELECT * FROM proizvodi WHERE `naziv` LIKE %127% LIMIT $start, $per_page;
SQL is not guaranteed to return the same results in the same order each time, unless you use an order by. You code should look like:
SELECT *
FROM proizvodi
WHERE `naziv` LIKE %127%
ORDER BY <something>
LIMIT $start, $per_page
You can try something like:
$sql='SELECT * FROM product WHERE `ProName` LIKE "%'.$searchWord.'%" LIMIT '.$this_page_first_result.', '.$results_per_page.';'
Limit is not part of the where clause and therefore no AND is allowed.
$query = mysqli_query($connect,
"SELECT * FROM proizvodi
WHERE `naziv` LIKE %127%
ORDER BY naziv ASC
LIMIT 10");
This will limit your queries up to 10.
$start, $per_page is something to get hands later if this is a problem now.. :)

Two results to one mysql statement

I've successfully managed to output the posts of a users friends...
$query = mysql_query("SELECT * FROM `users_posts` WHERE user_id IN ($friend) ORDER BY `time` DESC");
This outputs all of the friends posts of the user. However I want to get the posts of the user itself AS WELL as the friends posts...this is what I have tried...
$query = mysql_query("SELECT * FROM `users_posts` WHERE user_id IN ($friend) AND `user_id`=$session_user_id ORDER BY `time` DESC");
I even tried making another mysql statement just to load the users posts however when I did that, the users posts were being outputted first in the order of the time that they were outputted and then after the users posts were the friends posts shown...
Thanks :)
You actually want an OR condition:
$query = mysql_query("SELECT * FROM `users_posts` WHERE user_id IN ($friend) OR `user_id`=$session_user_id ORDER BY `time` DESC");
Try:
$query = mysql_query("SELECT * FROM `users_posts` WHERE user_id IN ($friend) OR `user_id`=$session_user_id ORDER BY `time` DESC");
That will return anything where user_id is in your array; as well as the user's own ID.
If I understand correctly chwhat you are trying to do all you need do is change
And 'user_id = $session_iser_id
To
Or 'user_id = $session_iser_id

Categories