Jump to content

counting arrays


runnerjp

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.