MYSQL + PHP issue where Firstname [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
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

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

In mysql, how to I query to see if a specific user is in a table? [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 a table of users and I want a query that will tell me if a particular user is listed in the table. For example, in the table below:
Users | Ages
Bob | 22
Mike | 30
Sue | 21
Can someone help me with a query that does something like,
If (In USERS_TABLE, Mike is in column 'Users'){$userPresent="true";}
Mysql Num rows can help you with that
$query = mysql_query("select * from users_table where Users = 'Mike'");
if(mysql_num_rows($query))
{
echo "user present";//use your code how you want
}
else
{
echo "user not present";
}
mysql_ extension is deprecated as of PHP 5.5.0.
So Please choose PDO or MYSQLI api for better experience.
Your query would be:
SELECT * FROM USERS_TABLE WHERE Users='Mike'
You could run a query like
SELECT * FROM USERS_TABLE WHERE Users='Mike'
Then, you could check if the number of rows returned from that query was more than 0.
SELECT count(*) as count FROM USERS_TABLE WHERE Users='Mike'
If count>0 then user exists.
or if you want that user record,just use as below
SELECT * FROM USERS_TABLE WHERE Users='Mike'
Select * FROM USERS_TABLE WHERE Users = 'mike', here you can choose specific table like
Select Users FROM USERS_TABLE WHERE Users= 'mike'

SQL query display last row by a column [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 trying to display all information submitted by a specific username(variable) in my case:
<?php
$Username = $_SESSION['VALID_USER_ID'];
$q = mysql_query("SELECT * FROM `article_table` ORDER BY FIELD (Username, '.$Username.') DESC LIMIT 1");
while($db = mysql_fetch_array($q)) { ?>
Your Articles: <?=$db['Subject'];?><br />
<? } ?>
But don't work, I'll display the last article subject(for example) from the table and not from the specific username, where I'm wrong?
That is not how ORDER BY works. You first need to filter the results by using the WHERE clause.
$q = mysql_query("SELECT * FROM `article_table` WHERE `Username` = '$Username' ORDER BY `other_column` DESC LIMIT 1");
Replace other_colum in this query by the name of your date column: ie. date_created
Here is your query:
SELECT *
FROM `article_table`
ORDER BY FIELD (Username, '.$Username.') DESC
LIMIT 1;
This should be returning the username you are looking for when it is available. The logic is that field returns 1 when the name matches and 0 otherwise. So the descending keyword puts the match first. If there is no match, then you will get another row.
Presumably the data does not exist. You can test that easily enough by running:
SELECT *
FROM `article_table`
WHERE Username = '.$Username.';

SQL query select all rows except one [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 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() ");

Categories