runnerjp Posted March 3, 2010 Share Posted March 3, 2010 Hey i have my forum set up and i want to have a number next to the post.. e.g #2 #3# ect Below is my array and the page displayed for each array $getreplies = "Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime $max"; //getting replies $getreplies2=mysql_query($getreplies) or die(mysql_error() . "Could not get replies"); while ($getreplies3=mysql_fetch_array($getreplies2)) { ?><br /> <table width = "90%" align="center" cellpadding = "0" cellspacing = "0" > <tr> <td> <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin"> <tr> <td colspan="3" align="right" class = 'border'> <table width="100%"> <tr> <td width="15%" align="left"><font size="2" color="white"> <?php foreach(array_keys($getreplies2) as $key){ echo $key ." ". $getreplies2[$key]."<br>"; } ?> <a name="<?php echo $getreplies3['postid'] ?>"> </a><a href ='http://www.runningprofiles.com/members/index.php?page=message&forum=<?php echo $forum ?>&id=<?php echo $forumpostid ?>#<?php echo $getreplies3['postid'] ?>'><strong>RE: <? echo $gettopic3[title] ?></strong></a></span></font></td> <td width="32%" align="left"> </td> <td width="33%" align="right"><font size="2" color="white">» Replied obv more below but you only need to see code above really. Where it says : <?php foreach(array_keys($getreplies2) as $key){ echo $key ." ". $getreplies2[$key]."<br>"; } ?> i wanted it to display the array number but also i need it to start from #2. Is any 1 able to help? Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/ Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 Is it displaying the array number now? If it is then all you have to do is slip in if statement in there ofc to test if the $key is < 2 Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1020957 Share on other sites More sharing options...
runnerjp Posted March 3, 2010 Author Share Posted March 3, 2010 No i just get: Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/runningp/public_html/members/include/message.php on line 271 Warning: Invalid argument supplied for foreach() in /home/runningp/public_html/members/include/message.php on line 271 Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1020960 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 No i just get: Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/runningp/public_html/members/include/message.php on line 271 Warning: Invalid argument supplied for foreach() in /home/runningp/public_html/members/include/message.php on line 271 Silly goose you need to put it into an array. A result set is not a traditional array. Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1020962 Share on other sites More sharing options...
runnerjp Posted March 3, 2010 Author Share Posted March 3, 2010 Would i just add arry() around it? Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1020977 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 Would i just add arry() around it? No you would do something like this $arr = array(); while($row = mysql_fetch_assoc($resultset)){ $arr[] = $row; } Then all ur stuff will be in the $arr array Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1020983 Share on other sites More sharing options...
runnerjp Posted March 4, 2010 Author Share Posted March 4, 2010 ok i have tried this... $counter2 = 0; $counter2++; $getreplies = "Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime $max"; //getting replies $getreplies2=mysql_query($getreplies) or die(mysql_error() . "Could not get replies"); while ($getreplies3=mysql_fetch_array($getreplies2)) { ?><br /> <table width = "90%" align="center" cellpadding = "0" cellspacing = "0" > <tr> <td> <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin"> <tr> <td colspan="3" align="right" class = 'border'> <table width="100%"> <tr> <td width="15%" align="left"><font size="2" color="white"> <?php echo $counter2; ?> put it just has 1 on them all Link to comment https://forums.phpfreaks.com/topic/194009-counting-arrays/#findComment-1021374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.