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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:51:47+00:00 2026-05-27T00:51:47+00:00

This is the original MySQL query: UPDATE jos_bully_table AS jbt1 INNER JOIN ( SELECT

  • 0

This is the original MySQL query:

 UPDATE jos_bully_table AS jbt1
 INNER
  JOIN ( SELECT jbt2.bully_concat_name,
                COUNT(*) AS b_name_count
           FROM jos_bully_table AS jbt2
          GROUP
             BY jbt2.bully_concat_name
       ) AS jbt3
    ON jbt3.bully_concat_name = jbt1.bully_concat_name
   SET jbt1.b_name_count = jbt3.b_name_count
;

It works great when running from phpMyAdmin. I clicked Create PHP Code and this is generated:

$sql = "UPDATE jos_bully_table AS jbt1\n"
    . " INNER\n"
    . " JOIN ( SELECT jbt2.bully_concat_name,\n"
    . " COUNT(*) AS b_name_count\n"
    . " FROM jos_bully_table AS jbt2\n"
    . " GROUP\n"
    . " BY jbt2.bully_concat_name\n"
    . " ) AS jbt3\n"
    . " ON jbt3.bully_concat_name = jbt1.bully_concat_name\n"
    . " SET jbt1.b_name_count = jbt3.b_name_count\n"
    . "";

I’m trying to run the same query from a php file, but the db isn’t updating.

Here is my php file:

<?php

$database = "xxxxxxxxx" ;
$username = "xxxxxxxxx" ;
$password = "xxxxxxxxx" ;

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


mysql_query($sql);

$sql = "UPDATE jos_bully_table AS jbt1\n"
    . " INNER\n"
    . " JOIN ( SELECT jbt2.bully_concat_name,\n"
    . " COUNT(*) AS b_name_count\n"
    . " FROM jos_bully_table AS jbt2\n"
    . " GROUP\n"
    . " BY jbt2.bully_concat_name\n"
    . " ) AS jbt3\n"
    . " ON jbt3.bully_concat_name = jbt1.bully_concat_name\n"
    . " SET jbt1.b_name_count = jbt3.b_name_count\n"
    . "";

echo "<!-- SQL Error ".mysql_error()." -->";

?>

What is wrong with this?

  • 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-27T00:51:48+00:00Added an answer on May 27, 2026 at 12:51 am

    You’re running your query string BEFORE you defined it.

    $sql = "SELECT ..."
    $result = mysql_query($sql) or die(mysql_error());
    

    As well, look into HEREDOCs for defining multi-line strings:

    $sql = <<<EOL
    SELECT ..
    FROM ...
    WHERE ...
    ORDER BY ..
    EOL;
    

    is far more readable than a multi-line concatenation

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

Sidebar

Related Questions

The original query looks like this (MySQL): SELECT * FROM books WHERE title LIKE
The original query was: UPDATE `test`.`documents` SET `title` = ‘测试中文’, `content` = ‘this is
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
from this code will show in original color how can i change it to
UPDATE: This question is out of date, but left for informational purposes. Original Question
I've editing this original question as I think I've narrowed down the problem... I
This is a continuation of this question: Original Question (SO) The answer to this
This is a simplified version of the original problem. I have a class called
this is an edit of the original post now that I better understand the
This question is sort of a follow-up to my original question here . Let's

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.