gwolff2005 Posted March 28, 2011 Share Posted March 28, 2011 Hi guys, I want to count the number of rows in a table and want to display them. However that field stays empty. Everythign else works. What do I do wrong? <?php //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="25" align="center"><span class="style2">No.</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="342" align="center"><span class="style2">school</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['num_rows']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/231981-count-rows/ Share on other sites More sharing options...
Maq Posted March 28, 2011 Share Posted March 28, 2011 You already have the number of rows held in a separate variables ($num_rows). Change: echo $rows['num_rows']; ?> to Link to comment https://forums.phpfreaks.com/topic/231981-count-rows/#findComment-1193394 Share on other sites More sharing options...
gwolff2005 Posted March 28, 2011 Author Share Posted March 28, 2011 Hi Maq, thanks, but I think I did not explain myself correctly, because now it shows in every column the total amount of rows. I want that it counts 1,2,3,4,etc... Link to comment https://forums.phpfreaks.com/topic/231981-count-rows/#findComment-1193395 Share on other sites More sharing options...
Maq Posted March 28, 2011 Share Posted March 28, 2011 Oh yeah sorry. I don't think you want to use a COUNT or num_rows function here. You would either want to use a variable that increments its value in the loop or the user_id from your table. Link to comment https://forums.phpfreaks.com/topic/231981-count-rows/#findComment-1193397 Share on other sites More sharing options...
sasa Posted March 28, 2011 Share Posted March 28, 2011 change $num_rows=mysql_num_rows($result); to $num_rows=1; and <td><span class="style10"><?php echo $num_rows ?></span></td> to <td><span class="style10"><?php echo $num_rows++; ?></span></td> Link to comment https://forums.phpfreaks.com/topic/231981-count-rows/#findComment-1193421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.