rashmi_k28 Posted March 20, 2008 Share Posted March 20, 2008 How to add the serial number from 1. When I use $i=1 and $cnt=count(records)+1 and use the value of $cnt in for loop the first entry from the table is not printed. for($i=0;$i<=count($rec);$i++){ $data=split("#",$rec[$i]); echo "<tr>"; echo "<td>$i</td>"; } Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/ Share on other sites More sharing options...
uniflare Posted March 20, 2008 Share Posted March 20, 2008 not quite sure what you mean, also never use count in a for loop argument, it counts it every time, count before hand and store to a variable (eg, $x), like so: $x = count($rec); for($i=0;$i<$x;$i++){ also try "print_r($rec); before the $x variable i just noted. this will print the complete array, hopefully will give you some answers. hope this helps, Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496646 Share on other sites More sharing options...
rashmi_k28 Posted March 20, 2008 Author Share Posted March 20, 2008 In the table of <td> I have to add the serial number counting from 1 to n rows. Now I have used $i inside <td> but serial number is printed from 0 to n rows. How to make the serial number from 1 to n+1 numbers Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496652 Share on other sites More sharing options...
uniflare Posted March 20, 2008 Share Posted March 20, 2008 i think i get u: $x = count($rec) + 1; for($i=1;$i<$x;$i++){ Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496653 Share on other sites More sharing options...
sasa Posted March 20, 2008 Share Posted March 20, 2008 change echo "<td>$i</td>"; to echo "<td>".$i+1."</td>"; Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496656 Share on other sites More sharing options...
rashmi_k28 Posted March 20, 2008 Author Share Posted March 20, 2008 I am getting error as PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' when I use code as echo "<td>'".$i+1."'</td>"; Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496660 Share on other sites More sharing options...
sasa Posted March 20, 2008 Share Posted March 20, 2008 ups i mean echo "<td>".($i+1)."</td>"; Link to comment https://forums.phpfreaks.com/topic/97061-serial-number/#findComment-496748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.