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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:44:05+00:00 2026-06-04T09:44:05+00:00

<?php $query1 = CREATE VIEW current_rankings AS SELECT * FROM main_table WHERE date =

  • 0
<?php

$query1 = "CREATE VIEW current_rankings AS SELECT * FROM main_table WHERE date = X";

$query2 = "CREATE VIEW previous_rankings AS SELECT rank FROM main_table WHERE date = date_sub('X', INTERVAL 1 MONTH)";

$query3 = "CREATE VIEW final_output AS SELECT current_rankings.player, current_rankings.rank as current_rank LEFT JOIN previous_rankings.rank as prev_rank
             ON (current_rankings.player = previous_rankings.player)";

$query4 = "SELECT *, @rank_change = prev_rank - current_rank as rank_change from final_output";

$result = mysql_query($query4) or die(mysql_error()); 

while($row = mysql_fetch_array($result)) {
echo $row['player']. $row['current_rank']. $row['prev_rank']. $row['rank_change'];
}

?>

All the queries work independently but am really struggling putting all the pieces together in one single result so I can use it with mysql_fetch_array.

I’ve tried to create views as well as temporary tables but each time it either says table does not exist or return an empty fetch array loop…logic is there but syntax is messed up I think as it’s the 1st time I had to deal with multiple queries I need to merge all together. Looking forward to some support. Many thanks.

  • 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-04T09:44:06+00:00Added an answer on June 4, 2026 at 9:44 am

    Thanks to php.net I’ve come up with a solution : you have to use (mysqli_multi_query($link, $query)) to run multiple concatenated queries.

     /* create sql connection*/
    $link = mysqli_connect("server", "user", "password", "database");
    
    $query = "SQL STATEMENTS;"; /*  first query : Notice the 2 semicolons at the end ! */
    $query .= "SQL STATEMENTS;"; /* Notice the dot before = and the 2 semicolons at the end ! */
    $query .= "SQL STATEMENTS;"; /* Notice the dot before = and the 2 semicolons at the end ! */
    $query .= "SQL STATEMENTS"; /* last query : Notice the dot before = at the end ! */
    
    /* Execute queries */
    
    if (mysqli_multi_query($link, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_array($result)) 
    
    /* print your results */    
    {
    echo $row['column1'];
    echo $row['column2'];
    }
    mysqli_free_result($result);
    }   
    } while (mysqli_next_result($link));
    }
    

    EDIT – The solution above works if you really want to do one big query but it’s also possible to execute as many queries as you wish and execute them separately.

    $query1 = "Create temporary table A select c1 from t1"; 
    $result1 = mysqli_query($link, $query1) or die(mysqli_error());
    
    $query2 = "select c1 from A"; 
    $result2 = mysqli_query($link, $query2) or die(mysqli_error());
    
    while($row = mysqli_fetch_array($result2)) {
    
    echo $row['c1'];
        }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a json encode in PHP like this: $get = mysql_query(SELECT * FROM
I am using a query inside PHP as: $query = 'SELECT * from #__chronoforms_UploadAuthor
I'm trying to create an SQL query in PHP to update a table. Is
I am using simple PHP query to fetch rows from the database, there are
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I am trying to create a menu where users can view a menu that
Let's say I have a PHP Model-View-Controller framework that maps an address like http://example.com/admin/posts/edit/5
I have a Zend_Paginator_Adapter_DbTableSelect object from this query: public function fetchPagedTracks() { $select =
I am creating a php page that loads cordinates from a mysql table and
I've been working on a system where you can create-read-update-delete to/from a table in

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.