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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:33:53+00:00 2026-05-27T06:33:53+00:00

I am using MySQL to build a messaging system. Everything works beautifully so far

  • 0

I am using MySQL to build a messaging system. Everything works beautifully so far but I need to be able to do one particular thing.

In one of the tables I have the column ‘sender_id’.

I take this ‘sender_id’ and run it through a function which then retrieves the users avatar and outputs the link in the returned JSON response.

I need this link… But I also need to be able to retrieve the ‘sender_id’ itself as a number so that I can test against it in jquery.

So what I ultimately what is for the originaly ‘sender_id’ to be duplicated and put into a kind of virtual column ‘before’ it has been processed by my ‘get avatar’ function.

The code I am using to output the JSON after the queries etc. is as follows:-

/*
     * Output
     */
    $output = array(
        "sEcho" => intval($_GET['sEcho']),
        "iTotalRecords" => $iTotal,
        "iTotalDisplayRecords" => $iFilteredTotal,
        "aaData" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
        $row = array();
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( $aColumns[$i] == "version" )
            {
                /* Special output formatting for 'version' column */
                $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
            }
            if ( $aColumns[$i] == "sender_id" )
            {
                /* Special output to render Avatar by user id */
                $row[] = commentplayer_get_user_avatar($aRow[ $aColumns[$i] ]);

            }
            else if ( $aColumns[$i] == "message" )
            {
                /* General output */
                $row[] = strip_slashes($aRow[ $aColumns[$i] ]);
            }

            else if ( $aColumns[$i] != ' ' )
            {
                /* General output */
                $row[] = $aRow[ $aColumns[$i] ];
            }
        }
        $output['aaData'][] = $row;
    }

    echo json_encode( $output );
?>

$aColumns is the array of columns which are defined earlier, obviously ‘sender_id’ is one of these. As you can see I have put in a conditional statement so that the sender_id is retruned as an avatar link rather than the actual sender_id. So to sumarise I just need to be able to pull the actual sender_id out aswell as the avatar, preferably into a separate column.

Any ideas?

  • 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-27T06:33:53+00:00Added an answer on May 27, 2026 at 6:33 am

    You can add a line to the code handling the column sender_id:

            if ( $aColumns[$i] == "sender_id" )
            {
                /* Output user id */
                $row[] = $aRow[ $aColumns[$i]] );
                /* Special output to render Avatar by user id */
                $row[] = commentplayer_get_user_avatar($aRow[ $aColumns[$i] ]);
    
            }
    

    This will insert the user id right before the avatar URL in each returned JSON row-array.

    In fact, it would be nicer to get rid of the for-loop over the columns, and just fill $row with the items you need, indexed by proper names instead of depending on the order. This makes it easier to see what is actually appended to $output. It does mean that when interpreting the JSON on the client, you will have to treat the row as an object rather than an array.

        $row = array(
            "version"   => ($aRow["version"] == "0") ? '-' : $aRow["version"],
            "sender_id" => $aRow["sender_id"],
            "avatar"    => commentplayer_get_user_avatar($aRow["sender_id"]),
            "message"   => strip_slashes($aRow["message"]),
            // other items here
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP and MySQL, I have a forum system I'm trying to build. What
I am planning to build a University Management System using PHP/MYSQL. Should I get
I want to build a chat system in nodeJs + MYSQL using php. It
I am using MySQL and PHP to build a data layer for a flash
I'm using JDBC to insert a row into a MYSQL database. I build a
Using MySQL and PHP; I'm trying to build an index that contains the averages
I'm using PHP, jQuery and mySQL to build an admin site to my webpage.
As far as I know, when I build a desktop/server app using any GPL
I'm interested to build a huge database (100s millions of records) using MySQL, to
I'm new to C++, but not C, and I'm using the MySQL/C++ Connector package

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.