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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:40:19+00:00 2026-05-19T02:40:19+00:00

I’m running a MySQL Query, here it is: CREATE TEMPORARY TABLE LeaderBoard ( `agent_name`

  • 0

I’m running a MySQL Query, here it is:

CREATE TEMPORARY TABLE LeaderBoard (
`agent_name` varchar(20) NOT NULL,
`job_number` int(5) NOT NULL,
`job_value` decimal(3,1) NOT NULL,
`points_value` decimal(8,2) NOT NULL
);
INSERT INTO LeaderBoard (`agent_name`, `job_number`, `job_value`, `points_value`) SELECT agent_name, job_number, job_value, points_value FROM jobs WHERE YEAR(booked_date) = 2010 && WEEKOFYEAR(booked_date) = 49;
INSERT INTO LeaderBoard (`agent_name`) SELECT DISTINCT agent_name FROM apps WHERE YEAR(booked_date) = 2010 && WEEKOFYEAR(booked_date) = 49;
SELECT agent_name, SUM(job_value), SUM(points_value) FROM leaderboard GROUP BY agent_name ORDER BY SUM(points_value) DESC

If i run this query in the phpmyadmin sql field, it works and I get the correct data that I want to use!

But when I put this into my PHP script it comes back with an error saying: “Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\reporting_2010.php on line 383”

Here is my PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Reports - Yearly Summary 2010</title>
    <link rel="stylesheet" type="text/css" href="css/allreset.css">
    <link rel="stylesheet" type="text/css" href="css/input.css">
    <link rel="stylesheet" type="text/css" href="css/calendar.css">
    <script language="JavaScript" src="calendar_db.js"></script>
</head>

<?php include("config.php"); ?>

<body>

<?php

/* Config Script START */

    $current_year = 2010;

/* Config Script END */

    $date_today = date("Y-m-d");
    $day_number = date('w');
    $week_begin = date("Y-m-d",time() - ($day_number)*60*60*24);
    $last_week = $current_week - 1;
    $days[0] = 'Saturday';
    $days[1] = 'Sunday';
    $days[2] = 'Monday';
    $days[3] = 'Tuesday';
    $days[4] = 'Wednesday';
    $days[5] = 'Thursday';
    $days[6] = 'Friday';
    $time_now = date ('H:i:s');

    $result = mysql_query("SELECT booked_date FROM jobs WHERE YEAR(booked_date) = $current_year GROUP BY WEEKOFYEAR(booked_date)");
    $numrows = mysql_num_rows($result);

    function getAgentAppsDay($agent_search,$day_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year' && agent_name = '$agent_search' && booked_date = '$day_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAgentAppsWeek($agent_search,$week_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year' && agent_name = '$agent_search' && WEEKOFYEAR(booked_date) = '$week_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAppsDay($day_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year' && booked_date = '$day_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAppsDayNumber($day_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year'&& DAYOFWEEK(booked_date) = '$day_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAppsWeek($week_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year' && WEEKOFYEAR(booked_date) = '$week_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAppsHour($hour_search,$current_year) {
        $result = mysql_query("SELECT * FROM apps WHERE YEAR(booked_date) = '$current_year' && HOUR(booked_time) = '$hour_search' ");
        $num_apps = mysql_numrows($result);
        return $num_apps;
    }

    function getAgentJobsWeek($agent_search,$week_search,$current_year) {
        $result = mysql_query("SELECT SUM(job_value) FROM jobs WHERE YEAR(booked_date) = '$current_year' && agent_name = '$agent_search' && WEEKOFYEAR(booked_date) = '$week_search' ");
        $row = mysql_fetch_array($result);
        return $row[0];
    }

    function getAgentPointsWeek($agent_search,$week_search,$current_year) {
        $result = mysql_query("SELECT SUM(points_value) FROM jobs WHERE YEAR(booked_date) = '$current_year' && agent_name = '$agent_search' && WEEKOFYEAR(booked_date) = '$week_search' ");
        $row = mysql_fetch_array($result);
        return $row[0];
    }
?>

<div id="container">

    <div id="header">
        <img src="images/logo.jpg" align="left">
        <img src="images/logo.jpg" align="right">
        <h3>Reports - Yearly Summary 2010</h3>
    </div>

    <div align="center">
        <form class="menu">
            <input type="button" class="btn" value="Log-Out" onClick="parent.location='index.php'"> //
            <input type="button" class="btn" value="This Week/Last Week" onClick="parent.location='reporting.php'"> -
            <input type="button" class="btn" value="This Month/Last Month" onClick="parent.location='reporting_month.php'"> -
            <input type="button" class="btn" value="Yearly Summary 2011" onClick="parent.location='reporting_2011.php'"> -
            <input type="button" class="btn" value="Yearly Summary 2010" onClick="parent.location='reporting_2010.php'"> -
            <input type="button" class="btn" value="Yearly Summary 2009" onClick="parent.location='reporting_2009.php'">
        </form>
    </div>

    <div id="message">
        <?php echo $message.'Year: '.$current_year.', Number of Weeks: '.$numrows;?>
    </div>

    <div id="reports">
    <table align="center">
    <tr>
    <td valign="top">
        <p align="center">Summary of job booking times by hour</p>
        <table cellpadding=10>
            <colgroup style="width: 80px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Hour</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>

<?php

    $hour = 9;
    $i = 0;
    while ($hour < 18){
        $hourresult = mysql_query("SELECT SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year && HOUR(booked_time) = $hour");
        $row = mysql_fetch_array($hourresult);
        $num_per_hour = mysql_numrows($hourresult);
        $i++;
?>

            <tr class="tr<?php echo ($i & 1) ?>">
                <td style="font-weight: bold;"><?php echo $hour; ?></td>
                <td><?php echo $row['SUM(job_value)'] ?></td>
                <td><?php echo $row['SUM(points_value)'] ?></td>
                <td><?php echo getAppsHour($hour,$current_year); ?></td>
            </tr>

<?php 

      $hour++;
    }
?>

        </table>
    </td>
    <td valign="top">
        <p align="center">Summary of job booking times by day</p>
        <table cellpadding=10>
            <colgroup style="width: 120px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Day</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>

<?php

    $day = 2;
    $i = 0;
    while ($day < 7){
        $dayresult = mysql_query("SELECT SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year && DAYOFWEEK(booked_date) = $day");
        $row = mysql_fetch_array($dayresult);
        $num_per_hour = mysql_numrows($dayresult);
        $i++;
?>

            <tr class="tr<?php echo ($i & 1) ?>">
                <td style="font-weight: bold;"><?php echo $days[$day] ?></td>
                <td><?php echo $row['SUM(job_value)'] ?></td>
                <td><?php echo $row['SUM(points_value)'] ?></td>
                <td><?php echo getAppsDayNumber($day,$current_year); ?></td>
            </tr>
<?php

    $day++;
    }
?>

        </table>
    </td>
    <td valign="top">
        <p align="center">Summary of weekly results</p>
        <table cellpadding=10>
            <colgroup style="width: 80px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Week</td>
                <td>Starting</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>
<?php

    $weeklyresult = mysql_query("SELECT booked_date, SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year GROUP BY WEEKOFYEAR(booked_date) ORDER BY booked_date DESC");
    $i = 0;
    while ($row = mysql_fetch_array($weeklyresult)){
        $appsweek = $row['booked_date'];
        $weeknum = date('W', strtotime($appsweek));
        $starting = date('d/m/Y', strtotime($appsweek));
        $number_of_apps = getAppsWeek($weeknum,$current_year);
        $i++;
?>

            <tr class="tr<?php echo ($i & 1) ?>">
                <td style="font-weight: bold;"><?php echo $weeknum ?></td>
                <td><?php echo $starting ?></td>
                <td><?php echo $row['SUM(job_value)'] ?></td>
                <td><?php echo $row['SUM(points_value)'] ?></td>
                <td><?php echo $number_of_apps ?></td>
            </tr>
<?php

    }
?>

        </table>
    </td>
    </tr>
    </table>
    <table align="center">
    <tr>
    <td valign="top">

<?php

    $agentresult = mysql_query("SELECT DISTINCT agent_name FROM jobs WHERE YEAR(booked_date) = '$current_year' ORDER BY agent_name ASC");
    while ($row = mysql_fetch_array($agentresult)){
        $agentname = $row['agent_name'];
?>
        <p align="center"><?php echo $agentname ?></p>
        <table cellpadding=10>
            <colgroup style="width: 80px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Week</td>
                <td>Starting</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>

<?php

    $agentresult2 = mysql_query("SELECT booked_date, SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year && agent_name = '$agentname' GROUP BY WEEKOFYEAR(booked_date) ORDER BY booked_date DESC");
    $i = 0;
    while ($row = mysql_fetch_array($agentresult2)){
        $appsweek = $row['booked_date'];
        $weeknum = date('W', strtotime($appsweek));
        $starting = date('d/m/Y', strtotime($appsweek));
        $number_of_apps = getAgentAppsWeek($agentname,$weeknum,$current_year);
        $i++;
?>

        <tr class="tr<?php echo ($i & 1) ?>">
            <td style="font-weight: bold;"><?php echo $weeknum ?></td>
            <td><?php echo $starting ?></td>
            <td><?php echo $row['SUM(job_value)'] ?></td>
            <td><?php echo $row['SUM(points_value)'] ?></td>
            <td><?php echo $number_of_apps ?></td>
        </tr>

<?php

    }
?>

        </table>

<?php

    }
?>
    </td>
    <td width="100px">
    </td>
    <td valign="top">
<?php

    $weeknumresult = mysql_query("SELECT booked_date FROM jobs WHERE YEAR(booked_date) = $current_year GROUP BY WEEKOFYEAR(booked_date) ORDER BY booked_date DESC");
    while ($row = mysql_fetch_array($weeknumresult)){
        $appsweek = $row['booked_date'];
        $weeknum = date('W', strtotime($appsweek));
?>

        <p align="center">Week No. <?php echo $weeknum; ?>, Starting: <?php echo $starting; ?></p>
        <table cellpadding=10>  
            <colgroup style="width: 120px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Day</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>

<?php

    $weeknumresult2 = mysql_query("SELECT booked_date, SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year && WEEKOFYEAR(booked_date) = $weeknum GROUP BY booked_date ORDER BY booked_date ASC");
    $i = 0;
    while ($row = mysql_fetch_array($weeknumresult2)){
        $number_of_apps = getAppsDay($row['booked_date'],$current_year);
        $i++;
?>

            <tr class="tr<?php echo ($i & 1) ?>"> 
                <td style="font-weight: bold;"><?php echo date('l', strtotime($row['booked_date'])) ?></td>
                <td><?php echo $row['SUM(job_value)'] ?></td>
                <td><?php echo $row['SUM(points_value)'] ?></td>
                <td><?php echo $number_of_apps ?></td>
            </tr>

<?php

    }

    $weeknumresult3 = mysql_query("SELECT SUM(job_value), SUM(points_value) FROM jobs WHERE YEAR(booked_date) = $current_year && WEEKOFYEAR(booked_date) = $weeknum");
    $row = mysql_fetch_array($weeknumresult3);
    $number_of_apps = getAppsWeek($weeknum,$current_year);
?>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Total</td>
                <td><?php echo $row['SUM(job_value)']; ?></td>
                <td><?php echo $row['SUM(points_value)']; ?></td>
                <td><?php echo $number_of_apps; ?></td>
            </tr>
        </table>
        <br/>
        <table cellpadding=10>
            <colgroup style="width: 120px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 100px"></colgroup>
            <colgroup style="width: 80px"></colgroup>

            <tr bgcolor='#ff6600' style="text-align: center; font-weight: bold">
                <td>Agent</td>
                <td>Jobs</td>
                <td>Points</td>
                <td>Apps</td>
            </tr>

<?php

    $agentsquery = ("
    CREATE TEMPORARY TABLE LeaderBoard (
        `agent_name` varchar(20) NOT NULL,
        `job_number` int(5) NOT NULL,
        `job_value` decimal(3,1) NOT NULL,
        `points_value` decimal(8,2) NOT NULL
    );
    INSERT INTO LeaderBoard (`agent_name`, `job_number`, `job_value`, `points_value`) SELECT agent_name, job_number, job_value, points_value FROM jobs WHERE YEAR(booked_date) = $current_year && WEEKOFYEAR(booked_date) = $weeknum;
    INSERT INTO LeaderBoard (`agent_name`) SELECT DISTINCT agent_name FROM apps WHERE YEAR(booked_date) = $current_year && WEEKOFYEAR(booked_date) = $weeknum;
    SELECT agent_name, SUM(job_value), SUM(points_value) FROM leaderboard GROUP BY agent_name ORDER BY SUM(points_value) DESC
    ");
    $i = 0;
    while ($row = mysql_fetch_array($agentsquery)){
        $number_of_apps = getAgentAppsWeek($row['agent_name'],$weeknum,$current_year);
        $i++;
?>

            <tr class="tr<?php echo ($i & 1) ?>">
                <td style="font-weight: bold;"><?php echo $row['agent_name'] ?></td>
                <td><?php echo $row['SUM(job_value)'] ?></td>
                <td><?php echo $row['SUM(points_value)'] ?></td>
                <td><?php echo $number_of_apps; ?></td>
            </tr>

<?php

    }
?>

        </table>

<?php

    }

    mysql_close($con);
?>

    </td>
    </tr>
    </table>
    </div>
</div>
<br/>
</body>
</html>
  • 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-19T02:40:20+00:00Added an answer on May 19, 2026 at 2:40 am

    The mysql_query() function cannot run multiple queries (see http://docs.php.net/manual/en/function.mysql-query.php). You need to run each query separately.

    Alternatively, use MySQLi::multi_query() (see http://docs.php.net/manual/en/mysqli.multi-query.php).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.