Re: [weekendphp:2781] Creating a list in PHP

1 view
Skip to first unread message

vikas dwivedi

unread,
Feb 5, 2013, 8:33:58 AM2/5/13
to WEEKEND
Hello Meher,

Please find your answer.


In that way you can create dynamic table in php .

regards !
vikas dwivedi 


On Tue, Feb 5, 2013 at 6:03 PM, Meher Bala <meher....@gmail.com> wrote:
Hi,

There is a PHP program which retrieves information from the database and displays to site visitors.
There is a column in the database in which a number is stored. This number will be from 1- 56.

On bases of that number, a for() loop is getting executed which creates a unordered list.

Here is the for() for my program:

<ul id="articleid">
<?php
for ($i=1; $i<=$m_article; $i++)
{
    if($i != 57)
    {
    ?>
    <li>
        <a href="/test?id=<?php echo $i; ?>">Day <?php echo $i; ?></a>
    </li>
    <?php
    }
}
?>
</ul>

Based on the for() loop give above this is the output.

Day 1
Day 2
Day 3
Day 4
Day 5
...
...
...
...
...
...
Day 56

Since it is a list all are coming one below the other.

What I want is to be able to display the list as follows:

Day 1            Day 21                 Day 41
Day 2            Day 22                 Day 42
Day 3            Day 23                 Day 43        
Day 4            Day 24                 Day 44     
Day 5            Day 25                 Day 45     
Day 6            Day 26                 Day 46     
Day 7            Day 27                 Day 47     
Day 8            Day 28                 Day 48     
Day 9            Day 29                 Day 49     
Day 10          Day 30                 Day 50      
Day 11          Day 31                 Day 51        
Day 12          Day 32                 Day 52        
Day 13          Day 33                 Day 53        
Day 14          Day 34                 Day 54        
Day 15          Day 35                 Day 55        
Day 16          Day 36                 Day 56        
Day 17          Day 37                 Day 57         
Day 18          Day 38                          
Day 19          Day 39                
Day 20          Day 40                

Can any one give me a suggestion on how do I archive this?

Any help will be appreciated.

Thank You.

--
Manage your settings from http://groups.google.com/groups/mysubs?pli=1
---
You received this message because you are subscribed to the Google Groups "Weekend php classes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weekendphp+...@googlegroups.com.
To post to this group, send email to weeke...@googlegroups.com.
Visit this group at http://groups.google.com/group/weekendphp?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Meher Bala

unread,
Feb 6, 2013, 5:30:17 AM2/6/13
to weeke...@googlegroups.com
Hi Vikas,

Thanks a lot for your help. Really appreciate the help.

I am unable to use the code provided by you.
Not sure if I correctly explained the problem.

Let me try explaining again. Here goes.

I am actually created a list of days based on the number stored in the database.

If a persons logs into the system and reads the content for that day, that number is stored in the database.
On the first day 1 will be stored in the database.
On the fourth fifth day 45 will be stored in the database.
NOTE: Only numbers are stored with user id in the database.

Based on the number received from the database a list is created.
Future days are not displayed.

If the value received from the database is 1, then it will be displayed as:
Day 1

If the value from the database received in 26, then it be displayed as:

Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
..
..
..
Day 26

If the value from the database received in 56, then it be displayed as:

Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
..
..
..
Day 56

There are only 56 days to be displayed.

Want I am trying to archive is:
First column should be from day 1 to day 20.
Second column should be from day 21 to day 40.
Third column should be from day 41 to day 56.

Here is my original code.

<div class="divCol">
    <span>Days:</span>
    <br /><br />
    <?php
        $qryUserLastArticle="SELECT * FROM assetchk WHERE user_id = '".$_COOKIE['cookie_start_userid']."'";
        $rsUserLastArticle = mysql_query($qryUserLastArticle);
        $row = mysql_fetch_array($rsUserLastArticle);
        $m_lastarticle = $row['lastarticleid'];
    ?>
    <ul id="articleid">
        <?php
        for ($i=1; $i<=$m_lastarticle; $i++)

        {
            if($i != 57)
            {
            ?>
            <li>
                <a href="/test/test.php?id=<?php echo $i; ?>">Day <?php echo $i; ?></a>
            </li>
            <?php
            }
        }
        ?>
    </ul>
</div>

Hope this explanation helps.

If you could please help me out.

Any help will be appreciated.

Thank You.

Regards,

Meher

PRASANT KUMAR SUMAN

unread,
Feb 6, 2013, 6:00:41 AM2/6/13
to weeke...@googlegroups.com
simple ...

I am not writing code ...instead i am giving you psuedocode

If(id=21) then start the loop of  <ul> and start <li> from 21 to 40
again repeat it for 41 and so on...
--

ℙґα﹩@η☂ Ḳüღαґ $üмαη
www.facebook.com/PKSUMAN
Mob:- 08010173356



Reply all
Reply to author
Forward
0 new messages