Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:27:23+00:00 2026-05-30T14:27:23+00:00

How do I find the first column with no data? //column pet1=’dog’ //column pet2=”

  • 0

How do I find the first column with no data?

//column pet1='dog'
//column pet2=''
//column pet3=''
//column pet4='cat'


if($F=="getempty"){
    $uid=$_GET["uid"];
    $sql = mysql_query("SELECT DISTINCT pet1,pet2,pet3,pet4 FROM a WHERE uid='".$uid."' AND pet1='' OR pet2='' OR pet3=''OR pet4=''");    
    while($column=mysql_fetch_field($sql)){
        $empty=$column->name;
        echo json_encode(array("empty"=>$empty));
        }
    }else{}

I keep trying but so far it just returns all column names if one is empty

pet1,pet2,pet3,pet4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:27:24+00:00Added an answer on May 30, 2026 at 2:27 pm

    DISTINCT will combine the rows which are exactly alike (having all the selected columns the same) and return them.

    To get the name of the first empty column, use a query like:

    SELECT
      CASE 
        WHEN pet1 = '' THEN 'pet1'
        WHEN pet2 = '' THEN 'pet2'
        WHEN pet3 = '' THEN 'pet3'
        WHEN pet4 = '' THEN 'pet4'
      ELSE NULL
     END AS firstempty
    FROM a
    WHERE uid = '$uid';
    

    The idea is that the CASE statement checks each one in order, and finding an empty one returns the column name without checking the rest of them.

    Don’t forget to escape $uid with mysql_real_escape_string() before passing it to the query.

    $uid = mysql_real_escape_string($uid);
    

    Since we’re now getting the column name inside a field called firstempty, we’ll also need to change the way it’s fetched:

    while($row = mysql_fetch_assoc($sql)){
         $empty = $row['firstempty'];
         echo json_encode(array("empty"=>$empty));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am comparing between two tables first column each. If there is find a
In Ruby on Rails I'm doing something like: Appointment.find( :first, :conditions => staff_id =
I want to find the first item in a sorted vector that has a
I traced an oracle process, and find it first open a file /etc/netconfig as
Im building a calendar and to find out the first day of the month
At first I want to say: I couldn't find a support forum for this
How to find out if site is the first item in history? This doesn't
I'm trying to find rows where the first character is not a digit. I
i want to find factorial a number which i take memory first.(intel 8085) edit:
Writing my first Linq application, and I'm trying to find the best way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.