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

  • SEARCH
  • Home
  • 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 6374713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:31:21+00:00 2026-05-25T01:31:21+00:00

I got stuck on selecting fields from a table using SQL and PHP. I

  • 0

I got stuck on selecting fields from a table using SQL and PHP.

I have a table named invitations with those fields:

  • senderid
  • receiverid1
  • receiverid2
  • …
  • receiverid10

I have different rows with the same senderid and want to select the receiverid corresponding to it.

Some receiversid may be null so I filter only non null value.

Here is my code:

$d1 = mysql_connect($dbhost,$dbuser ,$dbpass);
mysql_select_db($dbname, $d1);

/* fetching receivers */
$q1 = mysql_query("select receiverid1,receiverid2,receiverid3,receiverid4,
        receiverid5,receiverid6,receiverid7,receiverid8,receiverid9,receiverid10  
        from invitations 
        where senderid = '528495538' ", $d1);

while($row = mysql_fetch_array($q1))
{ 
    $totalreceivers = count(array_filter($row));
    $receivers[] = array_filter($row);

}
echo '<br>';    
echo "the receivers";
echo '<br>';
print_r($receivers);
echo '<br>';
echo $totalreceivers;

With the above sender id, on the table I have 2 rows but when I execute the code I get only one:

the receivers Array ( [0] => 1743650643 [receiverid1] => 1743650643 ) 2

Any kind of help will be appreciated, thank you.

  • 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-25T01:31:21+00:00Added an answer on May 25, 2026 at 1:31 am

    Make $recievers into an array, and $totalreceivers into an int starting at 0, and declare them before the loop. You are reassigning them on each loop instead of adding to them:

    $totalreceivers = 0;
    $receivers = array();
    while($row = mysql_fetch_assoc($q1)) {
      $filtered = array_filter($row);
      $totalreceivers += count($filtered);
      $receivers[] = $filtered;
    }
    

    Note that it is more efficient to call array_filter() once and assign it to a variable than it is to call it twice for each operation. Also, especially for the operation above, use mysql_fetch_assoc() instead of mysql_fetch_array().

    EDIT See if this is more like what you want (slightly fixed)…

    $receivers = array();
    while($row = mysql_fetch_assoc($q1)) {
      foreach (array_filter($row) as $item) {
        $receivers[] = $item;
      }
    }
    $totalreceivers = count($receivers);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass structs between processes using named pipes. I got stuck at
I have a problem selecting 6 random friends This is the query I've got
I'm learning php and I've got to say I've googled everywhere and I'm stuck
i am using jquery plugin and i got stuck in how to display the
I have just jumped into Objective-C and I got stuck pretty early on. I
i have been working on plist these days and got stuck in adding a
I'm very new to dealing with bits and have got stuck on the following
I just got stuck. I have 2 view controllers one is WatchListViewController and 2nd
I am new to grails and i got stuck with another issue. I have
i am using XSLT 1.0 version and got stuck in translating a pattern. I

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.