...

View Full Version : mysql_num_rows problem



hassanab
09-06-2009, 09:08 AM
I have problem in mysql_num_rows
$qr = "select * from faqs where inis_no='$inis' and course_no='$cid'";
$res = mysql_query($qr) or die(mysql_error())
if (mysql_num_rows($res) == 0)
{
code block 1;
}
else
{
code block2;
}
it give me code block 1 but the mysql database has number of rows not 0
A complete code
faqs.php


<?php
session_start();
@ob_start();
?>
<html>
<head>
<title>Welcome to BioChemistryOnline.edu</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="1.css" type="text/css">
<SCRIPT language="JavaScript">
function setHomepage(myElement)
{
myElement.style.behavior='url(#default#homepage)';
myElement.setHomepage('http://www.biochemistryonline.edu');
return false;
}
</SCRIPT>
</head>

<body>
<table width="90%" height="100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5"><img src="images/banner3.jpg" width="100%" height="120"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="3">&nbsp;<a href="index.php"><strong><font face="Verdana, Arial, Helvetica, sans-serif">Home</font></strong></a><font face="Verdana, Arial, Helvetica, sans-serif"><strong>
&nbsp;&nbsp; <a href="about.php">About Us</a> &nbsp;&nbsp;<a href="contact.php">Contact
Us</a></strong></font></td>
</tr>
<tr>
<td colspan="5"><hr></td>
</tr>
<tr>
<td width="20%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="75%" colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="20%" valign="bottom"><img src="images/side_m_top.jpg" width="100%" height="20" align="bottom"></td>
<td width="5%" valign="bottom">&nbsp;</td>
<td width="75%" colspan="3">
<?php
include 'main.php';
$link = bio_connect();
$cid=$_GET['cid'];
$res = mysql_query("select * from courses where course_no='$cid'")or die(mysql_error());
while ($row=mysql_fetch_array($res))
{
$course_name = $row[course_name];
$desc = $row[course_desc];
$image = $row[course_img];
}
echo"<h2>Frequently Asked Questions of&nbsp;<font color='#8e9bb8'>$course_name</font>&nbsp;Course</h2></td>";
?>
</tr>
<tr>
<td width="20%" valign="top" bordercolor="#FFFFFF" background="images/bg.jpg">
<table width="100%" border="0">
<tr>
<td>
<?php
if (is_null($_SESSION['user']))
{
header("Location: index.php");
exit();
}
else
{
$user = $_SESSION['user'];
$name = $_SESSION['name'];
$ut = $_SESSION['ut'];
$inis = $_SESSION['inis'];
if ($ut == 's')
$type = "Student";
else
$type ="Teacher";
echo "<strong>Current $type <br><font color='#DEDEC7'> $name</font></strong>";
$res = mysql_query("select * from inistitutes where inis_no='$inis'")or die(mysql_error());
while($row=mysql_fetch_array($res))
{
$university = $row[inis_name];
$college = $row[college];
}
}
?>
</td>
</tr>
<tr>
<td> <strong><font color="#0000FF" face="Verdana, Arial, Helvetica, sans-serif">Courses
Available</font></strong> <br> <table cellpadding="0" cellspacing="0" width="100%">
<?php
$qr = "select std_level from students where std_no='$user'";
$res = mysql_query($qr)or die(mysql_error());
while ($row=mysql_fetch_array($res))
{
$level = $row[std_level];
}
$qr = "select course_no from inis_courses where inis_no='$inis' and std_level='$level'";
$res = mysql_query($qr)or die(mysql_error());
while ($row=mysql_fetch_array($res))
{
$course = $row[course_no];
$result = mysql_query("select course_name from courses where course_no='$course'")
or die(mysql_error());
while ($line = mysql_fetch_array($result))
{
echo"<tr><td width='20%'>&nbsp;</td>
<td width='80%'>
<font face='Verdana, Arial, Helvetica, sans-serif'><strong><a href='courses.php?cid=$course'>
$line[course_name]</a></strong></font></td></tr>";
}
}
?>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif"><strong><a href="mngAccount.php">Manage
My Account</a></strong></font></td>
</tr>
<tr>
<td><strong><a href="students.php">Students Home Page</a></strong></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif"><strong><a href="logout.php">Logout</a></strong></font></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center"><a href="http://www.saec-sd.org/" target="_blank"><img src="images/saec.jpg" width="140" height="40" border="0"></a></td>
</tr>
<tr>
<td></td>
</tr>
</table></td>
<td width="5%" bordercolor="#FFFFFF">&nbsp;</td>
<td width="75%" colspan="3" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<?php
$qr = "select * from faqs where inis_no='$inis' and course_no='$cid'";
$res = mysql_query($qr) or die(mysql_error());
if (mysql_num_rows($res) == 0)
echo"<font size='+1'>Sorry, there is no question posted!.</font>";
else
{
$i = 1;
while ($row = mysql_fetch_array($res))
{
$user_post = $row[std_no];
$result = mysql_query("select std_name from students where std_no='$user_post'")or die(mysql_error());
while ($line = mysql_fetch_array($result))
{ $stname = $line[std_name]; }
if (strlen($row[faq_ans]) != 0)
{
echo"<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#0066FF'>
<tr>
<td bgcolor='#DBDBDB'><strong>Q#: $i</strong></td>
<td bgcolor='#DBDBDB'><strong>Posted By: </strong>$stname</td>
<td bgcolor='#DBDBDB'><strong>Post Date: </strong>$row[post_date]</td>
</tr>
<tr>
<td colspan='3'><strong>Question: </strong>$row[faq_question]</td>
</tr>
<tr>
<td colspan='3'><strong>Ansewr: </strong>$row[faq_ans]</td>
</tr>
</table>
<br>";
}
$i++;
}
}
?>
</td>
</tr>
<tr>
<td align="right" valign="bottom"><?php echo"<a href='post_ques.php?cid=$cid'>Post Your
Qouestion</a>"; ?></td>
</tr>
</table></td>
</tr>
<tr>
<td width="20%"><img src="images/side_m_bot.jpg" width="100%" height="20"></td>
<td width="150">&nbsp;</td>
<td>
<?php
$res = mysql_query("select std_group from students where std_no='$user'")or die(mysql_error());
while ($row=mysql_fetch_array($res))
{ $group = $row[std_group]; }
$res = mysql_query("select teach_no from teaching where inis_no='$inis' and course_no='$cid' and std_group='$group'")or die(mysql_error());
while ($row=mysql_fetch_array($res))
{ $teacher = $row[teach_no]; }
$res = mysql_query("select tname from teachers where teach_no='$teacher'")or die(mysql_error());
while ($row=mysql_fetch_array($res))
{
echo"<a href='contact_teach.php?tid=$teacher&&cid=$cid'>Contact Tutor: $row[tname]</a>";
}
?>
</td>
<td align="center"><?php echo"<a href='faqs.php?cid=$cid'>Course FAQs</a>"; ?></td>
<td align="right"><?php echo"<a href='courses.php?cid=$cid'>Back to Course Outlines</a>"; ?></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td width="150">&nbsp;</td>
<td colspan="3"><div align="right">
<SCRIPT type=text/javascript>
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Microsoft Internet Explorer"))
{
document.write('<a href="#" onclick="setHomepage(this)"><font size="1">Make BiochemistryOnline.edu my homepage!</font></a>');
}
</SCRIPT>
&nbsp;</div></td>
</tr>
<tr bgcolor="#8e9bb8">
<td colspan="5"><div align="center"><strong>Copyrights &copy; 2005-2006 BiochemistryOnline.edu.
All Rights Reserved.&nbsp;&nbsp;<a href="link.htm">About Us</a>, <a href="link.htm">Contact</a></strong></div></td>
</tr>
</table>
</body>
</html>

Phil Jackson
09-06-2009, 09:17 AM
try:



if (mysql_num_rows($res) != 0)
{
code block 2;
}
else
{
code block1;
}

hassanab
09-06-2009, 09:34 AM
I have uploaded wrong folder when I update $_GET['title']; it works fine
Thank you for help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum