一个网站已经传递给我和我的IT同班同学,我们目前在OJT上,最近我们正在处理一个Android项目。对此我们感到生疏和过时,请提供帮助。
-问题:警告:mysql_num_rows()期望参数1为资源,在第21行的C:\ xampp \ b \ htdocs \ alumni_mod \ admin \ dbOp.php中给出布尔值
<?php
include "db.php";
function dispAnnounce(){
$disp="";
adb();
$query=mysql_query("SELECT title,content FROM announce ORDER BY date_created DESC");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current announcement!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='aTitle'>".$row->title."</div>";
$disp.="<div id='aContent'>".$row->content."</div>";
}
}
endadb();
echo $disp;
}
function dispContent($content)/*this is line 21*/{
$disp="";
adb();
if ($content=="offname"){
$query=mysql_query("SELECT title,content FROM offname");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current official name!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}elseif ($content=="objective"){
$query=mysql_query("SELECT title,content FROM objective");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current objectives!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}elseif ($content=="ongoing"){
$query=mysql_query("SELECT title,content FROM ongoing");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current on going events!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}elseif ($content=="other"){
$query=mysql_query("SELECT title,content FROM other");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current other projects!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}elseif ($content=="sec"){
$query=mysql_query("SELECT title,content FROM sec order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current SEC!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}elseif ($content=="upcoming"){
$query=mysql_query("SELECT title,content FROM upcoming order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current upcoming events!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="hist"){
$query=mysql_query("SELECT title,content FROM history");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current history!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='dTitle'>".$row->title."</div>";
$disp.="<div id='dContent'>".$row->content."</div>";
}
}
}
elseif ($content=="law"){
$query=mysql_query("SELECT title,content FROM law order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current By Laws!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="foun"){
$query=mysql_query("SELECT title,content FROM founofficer order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current foundation officers!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="col"){
$query=mysql_query("SELECT title,content FROM colofficer order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current college officers!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="hs"){
$query=mysql_query("SELECT title,content FROM hs order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current past events!!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="scholar"){
$query=mysql_query("SELECT title,content FROM scholar order by id desc");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current scholar!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="contact"){
$query=mysql_query("SELECT title,content FROM contact");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current contacts!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="elem"){
$query=mysql_query("SELECT title,content FROM elemofficer");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current elementary officers!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
elseif ($content=="aqueen"){
$query=mysql_query("SELECT title,content FROM aqueen ORDER BY date_created DESC");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No current alumni queen!";
}
else {
for($j=1;$j<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
/*this part here is what I'm going to add*/
elseif($content=="former"){
$query=mysql_query("SELECT title,content FROM formerpres");
$limit=mysql_num_rows($query);
if ($limit==0){
$disp.="No former president!";
}
else{
for($j=1;<=$limit;$j++){
$row=mysql_fetch_object($query);
$disp.="<div id='hTitle'>".$row->title."</div>";
$disp.="<div id='hContent'>".$row->content."</div>";
}
}
}
endadb();
return $disp;
} ?>
/*db.php*/
<?php
function adb(){
global $con;
try {
$host = "localhost";
$user = "webalumni";
$pwd = "s1j2c3a4l5u6m7n8i9";
$db = "alumnidb";
$con = mysql_connect($host,$user,$pwd);
$select = mysql_select_db($db, $con);
}
catch(Exception $e){
echo "Error Found:";
}
}
function endadb(){
global $con;
mysql_close($con);
}
?>
答案 0 :(得分:0)
对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()成功时返回资源,错误时返回FALSE。
因此,很可能查询是错误的。
我希望我有所帮助:)