PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 8th, 2002, 12:57 PM
Blake Blake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 125 Blake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
mysql_num_rows()

Can anyone tell me why $num_results returns 1 even when there are more than 1 result displayed on the page? If there are 0 results then 0 is displayed correctly.

Here is the code
php Code:
Original - php Code
  1.  
  2. dbconnect();
  3.     mysql_select_db($mysql_dbase);
  4.    
  5.     $sql = "SELECT * FROM $table WHERE status = 'New'";
  6.     $result = mysql_query($sql);
  7.    
  8.     $num_results = mysql_num_rows($result);
  9.        
  10.         if ($num_results != 0)
  11.         {
  12.        
  13.         if($num_results = 1)
  14.         {
  15.             $grammar1 = "is";
  16.             $grammar2 = "request";
  17.         }
  18.         else
  19.         {
  20.             $grammar1 = "are";
  21.             $grammar2 = "requests";
  22.         }
  23.        
  24.         page_header();
  25.         ?>
  26.         <tr>
  27.     <td height="370" align="center" valign="top"> <div align="right" class="vsmall">Logged in
  28.         as <?php echo $fname ?> <?php echo $sname ?><br>
  29.       </div>
  30.       <table width="95%" border="0" cellspacing="0" cellpadding="0">
  31.         <tr>
  32.           <td width="16%"><div align="center" class="tbldata"><img src="../images/down-unassrqsts.gif" width="132" height="21"></div></td>
  33.           <td width="2%">&nbsp;</td>
  34.           <td width="16%"><div align="center" class="tbldata"><a href="myqueue.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('myqueue','','../images/down-<?php echo $fname ?>.gif',1)"><img src="../images/up-<?php echo $fname ?>.gif" alt="<?php echo $fname ?>'s queue" name="myqueue" width="132" height="21" border="0"></a></div></td>
  35.           <td width="2%">&nbsp;</td>
  36.           <td width="16%"><div align="center"><a href="business.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('business','','../images/down-business.gif',1)"><img src="../images/up-business.gif" alt="Business Travel Requests" name="business" width="132" height="21" border="0"></a></div></td>
  37.           <td width="2%"><div align="center"></div></td>
  38.           <td width="16%"><div align="center"><a href="reports.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('reports','','../images/down-reports.gif',1)"><img src="../images/up-reports.gif" alt="View reports" name="reports" width="132" height="21" border="0"></a></div></td>
  39.           <td width="2%">&nbsp;</td>
  40.           <td width="16%"><div align="center"><a href="logout.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('logout','','../images/down-logout.gif',1)"><img src="../images/up-logout.gif" alt="Logout" name="logout" width="132" height="21" border="0"></a></div></td>
  41.         </tr>
  42.       </table>
  43.       <br>
  44.       <table width="95%" border="0" cellspacing="0" cellpadding="0">
  45.         <tr>
  46.           <td colspan="4" class="tbldata">There <?php echo $grammar1 ?> currently <?php echo $num_results ?> new
  47.             travel <?php echo $grammar2 ?> awaiting to be assigned and actioned.</td>
  48.         </tr>
  49.         </table>
  50.         <br>
  51.         <table width="95%" cellspacing="0" cellpadding="0"border="1" bordercolor="#800000">
  52.         <tr class="tbldata">
  53.           <td><div align="center"><strong>Request ID</strong></div></td>
  54.           <td><div align="center"><strong>Request By</strong></div></td>
  55.           <td><div align="center"><strong>Date of Departure</strong></div></td>
  56.           <td><div align="center"><strong>Outbound Route</strong></div></td>
  57.           <td><div align="center"><strong>Date / Time of Request</strong></div></td>
  58.         </tr>
  59.         <?php
  60.         while($request_data = mysql_fetch_array($result))
  61.         {
  62.             $ID = $request_data['id'];
  63.             $StaffName = $request_data['staffname'];
  64.             $DateOfDeparture = $request_data['dod'];
  65.             $OutboundRoute = $request_data['flight_route1'];
  66.             $DateOfRequest = $request_data['date_of_request'];
  67.             $TimeOfRequest = $request_data['time_of_request'];
  68.         ?>
  69.         <tr class="tbldata">
  70.           <td><div align="center"><a href="assign.php?id=<?php echo $ID ?>" class="tbldata">000<?php echo $ID ?></a></div></td>
  71.           <td><div align="center"><?php echo $StaffName ?></div></td>
  72.           <td><div align="center"><?php echo $DateOfDeparture ?></div></td>
  73.           <td><div align="center"><?php echo $OutboundRoute ?></div></td>
  74.           <td><div align="center"><?php echo $DateOfRequest ?> <em>[<?php echo $TimeOfRequest ?>]</em></div></td>
  75.         </tr>
  76.         <?php
  77.         }
  78.         ?>
  79.       </table>
  80.     </td>
  81.   </tr>
  82. </table>
  83.         <?php
  84.         page_footer();   
  85.         }
  86.         else
  87.         {
  88. echo "No results";
  89. }

Reply With Quote
  #2  
Old November 8th, 2002, 01:13 PM
Blake Blake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 125 Blake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: mysql_num_rows()

Cracked it...
php Code:
Original - php Code
  1.  
  2. dbconnect();
  3.    
  4.     $result = mysql_query("SELECT * FROM $table WHERE status = 'New'");
  5.    
  6.     $num_results = mysql_num_rows($result);
  7.        
  8.         if ($num_results != 0)
  9.         {
  10.        
  11.         if($num_results != 1)
  12.         {
  13.             $grammar1 = "are";
  14.             $grammar2 = "requests";
  15.         }
  16.         else
  17.         {
  18.             $grammar1 = "is";
  19.             $grammar2 = "request";
  20.         }

etc...

Reply With Quote
  #3  
Old November 8th, 2002, 06:02 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: mysql_num_rows()

For future reference, if you wanted to use your original structure, you need to use the comparison operator '=='. Using '=' in your 'if' statement was assigning a value of '1' to 'num_results' instead of checking to see what it's value was.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > mysql_num_rows()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT