Quick PHP question, random data and limits

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech 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:

    $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?
    Extreme Link List - v1.0
  • sarettah
    see you later, I'm gone
    • Oct 2002
    • 14297

    #2
    Originally posted by Publisher Bucks
    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!

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Originally posted by sarettah
      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 :/

      $sql = "SELECT Culumn FROM Table WHERE Column IS NULL ORDER BY RAND() LIMIT 1";
      $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?)
      Extreme Link List - v1.0

      Comment

      • k0nr4d
        Confirmed User
        • Aug 2006
        • 9231

        #4
        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
        Mechanical Bunny Media
        Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

        Comment

        • Publisher Bucks
          Confirmed User
          • Oct 2018
          • 1330

          #5
          Originally posted by k0nr4d
          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?
          Extreme Link List - v1.0

          Comment

          • k0nr4d
            Confirmed User
            • Aug 2006
            • 9231

            #6
            Originally posted by Publisher Bucks
            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.
            Mechanical Bunny Media
            Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

            Comment

            • Publisher Bucks
              Confirmed User
              • Oct 2018
              • 1330

              #7
              Originally posted by k0nr4d
              != 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
              Extreme Link List - v1.0

              Comment

              • ZTT
                Confirmed User
                • Apr 2019
                • 659

                #8
                Originally posted by k0nr4d
                != 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.
                __________________

                Comment

                • k0nr4d
                  Confirmed User
                  • Aug 2006
                  • 9231

                  #9
                  Originally posted by ZTT
                  Though if you use != in PHP you'll find that null does equal an empty string.
                  Mechanical Bunny Media
                  Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

                  Comment

                  Working...