0

我在虚拟主机上收到此警告,页面 (report-hours-male.php) 如下

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hatimmak/public_html/ssp12/report-hours-male.php on line 28

我的问题是:该脚本在我的计算机上的本地主机 >> 上运行良好,而不能在互联网托管上运行!!!!!

这是页面

    <?php


include 'config.php';

?><BR>

Report for year <?php echo $_SESSION['year']; ?>  semester <?php echo $_SESSION['sem']; ?>  

<?php
 // list of teachers Table rows and total hours

echo "<table border='0' id='hor-minimalist-b' >
<tr>
<th scope='col'>Instructor name</th>
<th scope='col'>Total hours for this semester</th>
</tr>"; 


        //$gender = $_SESSION['gender'];
        $year = $_SESSION['year'];
        $sem = $_SESSION['sem'];

        $tab = "Report$year$sem";
        $query = "SELECT teacher, SUM(hours) FROM $tab GROUP BY teacher"; 
        $result = mysql_query($query) ;



while($row = mysql_fetch_array($result))
{


        $time = gmdate(DATE_RFC822);

        //$gender = $_SESSION['gender'];
        $year = $_SESSION['year'];
        $sem = $_SESSION['sem'];
        //$teacher = $_row['teacher'];
        //$sumhours = $_row['SUM(hours)'];



echo "<tr>";
echo "<td> ". $row['teacher']." </td>";
echo "<td> ". $row['SUM(hours)']." </td>";

echo "</tr>";
}
echo "</table>";

?>

<!--chart-->
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'hours');
        data.addRows([

<?php


        $queryr = "SELECT teacher, SUM(hours) FROM $tab GROUP BY teacher"; 
        $resultr = mysql_query($queryr) ;

while($rowr = mysql_fetch_array($resultr))
{
        $teacherr = $_rowr['teacher'];
        $sumhoursr = $_rowr['SUM(hours)'];


echo "['".$rowr['teacher']."' , ".$rowr['SUM(hours)']."]," ;
}

?>
          ['', 0]


        ]);

        // Set chart options

        var options = {'title':'Contact hours/instructor',
                'legend':'left',
                'is3D':true,

                'width':800,
                'height':300};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);
        }
    </script>

  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <center><div id="chart_div"></div></center>

   <form>
<input type="button" value="Print This Report" onclick="window.print();">  </form>

  </body>
</html>

<?php

ob_end_flush();

?>

这是 config.php

<?php

$con = mysql_connect("localhost","hatimmak_ssp","userpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$sel = mysql_select_db("hatimmak_ssp", $con) or die();

?>

请帮帮我 :(

4

2 回答 2

1

我怀疑是这些中的任何一个的值:$tab、老师、小时。
它们需要在您的主机上完全匹配。

    $tab = "Report$year$sem";
    $query = "SELECT teacher, SUM(hours) FROM $tab GROUP BY teacher"; 
于 2012-05-11T08:11:39.893 回答
-1

你确定查询成功了吗?您应该检查错误:

if (mysql_query($sql))
{
    // your code
}
else 
{
    die(mysql_error());
}
于 2012-05-11T07:48:01.557 回答