2012-05-11 42 views
0

互聯網上的工作我得到了託管在網絡上這樣的警告,頁面上的報告(小時-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 

我的問題是: 的腳本工作正常我的localhost >>在我的電腦上 雖然不工作在互聯網託管!!!!!

這是頁面

<?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(); 

?> 

請幫助我:(

+1

數據庫資源在哪裏? – k102

+1

顯示你的'config.php' – Norse

+0

你的數據庫連接可能沒有成功。 – halfer

回答

1

我懷疑是這些中的任何一個的價值:$ tab,teacher,hours。
他們需要完全匹配您的主機。

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

謝謝,解決了,問題出在$ tab =「Report $ year $ sem」; 它應該是$ tab =「report $ year $ sem」; 只有R >> r 非常感謝您對Mr.adydy :) – Hatim

+0

@歡迎您的光臨,歡呼:) – adydy

-1

確定查詢成功,您應該檢查是否有錯誤?

if (mysql_query($sql)) 
{ 
    // your code 
} 
else 
{ 
    die(mysql_error()); 
} 
+0

我這樣做了,我得到了這個錯誤 – Hatim

+0

這在你的代碼中並不明顯。正如Carlos提到的那樣,您應該只包含相關代碼以及db連接所在的代碼。如果這段代碼在你的測試系統上正常工作,並且你的數據庫在測試系統和產品系統上都是一樣的話,那就意味着我能想到的唯一問題就是MySQL連接問題。 – Julien

+0

我改變了$結果Gokhan Ozturk說,我得到了這個問題,報告年學期錯誤:表'hatimmak_ssp.Report'不存在 – Hatim

相關問題