Dawid Wiewiór
Dawid Wiewiór

Reputation: 41

select not null values from table Mysql

guys i have problems with select not null values from my table

$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos = ".$losuj['test1']." 
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']." order by rand() limit 1"));
$szansa = rand(1,100000);

i arleady try with add and (cos IS NOT NULL) but doesnt work here is my full code

$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos = ".$losuj['test1']." 
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']."  and (cos IS NOT NULL) order by rand() limit 1"));
$szansa = rand(1,100000);

Upvotes: 0

Views: 68

Answers (2)

Raul Luna
Raul Luna

Reputation: 2046

I am afraid that the problem is in the parenthesis. This correction should work (pay attention to the parenthesis):

$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where (cos = ".$losuj['test1']." 
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']." ) and (cos IS NOT NULL) order by rand() limit 1"));
$szansa = rand(1,100000);

Upvotes: 0

rowmoin
rowmoin

Reputation: 708

You can use alternative query but its not a standard:

SELECT *
FROM table 
WHERE NOT (YourColumn <=> NULL);

You also should use uppercase "AND"

You can try this also:

mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos IS NOT NULL AND (cos = ".$losuj['test1']. " 
OR cos = ".$losuj['test2']. "
OR cos = ".$losuj['test3']. "
OR cos = ".$losuj['test4']. "
OR cos = ".$losuj['test5']. "
OR cos = ".$losuj['test6']. ") ORDER BY rand() LIMIT 1"));

Upvotes: 1

Related Questions