Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-19-2021, 03:20 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,121
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?
__________________
NOTHING TO SEE HERE
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-19-2021, 04:08 PM   #2
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,053
Quote:
Originally Posted by Publisher Bucks View Post
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

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-19-2021, 09:14 PM   #3
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,121
Quote:
Originally Posted by sarettah View Post
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?)
__________________
NOTHING TO SEE HERE
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 12:07 AM   #4
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
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
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 12:35 AM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,121
Quote:
Originally Posted by k0nr4d View Post
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?
__________________
NOTHING TO SEE HERE
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 01:24 AM   #6
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by Publisher Bucks View Post
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.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 01:51 AM   #7
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,121
Quote:
Originally Posted by k0nr4d View Post
!= 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
__________________
NOTHING TO SEE HERE
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 03:39 AM   #8
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
Quote:
Originally Posted by k0nr4d View Post
!= 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.
__________________
__________________
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-20-2021, 04:33 AM   #9
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by ZTT View Post
Though if you use != in PHP you'll find that null does equal an empty string.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
data, column, querie, rows, php, table, blank, fields, displaying, row, exist, pulling, coding, randomly, 1/2, sense, makes, specific, change, force, displayed, select, set, entire, fill



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.