Sleeper Posted February 16, 2011 Share Posted February 16, 2011 I am pulling data from an sql data base. I want it to displayed (Item # | Error button | Link) however as its looping with a while on the database info I cant seem to get it to loop on the item number so it shows 1, 2, 3,.... on each row. Current coding is: while ($info = mysql_fetch_array($data)){ Print '<tr>'; Print"<td style='width: 15px;' class='cat-list'>$D</td>"; if ($info['id']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list' style='width: 20px;'><img border='0' src='images/error.png' width='16' height='16'></td>"; } if ($info['link']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list'><a target='_blank' href='".html_entity_decode(stripslashes($info[link]))."'>".substr(html_entity_decode(stripslashes($info[link])), 0, 85)."</a></td>"; } } How would I get the $D item to show 1 2 3... ect? Thanks, Jim Link to comment https://forums.phpfreaks.com/topic/227826-looping-help/ Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 while ($info = mysql_fetch_array($data)){ $D = $info['id']; Print '<tr>'; Print"<td style='width: 15px;' class='cat-list'>$D</td>"; if ($info['id']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list' style='width: 20px;'><img border='0' src='images/error.png' width='16' height='16'></td>"; } if ($info['link']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list'><a target='_blank' href='".html_entity_decode(stripslashes($info[link]))."'>".substr(html_entity_decode(stripslashes($info[link])), 0, 85)."</a></td>"; } } Link to comment https://forums.phpfreaks.com/topic/227826-looping-help/#findComment-1174829 Share on other sites More sharing options...
Sleeper Posted February 16, 2011 Author Share Posted February 16, 2011 I don't want to use the id of the item as we may delete some now and then and then I would have something like 3,4,5,8 and that's not what I want. Link to comment https://forums.phpfreaks.com/topic/227826-looping-help/#findComment-1174830 Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 $D = 1; while ($info = mysql_fetch_array($data)){ Print '<tr>'; Print"<td style='width: 15px;' class='cat-list'>$D</td>"; if ($info['id']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list' style='width: 20px;'><img border='0' src='images/error.png' width='16' height='16'></td>"; } if ($info['link']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list'><a target='_blank' href='".html_entity_decode(stripslashes($info[link]))."'>".substr(html_entity_decode(stripslashes($info[link])), 0, 85)."</a></td>"; } $D++; } Link to comment https://forums.phpfreaks.com/topic/227826-looping-help/#findComment-1174832 Share on other sites More sharing options...
Sleeper Posted February 16, 2011 Author Share Posted February 16, 2011 That worked. Ty Link to comment https://forums.phpfreaks.com/topic/227826-looping-help/#findComment-1174835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.