mercredi 14 août 2019

How to skip blank table rows and randomly show null rows only

I am adding an affiliate system that shows each person to add their affiliate link on the home page once that user submits it in the member's section. Then their link will show in the rotation on the home page.

I need to add the random call with the IS NOT NULL when selecting the SQL and I only want one affiliate URL to show at a time.

My server is php5.6 for now and I have tried adding IS NOT NULL in different ways using

SELECT * FROM users IS NOT NULL ORDER by rand() LIMIT 1;

but I get an error. I also have tried

SELECT leads ORDER by rand() FROM users IS NOT NULL LIMIT 1;

Still no results.

SELECT * FROM users IS NOT NULL LIMIT 1;

It works but it will not randomly select trough the null data.

I keep getting the following errors

ERROR: Could not able to execute SELECT * FROM users IS NOT NULL ORDER by rand() LIMIT 1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IS NOT NULL ORDER by rand() LIMIT 1' at line 1

and below this does not give an error but it does not do what I need it to do.

SELECT leads IS NOT NULL FROM users ORDER by rand() LIMIT 1;




Aucun commentaire:

Enregistrer un commentaire