GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Quick PHP question, random data and limits (https://gfy.com/showthread.php?t=1350799)

Publisher Bucks 12-19-2021 03:20 PM

Quick PHP question, random data and limits
 
So i have a table that contains a range of columns, some of them fill the entire set of rows, some of them have say, 10 items in the column, while I have 25 rows.

This is the querie that I am using to display the data:

Quote:

$sql = "SELECT ColumnName FROM Table ORDER BY RAND() LIMIT 1";
I understand why its only displaying blank fields in some areas of my PHP coding (because its randomly pulling row data that doesnt exist in a column), however, how would I change the above querie to FORCE data to be displayed for a specific column, whether its full or only 1/2 full with data?

Hopefully, that makes sense?

sarettah 12-19-2021 04:08 PM

Quote:

Originally Posted by Publisher Bucks (Post 22945539)
So i have a table that contains a range of columns, some of them fill the entire set of rows, some of them have say, 10 items in the column, while I have 25 rows.

This is the querie that I am using to display the data:



I understand why its only displaying blank fields in some areas of my PHP coding (because its randomly pulling row data that doesnt exist in a column), however, how would I change the above querie to FORCE data to be displayed for a specific column, whether its full or only 1/2 full with data?

Hopefully, that makes sense?

If the empty fields are nulls then

Select field-name from table where field-name is no null order by rand() ....

Would work. If there are blank fields that are not null then

Select field-name from table where field-name>'' order by rand() ...

should work

.

Publisher Bucks 12-19-2021 09:14 PM

Quote:

Originally Posted by sarettah (Post 22945556)
If the empty fields are nulls then

Select field-name from table where field-name is no null order by rand() ....

Would work. If there are blank fields that are not null then

Select field-name from table where field-name>'' order by rand() ...

should work

.

Thanks,

I've tried both but neither seems to work, the page still displays empty data for some reason :/

Quote:

$sql = "SELECT Culumn FROM Table WHERE Column IS NULL ORDER BY RAND() LIMIT 1";
Quote:

$sql = "SELECT Column FROM Table WHERE Column IS NOT NULL ORDER BY RAND() LIMIT 1";
The column has 4 rows of data on 20 rows.

All rows are currently 'null' in the table and are also set as 'longtext' (If that matters?) :helpme

k0nr4d 12-20-2021 12:07 AM

Null and empty are not the same thing. Null is used to refer to nothing and empty is a string with zero length.


SELECT * FROM table WHERE column != '' ORDER BY RAND() LIMIT 1

Publisher Bucks 12-20-2021 12:35 AM

Quote:

Originally Posted by k0nr4d (Post 22945673)
Null and empty are not the same thing. Null is used to refer to nothing and empty is a string with zero length.


SELECT * FROM table WHERE column != '' ORDER BY RAND() LIMIT 1

Okay that works, thank you.

Any chance you could explain why for me though? What does that != do that a regular query doesnt?

k0nr4d 12-20-2021 01:24 AM

Quote:

Originally Posted by Publisher Bucks (Post 22945674)
Okay that works, thank you.

Any chance you could explain why for me though? What does that != do that a regular query doesnt?

!= is a regular query. "!=" is "does not equal". You can use it in PHP as well, it is the opposite of "==" like you'd use in an if statement.
An empty string is not null, it's an empty string.

Publisher Bucks 12-20-2021 01:51 AM

Quote:

Originally Posted by k0nr4d (Post 22945679)
!= is a regular query. "!=" is "does not equal". You can use it in PHP as well, it is the opposite of "==" like you'd use in an if statement.
An empty string is not null, it's an empty string.

Awesome, thanks for the extra tidbit of knowledge :thumbsup

ZTT 12-20-2021 03:39 AM

Quote:

Originally Posted by k0nr4d (Post 22945679)
!= is a regular query. "!=" is "does not equal". You can use it in PHP as well, it is the opposite of "==" like you'd use in an if statement.
An empty string is not null, it's an empty string.

Though if you use != in PHP you'll find that null does equal an empty string.

k0nr4d 12-20-2021 04:33 AM

Quote:

Originally Posted by ZTT (Post 22945692)
Though if you use != in PHP you'll find that null does equal an empty string.

https://img.devrant.com/devrant/rant...0871_pSXCf.jpg


All times are GMT -7. The time now is 10:25 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc