How to write for loop for these code

hello everyone,

actually i have 22languages in my database .each one starts with different ID’s(it has two category’s movie_id,celebrity_id)…then i want write those 22 languages code into for loop
example like,

$languages = {“english”, “hindi”};
$startMovieIds = { 8291800001, 9543200001};
$lastMovieIds = { 8291800100, 9543210000} ;
$startCelebIds = { 8912100001, 2345100001};
$lastCelebIds = {8912112540, 2345110000};

how can i write for loop for these ID’s
suggestions plz
thnks

[QUOTE=anji;5158569]hello everyone,

actually i have 22languages in my database .each one starts with different ID’s(it has two category’s movie_id,celebrity_id)…then i want write those 22 languages code into for loop
example like,

$languages = {“english”, “hindi”};
$startMovieIds = { 8291800001, 9543200001};
$lastMovieIds = { 8291800100, 9543210000} ;
$startCelebIds = { 8912100001, 2345100001};
$lastCelebIds = {8912112540, 2345110000};

how can i write for loop for these ID’s
suggestions plz

actually before this code i wrote another for loop
like

for($i=8291800001;$i<=8291800100;$i++)
{
array_push($urls,‘http://www.xxx.com/te/’.$i);
$i++;
}
for($j=8912100001;$j<=8912112540;$j++)
{
array_push($urls,‘http://www.xxx.com/te/’.$j);
$j++;
}
this is long process to write for loop for 22 languages

i want short my code…plz let me tel how to write for loop

What are you trying to accomplish with the loops? Are you just creating urls for each movie and celeb in every language?

please elaborate more, i can do this…

iam trying to run every for loop and then each and every time url will pushed to array…

@apxred i have 22 languages…each language has two types of id’s(movie_id,cel_id) each type has more number of id’s …iam trying to send those id’s as urls and then those urls are pushed into array for dispaly purpose…



$query = mysql_query("Select `movie_id`, `celeb_id` from `tablename`"); // run sql query
$moviearray = array(); // define movie array
$celebarray = array(); // define celeb array
$i = 1; // counter for array
while($fetcharray = mysql_fetch_array($query))
{
$moviearray[$i] = $fetcharray['movie_id'];
$celebarray[$i] = $fetcharray['celeb_id'];
$i++;

// for testing you can print movie array as follows
echo('&lt;a href="http://Linkstarting.com/'.$moviearray[$i].'"&gt;'.$moviearray[$i].'&lt;/a&gt;&lt;br /&gt;');
}

If you are having like a load of values, you can also paginate this script… I hope, you know how to paginate it…

And hope that this solves your issue :slight_smile:

thnks @apxred…but iam new to php…actually i don’t about paginate concept…if u have free time plz share me that concept (how to use paginate in my script)…one more thing iam also from india…

Ok, So here it is…

Suppose, you want to display only 08 links per page.
So we are first going to write the whole code, which will be displayed on page as follows…

[1] Index Page as below… Save it as index.php

  
//connect to the database
    include_once ('db.php'); // code for this page is at [2]
//get the function
    include_once ('paginate_function.php'); // code for this page is at [3]
 
        $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
        $limit = 8; // number of links to be displayed per page
        $startpoint = ($page * $limit) - $limit;
         
        //to make pagination
        $statement = "`list_id`";
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
 
&lt;head&gt;
    &lt;title&gt;Playing with Arrays&lt;/title&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
    &lt;link href="pagination.css" rel="stylesheet" type="text/css" /&gt; @[4]
    &lt;link href="green_tab.css" rel="stylesheet" type="text/css" /&gt; @[5]
    &lt;style type="text/css"&gt;
        .records {
            width: 510px;
            margin: 5px;
            padding:2px 5px;
            border:1px solid #B6B6B6;
        }
         
        .record {
            color: #474747;
            margin: 5px 0;
            padding: 3px 5px;
            background:#E6E6E6; 
            border: 1px solid #B6B6B6;
            cursor: pointer;
            letter-spacing: 2px;
        }
        .record:hover {
            background:#D3D2D2;
        }
         
         
        .round {
            -moz-border-radius:8px;
            -khtml-border-radius: 8px;
            -webkit-border-radius: 8px;
            border-radius:8px;   
        }   
         
        p.createdBy{
            padding:5px;
            width: 510px;
            font-size:15px;
            text-align:center;
        }
        p.createdBy a {color: #666666;text-decoration: none;}       
    &lt;/style&gt;   
&lt;/head&gt;
 
&lt;body&gt;
 
    &lt;div class="records round"&gt;
        &lt;?php
            //show records
            $query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint} , {$limit}");
             
            while ($row = mysql_fetch_assoc($query)) {
        ?&gt;
            &lt;div class="record round"&gt; &lt;a href="http://www.google.com/&lt;?php echo $row['movie_id']; ?&gt;"&gt; &lt;?php echo $row['movie_id'];?&gt; &lt;/a&gt; | &lt;a href="http://www.google.com/&lt;?php echo $row['celeb_id']; ?&gt;"&gt; &lt;?php echo $row['celeb_id'];?&gt; &lt;/a&gt; &lt;/div&gt;
        &lt;?php   
            }
        ?&gt;
    &lt;/div&gt;
 
&lt;?php
    echo pagination($statement,$limit,$page);
?&gt;

&lt;/body&gt;
&lt;/html&gt;

[2] Now, for the db.php … Save it as db.php


$connect = mysql_connect("localhost", "root", ""); // connection to database host using database URL, username and password
mysql_select_db("moviearray", $connect); // connection to database


[3] Now, let’s write down the code of Pagination in another php page and we already called it at top in php code… Save it as paginate_function.php


 
   function pagination($query, $per_page = 8,$page = 1, $url = '?'){       
        $query = "SELECT COUNT(*) as `num` FROM `list_id`";
        $row = mysql_fetch_array(mysql_query($query));
        $total = $row['num'];
        $adjacents = "2";
 
        $page = ($page == 0 ? 1 : $page); 
        $start = ($page - 1) * $per_page;                              
         
        $prev = $page - 1;                         
        $next = $page + 1;
        $lastpage = ceil($total/$per_page);
        $lpm1 = $lastpage - 1;
         
        $pagination = "";
        if($lastpage &gt; 1)
        {  
            $pagination .= "&lt;ul class='pagination'&gt;";
                    $pagination .= "&lt;li class='details'&gt;Page $page of $lastpage&lt;/li&gt;";
            if ($lastpage &lt; 7 + ($adjacents * 2))
            {  
                for ($counter = 1; $counter &lt;= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                    else
                        $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                }
            }
            elseif($lastpage &gt; 5 + ($adjacents * 2))
            {
                if($page &lt; 1 + ($adjacents * 2))    
                {
                    for ($counter = 1; $counter &lt; 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                        else
                            $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                    }
                    $pagination.= "&lt;li class='dot'&gt;...&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$lpm1'&gt;$lpm1&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$lastpage'&gt;$lastpage&lt;/a&gt;&lt;/li&gt;";     
                }
                elseif($lastpage - ($adjacents * 2) &gt; $page && $page &gt; ($adjacents * 2))
                {
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=1'&gt;1&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=2'&gt;2&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li class='dot'&gt;...&lt;/li&gt;";
                    for ($counter = $page - $adjacents; $counter &lt;= $page + $adjacents; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                        else
                            $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                    }
                    $pagination.= "&lt;li class='dot'&gt;..&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$lpm1'&gt;$lpm1&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$lastpage'&gt;$lastpage&lt;/a&gt;&lt;/li&gt;";     
                }
                else
                {
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=1'&gt;1&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li&gt;&lt;a href='{$url}page=2'&gt;2&lt;/a&gt;&lt;/li&gt;";
                    $pagination.= "&lt;li class='dot'&gt;..&lt;/li&gt;";
                    for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter &lt;= $lastpage; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                        else
                            $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                    }
                }
            }
             
            if ($page &lt; $counter - 1){
                $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$next'&gt;Next&lt;/a&gt;&lt;/li&gt;";
                $pagination.= "&lt;li&gt;&lt;a href='{$url}page=$lastpage'&gt;Last&lt;/a&gt;&lt;/li&gt;";
            }else{
                $pagination.= "&lt;li&gt;&lt;a class='current'&gt;Next&lt;/a&gt;&lt;/li&gt;";
                $pagination.= "&lt;li&gt;&lt;a class='current'&gt;Last&lt;/a&gt;&lt;/li&gt;";
            }
            $pagination.= "&lt;/ul&gt;\
";     
        }
     
     
        return $pagination;
    }


[4] Now CSS file for Styling the Pagination … Save it as pagination.css


ul.pagination{
    margin:0px;
    padding:0px;
    height:100%;
    overflow:hidden;
    font:12px 'Tahoma';
    list-style-type:none;  
}
 
ul.pagination li.details{
    padding:7px 10px 7px 10px;
    font-size:14px;
}
 
ul.pagination li.dot{padding: 3px 0;}
 
ul.pagination li{
    float:left;
    margin:0px;
    padding:0px;
    margin-left:5px;
}
 
ul.pagination li:first-child{
    margin-left:0px;
}
 
ul.pagination li a{
    color:black;
    display:block;
    text-decoration:none;
    padding:7px 10px 7px 10px;
}
 
ul.pagination li a img{
    border:none;
}


[5] Now Specific Color Tabs for Numbers… Save it as green_tab.css



ul.pagination li.details{
   color:#699613;
}
 
ul.pagination li a
{
    border-radius:3px; 
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
    padding:6px 9px 6px 9px;
}
 
ul.pagination li a
{
    color: #fff;
    background:#699613;
    background:-moz-linear-gradient(top,#87AB19,#699613);
    background:-webkit-gradient(linear,0 0,0 100%,from(#87AB19),to(#699613));  
}  
 
ul.pagination li a:hover,
ul.pagination li a.current
{
    color:#4F7119;
    background:#E7F2C7;
}




At Last, if you also want Database I used to see it working fully, just import the Sql file…

Sending an Attachment with this Mail… Download it and use as you like to…