0

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);
8
  • did you try without fast brackets before cos IS NOT NULL Commented Jul 23, 2017 at 15:52
  • @rowmoin ofcourse Commented Jul 23, 2017 at 15:54
  • 1
    What error showing when you run this query Commented Jul 23, 2017 at 15:55
  • @rowmoin Nothing but still select from tables field with a null value Commented Jul 23, 2017 at 15:58
  • 2
    Both of your queries should not return anay row where cos is NULL. BTW: You can use WHERE cos IN(.., .., ..) instead of multiple OR conditions. Commented Jul 23, 2017 at 16:24

2 Answers 2

1

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"));
Sign up to request clarification or add additional context in comments.

19 Comments

don't return any values
Both of your queries should not return anay row where cos is NULL. Are you sure do you have a value for this query?
$losuj['test2'] = 2 $losuj['test1'] = 1 $losuj['test3'] = 3 $losuj['test4'] = 4 $losuj['test5'] = null $losuj['test6'] null
what do you want to mean by this? do you have a value in your table where cos=2 or cos=1?
Could you please try again 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 rainnd() LIMIT 1")); I have some changed in query
|
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.