Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to show some data from a table in my database but i want it to show a specific ID "rid" that i get from another page with the code:
my SQL code is:
SELECT rid
, tid
, qid
, aid
, points
FROM result
WHEN rid = $val
if i delete WHEN rid=$val i will get all the all the "points" from my database. But i want to show a specific ID (rid). what should i do?
The correct SQL Statement would be
SELECT rid, tid, qid, aid, points FROM result WHERE rid=$val
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm creating a small project that scrapes specific webshops and gives an alert when the price changed.
When I try to insert a new record (if price is up/down) it won't insert the record. A connection with the database is in place as I check if the last known price went up or down.
$sql = "INSERT INTO `product_prices` (`productId`, `shopId`, `url`, `originalPrice`, `lowestPrice`, `dateChanged`) VALUES ($productId, $shopId, '".$url."', '".$originalPrice."', '".$lowestPrice."', '".$dateChanged."')";
When I echo $sql it generates this:
INSERT INTO `product_prices` (`productId`, `shopId`, `url`, `originalPrice`, `lowestPrice`, `dateChanged`) VALUES ('1', '1', 'https://www.webshop.com/', '999,99', '800', '2020-07-28 15:04:30')
When I use a remote SQL client (like Sequal Pro) and paste the output of above line it will insert the record. What am I doing wrong?
Problem found, I wasn't using $mysqli->query($sql); after inserting. Now I will dive into SQL injection. Thanks #nico for the heads-up.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So here I have a table of Products which contains ID, Name, Type & Price
Now I'm running a function to give me the minimal price of specific product types.
The datatype of Price is Price int(5,2)
function MinPrice($connection) {
echo "Minimum price: <br>";
$sql = "SELECT Type, min(Price)
FROM Products
GROUP BY Type;";
$result = mysqli_query($connection,$sql);
while ($row = mysqli_fetch_assoc($result)) {
//Printing the result
echo $row['Type'].' || '.$row['Price'].'<br>';
}
}
The code works but not properly. I get the names of the product types but for the price, it gives me an error.
Undefined index: Price
Can anyone please help me out with this?
Try this:
$sql = "SELECT Type, min(Price) as Price
FROM Products
GROUP BY Type;";
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Is there a simple explanation why this query doesn't work, and what is its alternative?
SELECT * FROM items WHERE item_category = 'shirts'
AND WHERE item_category = 'pants'
I have to keep the clause:
SELECT * FROM items
because I need all the data that is selected for later use.
Don't include WHERE twice:
SELECT * FROM items WHERE item_category = 'shirts' OR item_category = 'pants'
You also don't want to specify "AND", because there won't be a point where both item_category will be shirts and pants at the same time.
You have two WHERE keywords; the second is not necessary -- it generates an error.
However, you should simplify the query to use IN:
SELECT i.*
FROM items i
WHERE i.item_category IN ('shirts', 'pants');
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
please help me in this matter: I need to copy the unique values from entries_list.nr_comanda_entries to entries_uploaded.ship_id.
The tables have these values in common: entries_list.file_id = entries_uploaded.id
Both tables have many other columns, only the entries_uploaded.ship_id is empty.
Could you please tell me the mysql query to do that?
You could use an UPDATE query and an INNER JOIN:
UPDATE
entries_uploaded INNER JOIN entries_list
ON entries_list.file_id = entries_uploaded.id
SET
entries_uploaded.ship_id = entries_list.nr_comanda_entries
Please see fiddle here.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
$sql="SELECT product.title, product.description, product.price, product.product_id,
FROM product
INNER JOIN (SELECT * FROM product_category WHERE category_id='$categoryid') AS a
ON a.product_id=product.product_id";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
and the i get this warning:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in......
You have a comma even after the last selected field.
Might be ambigous, try to change it to:
...
FROM product p INNER JOIN
...
and replace the product. prefix in the first part of your SELECT statement by p.
If this still does not work, copy the complete command to phpmyadmin and execute it there (replace $categoryid with a real value first), you usually get a clue as to what is wrong with your statement.
Also there are commands to return more information on mysql errors in php as well (mysql_error)