SQL query select all rows except one [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to select everything in the table jogos except the row where intCategoria is 11. How can I do that?
$query_GameData = sprintf("SELECT * FROM `jogos` ORDER BY RAND()");

SELECT *
FROM `jogos`
WHERE intCategoria <> 11
ORDER BY RAND()

Just use WHERE clause like that :
$query_GameData = sprintf("SELECT * FROM `jogos` where intCategoria != 11 ORDER BY RAND() ");

Related

using ORDER BY id DESC and where [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how can i use right code for using ORDER BY id DESC and WHERE
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']."ORDER BY id DESC";
Add a space here as shown.
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
----^
Also, don't pass your parameters like $_GET or $_POST directly into the SQL query as it will definitely lead to SQL Injection Attacks. Filter those parameters or make use of Prepared Statements.
add a space before 'ORDER' at least
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
You need provide space before ORDER BY
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
Simply Use this :
$sel = "SELECT * FROM items where portfolio_id ='$_GET[folio_id]' ORDER BY id DESC";

mysql query for password should not be last three passwords? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have pwd_history table containing columns id(PK),old_password, created_date,user_id. When ever user modify the password an extra row will be added to that table.I want a single query through which it should verify the entered password is in last three passwords modified by the user. Is there a way in Mysql? thanks.
If the password was hashed with mysql's default password, then
try this, with valid input values:
Updated:
select * from (
select * from old_pwds_table
where user_id=input_id
order by created_date desc
limit 3
) a
where
old_password=password('new password')
Former answer:
select * from old_pwds_table
where user_id=input_id
and old_password=password('new password')
order by created_date desc
limit 3
Check this function hope It helps to you:
function check_old_pass($new_pwd){
$result=mysql_num_rows(mysql_query("select * from old_pwds_table
where user_id=input_id
and old_password=$new_pwd
order by created_date desc
limit 0,3"));
if ($result==1) {
return true;
} else {
return false;
}
}
SELECT
*
FROM
pwd_history
WHERE
user_id = 'USER_ID'
AND
oldpasswords = 'NEW_PASSWORD'
ORDER BY
created_date DESC
LIMIT 3

Checking Available Room Using MySql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Everybody. I have a problem with my assignment about hotel booking online, that my problem is difficult to check available room. So I have many table like:
tbRoom(RoomID,RoomName,...)
tbReservation(ResID,ResDate,....)
tbReservationDetail(ResID,RoomID,ArrvialDate,DepartureDate,....)
I want to get Room that available in between two date.
so, How I do?or DO I need to create more table?
Please help me, Thank for helping....
You can select your reserved rooms and invert:
SELECT * FROM tbRoom WHERE RoomID NOT IN (SELECT RoomID FROM tbReservationDetail WHERE ArrvialDate < yourDate AND DepartureDate > yourDate)
You can achieve your result using above 3 tables you specified. but only thing you have to change is that you have to use RoomID filed in tbReservation table also.
rbRoom -> store the distinct rooms
tbReservation -> when a room is reserved this table will hold the RoomID and Reservation ID
tbReservationDetail ->stores the other details regarding arrivalDate,DepartureDate etc.
then follow the below query
SELECT * FROM tbRoom WHERE RoomID NOT IN (SELECT RoomID FROM tbReservation
tr,tbReservationDetail td WHERE td.ArrvialDate < yourDate AND
td.DepartureDate > yourDate and tr.RoomID=td.RoomID)

Get n random rows from mysql and write them to file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to take n random rows from mysql table and write them to file . Please help me how could I do it using php? Structure of mysql table is:
CREATE TABLE IF NOT EXISTS `keys` (
`keyword` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Supposing that by first n rows you meant the first N alphabetically, your code shoud be something like:
$fd = fopen("/the/filename/you/want","w");
$db = new mysqli($host,$username,$passwd,$dbname);
$rs = $db->query("SELECT `keyword` FROM `keys` order by `keyword` LIMIT $n"); //Being $n the number of rows that you want
while ($row = $rs->fetch_assoc())
{
fwrite($fd,$row['keyword']);
}
$rs->free();
fclose($fd);

MYSQL + PHP issue where Firstname [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Guys im having a issue with my mysql php problem ok i want this to pull table information out of my mysql database in it shows up the firstname by the number 10 but i want to add more too it like 10 100 1000 in other numbers how can i do this from this code
$result = mysqli_query($con,"SELECT * FROM tvshows
WHERE FirstName='10',100,1000");
SELECT * FROM tvshows WHERE FirstName IN (10,100,1000);
You can look here:
http://dev.mysql.com/doc/refman/5.0/en/any-in-some-subqueries.html
and here:
http://dev.mysql.com/tech-resources/articles/subqueries_part_1.html
If you want to select strings, you need to '', ex.:
SELECT * FROM tvshows WHERE FirstName IN ('10','100','1000');
If Numbers like this:
SELECT * FROM tvshows WHERE FirstName IN (10,100,1000);
The IN operator allows you to specify multiple values in a WHERE clause.
$result = mysqli_query($con,"SELECT * FROM tvshows
WHERE FirstName IN('10','100','1000')");
See Example
You have to change the = for IN
$result = mysqli_query($con,"SELECT * FROM tvshows WHERE FirstName IN(10,100,1000);
SQL IN clause documentation

Categories