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 7565593
In Process

The Archive Base Latest Questions

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

What is the problem with my mysql array extraction below: $mysql_array = mysql_query(SELECT *

  • 0

What is the problem with my mysql array extraction below:

        $mysql_array = mysql_query("SELECT * FROM table1 WHERE uid1='$uid1'"); 
        $array = array();
        while($row = mysql_fetch_assoc($mysql_array)){
            $array[] = $row;
        }

        $array = array_unique($array);
        $array = array_reverse($array);
        $emails = array();
        $numbers = array();

        foreach($array as $row){
            $uid2 = $row['uid2'];
            $number = number($uid2);
            if(strlen($number) > 9){
                $numbers[] = array('uid2' => $uid2, 'number' => $number);
            }
            else{
                $email = email($uid2);
                $emails[] = array('uid2' => $uid2, 'email' => $email);
            }
        }
        $numbers = array_unique($numbers);
        $emails = array_unique($emails);            
        var_dump($numbers);
        var_dump($emails);

There must be something I need to do to convert the “Resource” from mysql into an array.
There must be a problem with the above code.
This is what I am getting on the var_dumps: array(0) { }
and array(1) { [0]=> array(2) { ["uid2"]=> NULL ["email"]=> NULL } }

  • 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:11:42+00:00Added an answer on May 30, 2026 at 2:11 pm

    I think this is what you’re trying to do:

    $result = mysql_query("SELECT DISTINCT * FROM table1 WHERE uid1 = '{$uid1}' ORDER BY /* insert column name here, followed by ASC or DESC */");
    $table = array();
    while ($row = mysql_fetch_assoc($result))
        $table[] = $row;
    
    // at this point, each entry in the $table array is one row from 'table1'.
    // shouldn't need to do array_unique or array_reverse with the modified SQL query above.
    
    $numbers = $emails = array();
    foreach ($table as $row)
    {
        $number = number($row["uid2"]);
        if (strlen($number) > 9 && !in_array($numbers[$row["uid2"]], $number, true))
            $numbers[$row["uid2"]][] = $number;
        else
        {
            $email = email($row["uid2"]);
            if (!in_array($emails[$row["uid2"]], $email, true))
                $emails[$row["uid2"]][] = $email;
        }
    }
    
    // shouldn't need to do array_unique with the if-statements above
    
    var_dump($numbers);
    var_dump($emails);
    

    EDIT Answering question from comments:

    Based on the logic you are using, the result will probably be the same. My example above will allow this scenario for $numbers, while your example will not:

    array(2)
    {
        [123] => array(2)
        {
            [0] => 1234567890,    // same as $numbers[456][0]
            [1] => 9876543210
        },
        [456] => array(1)
        {
            [0] => 1234567890    // same as $numbers[123][0]
        }
    }
    

    But based on the way that $number is generated based on $uid2, you probably won’t see any difference. What I mean is that, if number(123) returns 1234567890, then number(456) probably will not return 1234567890, so you probably wouldn’t ever run into a scenario where you would see a difference.


    EDIT 2 After thinking about this some more, I’m betting that your code can be greatly simplified to this:

    // only selecting uid2 from the table
    $result = mysql_query("SELECT DISTINCT uid2 FROM table1 WHERE uid1 = '{$uid1}' ORDER BY /* insert column name here, followed by ASC or DESC */");
    
    $output = array();
    while (list($uid2) = mysql_fetch_row($result))
    {
        $number = number($uid2);
        if (strlen($number) > 9)
            $output[$uid2]["number"] = $number;
        else
            $output[$uid2]["email"] = email($uid2);
    }
    
    var_dump($output);
    

    LAST EDIT (Hopefully):

    // only selecting uid2 from the table
    $result = mysql_query("SELECT DISTINCT uid2 FROM table1 WHERE uid1 = '{$uid1}' ORDER BY /* insert column name here, followed by ASC or DESC */");
    
    $numbers = $emails = array();
    while (list($uid2) = mysql_fetch_row($result))
    {
        $number = number($uid2);
        if (strlen($number) > 9)
            $numbers[$uid2] = $number;
        else
            $emails[$uid2] = email($uid2);
    }
    
    var_dump($numbers);
    var_dump($emails);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function addAds($n) { for ($i=0;$i<=$n;$i++) { while($row=mysql_fetch_array(mysql_query(SELECT * FROM users))) { $aut[]=$row['name']; } $author=$aut[rand(0,mysql_num_rows(mysql_query(SELECT
require(includes/connect.php); $result = mysql_query(SELECT * FROM entries, $link); while ($row = mysql_fetch_array($result)) { htmlentities($row['quotes']);
I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I am encountering a problem while extracting info from a database using php+mysql and
if (isset($submit)) { $getusers = mysql_query(SELECT * FROM register); while($getrows = mysql_fetch_array($getusers)) { $users
I have a mysql problem, my query looks as follows but not complete SELECT
This is a query that is executed without problem with MySql 5.0.51: SELECT cc_split.idSplit,
I have a problem with my php/mysql script. It should only output the while
$result = mysql_query(SELECT * FROM photos WHERE accountID = '{$accID}' GROUP BY album_name ORDER
I retrieve data from my database as such: while($row = mysql_fetch_array($result)) { echo $row['uid'];

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.