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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:34:41+00:00 2026-05-26T07:34:41+00:00

I get an array of values returned from the following function: function get_subscribitions($user) {

  • 0

I get an array of values returned from the following function:

function get_subscribitions($user)
{

$user = mysql_real_escape_string ($user);
$sql = "SELECT 'user_id' FROM `subscribe` WHERE subscriber = '$user'";
$result = mysql_query($sql);
$rows = array();   
while ($row = mysql_fetch_assoc($result)) {
   $rows[] = $row;
}    
mysql_free_result($result); 
return $rows;

I now want to use these values in a new function, where each “user_id” is used to collect text from the database through this function:

function get_text($writer) {
$writer = mysql_real_escape_string ($writer);
$sql = "SELECT * FROM `text` WHERE user_id='$writer' ORDER BY timestamp desc";
$result = mysql_query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
   $rows[] = $row;
}

mysql_free_result($result);
return $rows;

However the returned value from the first function is an array, and as I’ve learnt the hard way, arrays cannot be treated by “mysql_real_escape_string”.

How can I make the second function handle the values that I got from the first function?

Any responses appreciated.
Thank you in advance.

  • 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-26T07:34:41+00:00Added an answer on May 26, 2026 at 7:34 am

    Your first mistake is to use mysql_fetch_assoc when only selecting one column. You should use mysql_fetch_row for this. This is likely going to fix your primary problem.

    Could look like this:

    $subs = get_subscribitions($whateverId);
    $texts = get_text($subs);
    
    function get_subscribitions($user)
    {
        $user = mysql_real_escape_string ($user);
        $sql = "SELECT 'user_id' FROM `subscribe` WHERE subscriber = '$user'";
        $result = mysql_query($sql);
        $rows = array();
    
        while ($row = mysql_fetch_row($result)) {
            $user_id = $row['user_id'];
            $rows[$user_id] = $user_id;
        }
        mysql_free_result($result);
        return $rows;
    }
    
    function get_text($writer) {
        $writers = implode(",", $writer);
        $sql = "SELECT * FROM `text` WHERE user_id IN ({$writers}) ORDER BY timestamp DESC";
        $result = mysql_query($sql);
        $rows = array();
    
        while ($row = mysql_fetch_array($result)) {
            $rows[] = $row;
        }
    
        mysql_free_result($result);
        return $rows;
    }
    

    This will save you a lot of time, because you can get all data from 'text' in one statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get an array of values from an associative array ? Associate
I'm trying to get the values from a pointer to a float array, but
I have an array that's made up of data returned by a SQL query:
The objective is to get an array of MemberExpressions from two LambdaExpressions. The first
How do I interpret the returned array from build-in method getPixels for a Bitmap?
Can anyone describe the following php function: function get_setting_value($settings_array, $setting_name, $default_value = ) {
Trying to get a value out of 2d array inside of a hash and
I want to get the value of my integer array, at an index. The
How in C++ get array length with pointers only ? I know that tab
Is there a simple way to get array of all index paths for the

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.