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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:14:25+00:00 2026-06-07T06:14:25+00:00

So I’ve got this super long query that I’ve been debugging. I originally received

  • 0

So I’ve got this super long query that I’ve been debugging. I originally received an error that column s.name and all the other JOIN columns are not in the "field list", so after some googling I was able to fix that error by putting them in double quotes. So now the query returns a resource without an error, but the resource is empty.

Now what I get from the echos after the statement is "Resource id #4 Warning: implode(): Invalid arguments passed in /var/www/beta/index.php on line 143 0"

Here is the query and surrounding functions:

<?php /* other functions preceding */ $result = mysql_query("SELECT * FROM users WHERE uid=" . $_SESSION['uid'] . "");
    $cur_user = mysql_fetch_array($result);
    $ufriends = explode(';', $cur_user['friends']);
    $ufsql = trim(implode(',',$ufriends),',');
    $uevents = explode(';', $cur_user['events']);
    $uesql = trim(implode(',',$uevents),',');
    $urequests = explode(';', $cur_user['requests']);
    $ursql = trim(implode(',',$urequests),',');
    if (!empty($ufriends)) {
        $time1 = microtime();
        $megaresult = mysql_query("
            ( SELECT \"s.name\" AS source_name, NULL AS target_name, recent_updates.*, 1 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                WHERE update_type='10'
                LIMIT 1
            )
            UNION
            ( SELECT \"s.name\" AS source_name, NULL AS target_name, recent_updates.*, 2 as ORD FROM recent_updates
                INNER JOIN users AS su ON (\"s.uid\"=recent_updates.source_id)
                WHERE update_type='10'
                LIMIT 1,9
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN users AS t ON (\"t.uid\"=recent_updates.target_id)
                WHERE update_type='2'
                AND
                    ( target_id IN (" . $ufsql . ") )
                AND
                    ( source_id IN (" . $ufsql . ") )
                OR
                (
                    ( target_id IN (" . $cur_user['uid'] . ") )
                AND
                    ( source_id IN (" . $ufsql . ") )
                )
                OR
                (
                    ( target_id IN (" . $ufsql . ") )
                AND
                    ( source_id IN (" . $cur_user['uid'] . ") )
                )
                LIMIT 0,10
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN users AS t ON (\"t.uid\"=recent_updates.target_id)
                WHERE update_type='4'
                AND
                (
                    ( target_id IN (" . $ufsql . ") )
                AND
                    ( source_id IN (" . $ufsql . ") )
                )
                OR
                (
                    ( target_id IN (" . $cur_user['uid'] . ") )
                AND
                    ( source_id IN (" . $ufsql . ") )
                )
                OR
                (
                    ( target_id IN (" . $ufsql . ") )
                AND
                    ( source_id IN (" . $cur_user['uid'] . ") )
                )
                LIMIT 0,10
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN events AS t ON (\"t.id\"=recent_updates.target_id)
                WHERE update_type='3'
                AND
                target_id IN (" . $uesql . ")
                LIMIT 0,10
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN events AS t ON (\"t.id\"=recent_updates.target_id)
                WHERE update_type='3'
                AND
                target_id IN (" . $ursql . ")
                LIMIT 0,10
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN events AS t ON (\"t.id\"=recent_updates.target_id)
                WHERE update_type='5'
                AND
                target_id IN (" . $ursql . ")
                LIMIT 0,10
            )
            UNION
            ( SELECT \"s.name\" AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN users AS s ON (\"s.uid\"=recent_updates.source_id)
                INNER JOIN events AS t ON (\"t.id\"=recent_updates.target_id)
                WHERE update_type='11'
                AND
                (
                    target_id IN (" . $uesql . ")
                OR
                    target_id IN (" . $ursql . ")
                )
                AND
                (
                    source_id IN (" . $ufsql . ")
                )
                LIMIT 0,10
            )
            UNION
            ( SELECT NULL AS source_name, \"t.name\" AS target_name, recent_updates.*, 2 AS ORD FROM recent_updates
                INNER JOIN events AS t ON (\"t.id\"=recent_updates.target_id)
                WHERE public != 0 LIMIT 0,10
            )
            ORDER BY ORD ASC, time_un DESC");
        echo $megaresult;
        $feed = mysql_fetch_array($megaresult);
        echo mysql_error();
        $time2 = microtime();
        echo implode('##', $feed);
        echo mysql_num_rows($megaresult);
        echo mysql_info($con);
/* brackets closed, etc */ ?>

I have a feeling it has something to do with putting the aliased columns in double quotes. I had a previous version of this query which didn’t include any of the JOIN parts which worked perfectly fine, I uploaded it to pastebin: http://pastebin.com/upifa7VJ

EDIT:

Well this is embarrassing… I was right to suspect that the quotes were causing the problem (thanks @andrewtweber!), but the error I was getting without the quotes was due to a typo in the second SELECT statement, INNER JOIN users AS su instead of INNER JOIN users as s. Thanks for the help everyone!

  • 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-06-07T06:14:26+00:00Added an answer on June 7, 2026 at 6:14 am

    The double quotes mean you are selecting the string “s.name” and not the column s.name.

    What you probably meant to do was use a backtick `. The backtick allows you to use reserved MySQL keywords as column names, e.g.

    SELECT `table`.`name` FROM `table` ORDER BY `order` ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.