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

  • Home
  • SEARCH
  • 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 8312801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:16:46+00:00 2026-06-08T20:16:46+00:00

I am needing to run more than one Mysql Query using PHP. I have

  • 0

I am needing to run more than one Mysql Query using PHP. I have a site and pull all the information from the databse

$sql = "SELECT * FROM $table WHERE ID=$escape";
$query = mysql_query($sql) or die(mysql_error());
$rentals = mysql_fetch_assoc($query);

Now I have two other queries I need to also run for Previous and Next Buttons

$sqlPrev = 'SELECT `id` FROM `table`
        WHERE `id` < '$curId' AND `catId` = '$curCat'
        ORDER BY `id` DESC LIMIT 1;

$sqlNext = 'SELECT `id` FROM `table`
        WHERE `id` > '$curId' AND `catId` = '$curCat'
        ORDER BY `id` ASC LIMIT 1;

I have the coding right when I run these in PHP MyAdmin, however when I try to execute them via the website I get a mysql error!

  • 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-08T20:16:49+00:00Added an answer on June 8, 2026 at 8:16 pm

    mysql_query can only execute one query at a time.

    Basically you just need to have 3 calls to mysql_query.

    $sql = "SELECT * FROM $table WHERE ID=$escape";
    $query = mysql_query($sql) or die(mysql_error());
    $rentals = mysql_fetch_assoc($query);
    
    $sqlPrev = 'SELECT `id` FROM `table`
            WHERE `id` < ' . $curId . ' AND `catId` = ' . $curCat . '
            ORDER BY `id` DESC LIMIT 1';
    
    $sqlNext = 'SELECT `id` FROM `table`
            WHERE `id` > ' . $curId . ' AND `catId` = ' . $curCat . '
            ORDER BY `id` ASC LIMIT 1';
    
    $resultPrev = mysql_query($sqlPrev);
    $resultNext = mysql_query($sqlNext);
    
    // todo: check that the above queries executed successfully
    // if (!$resultPrev) echo mysql_error();
    
    if (mysql_num_rows($resultPrev)) {
        $prev = mysql_fetch_array($resultPrev);
        $prevId = $prev['id'];
    } else {
        $prevId = null; // there is no previous item
    }
    
    if (mysql_num_rows($resultNext)) {
        $next = mysql_fetch_array($resultNext);
        $nextId = $next['id'];
    } else {
        $nextId = null; // there is no next item
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am needing some information on including files in PHP classes. E.G. include Foo2.php;
I have a PHP script which includes one or two other libraries it depends
Is it possible to run an external PHP script without needing to convert it
I have some jars in the current directory, all needing to be in the
So, I am needing to run an infinite loop in the background of my
I am writing a wordpress theme, and have run into a fairly basic problem.
I have a solution with two service projects (one is hosting a unit test
I'm looking into Mono and .NET C# and we'll be needing to run the
I have the following: class DThread { virtual void run()=0; _beginthreadex(NULL,0,tfunc,this,0,&m_UIThreadID); // class itself
I have a slightly unusual situation where I'm needing to maintain CLIENT tcp connections

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.