I am building an application that gives user the opportunity to click on the day of the calendar and when there is an activity registered on that day, it shows a table with the activity registered...my problem is that when there is no activity on that day, I wont it to return the string : There is no activity.. I try to make it using if($nrofrows>0)
like below but all the time it returns me the string :there is not activity, even I have activity on that day. Please can you help me ? where is my error? Thanks in advance...
<body>
<?php
mysql_connect("127.0.0.1","root","") or die("Smund te lidhet me serverin");
mysql_select_db("axhenda") or die("Kjo databaze nuk u gjet");
session_start();
$perdoruesi=$_SESSION['user_id'];
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Perd_Id='$perdoruesi'");
$nrofrows= mysql_num_rows($result);
if($nrofrows>0)
{
?>
<div class="title"> Aktivitetet per daten <?php print ("$_POST[dataoutput]"); ?></div>
<form name="form1" method="post" action="delete.php">
<table >
<th>
<th ><strong>Emri </strong></th>
<th ><strong>Pershkrimi </strong></th>
<th><strong>Ora</strong></th>
</th>
<?php
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td ><input name="checkbox[]" type="checkbox" value="<?php echo $row['Id_Akt']; ?>"></td>
<td style="font-size:0.9em"><?php echo $row['Emri']; ?></td>
<td ><?php echo $row['Pershkrimi']; ?></td>
<td><?php echo $row['Ora']; ?></td>
</tr>
<?php
}
?>
</table>
<input class="button" name="delete" type="submit" value="Delete" style="margin-left:40%; margin-top:100px; width:15%">
</form>
<?php
}
else {
echo "<span id='errorformat'>There is no activity on this day!<span>";}
?>
</body>
</html>
Might be a problem with the query you can add this to see:
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Perd_Id='$perdoruesi'") or die ("query error" .mysql_error());
mysql_num_rows($result) returns false when there is an error so you might want to add this:
if($nrofrows && $nrofrows>0)
try this
if ( mysql_num_rows($result) > 0 ) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.