Hi, $query="SELECT * FROM products WHERE cat1='$cat1' AND cat2='$cat2' AND cat3 IS NULL Limit ".$x.",".$y; cat3 is null work well on local host on computer and return rows from table in database but it doesnt work on my web hosting server and doesnt return any rows Can anyone help with this?
You probably have no rows in which cat3 is null. (Blank and null are different. Null means that nothing has ever been written to that field on that row. Storing '' to the field leaves it blank, not null.) If you saved your data locally, then inserted it into the database on the server - and the insert statement included inserting cat3 as '' - there are no rows in which cat3 is null. Try WHERE cat1='$cat1' AND cat2='$cat2' AND cat3 = '' Limit ".$x.",".$y; (That's 2 single quotes.)
i think it was a browser cache problem. The script which was not working yesterday, working absolutely fine today after I closed the browser last night. I should have deleted cookies and temporary internet files. Rukbat can you please tell me how can I replace '' to null in fields in existing table in database?
I think you are facing the error because you don't have the database/ Table/ or any row and in Localhost you have so grab your database export it and import it
Since null means "never been written to", the only way would be to delete the row, then insert a new row with all the other fields (don't have cat3 in the list in the INSERT query). It's not a practical solution. Changing the WHERE to cat1='$cat1' AND cat2='$cat2' AND (cat3 is null or cat3 = '') is a better solution.