2

Before i was displaying zones records static although i have records in database table

HTML

<div class="pub_fot_sec_menu pub_fot_list_fst">
    <h2><a href="index.php?pages=zilla.php&val=1">Kosi</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=2">Mechi</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=3">Sagarmatha</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_sec">
    <h2><a href="index.php?pages=zilla.php&val=6">Bagmati</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=7">Janakpur</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=8">Narayani</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_thrd">
    <h2><a href="index.php?pages=zilla.php&val=9">Dhawalagiri</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=10">Gandaki</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=11">Lumbini</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_frth">
    <h2><a href="index.php?pages=zilla.php&val=12">Bheri</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=13">Karnali</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=14">Rapti</a></h2>
</div>

Now i want to fetch zone records using while or whatever method that work for me!

<?php
$sql="select * from tb_zone";
$res =mysql_query($sql);
while($data =mysql_fetch_array($res))
    {
        // want do display zone record in the above html output format
    }
?>

Any help would be appreciated!

2
  • where in the html output ? you want replace val ? or the names ?what result you want Commented Jun 16, 2013 at 13:25
  • @echo_Samir i want to load val value and <a> tag value (kosi, mechi etc) from mysql table using while loop or any method but each 3 zone list should be grouped in div tag Commented Jun 16, 2013 at 15:12

2 Answers 2

2

Try This

 <?php
$class = array ('pub_fot_sec_menu pub_fot_list_fst','pub_fot_sec_menu pub_fot_list_sec','pub_fot_sec_menu pub_fot_list_thrd','pub_fot_sec_menu pub_fot_list_frth'); 
$sql="select * from tb_zone";
$res =mysql_query($sql);
$j=0;
$i=0;
while($data =mysql_fetch_array($res))
    {
       if($i==0)
       {   echo '<div class="'.$class[$j].'">';   }

         echo  '<h2><a href="index.php?pages=zilla.php&val='.$data["value"].'">'.$data["zone"].'</a></h2>';

         if($i%2==0 && i > 0)
       {   echo '</div>';  $j++;$i=0; }
       else{    $i++;    }




    }



 ?>
Sign up to request clarification or add additional context in comments.

1 Comment

i want to load val value and <a> tag value (kosi, mechi etc) from mysql table using while loop or any method but each 3 zone list should be grouped in div tag.. will this script work?
0

just use this type

while($data =mysql_fetch_array($res))
{

echo
'
<div class="pub_fot_sec_menu pub_fot_list_fst">
    <h2><a href="index.php?pages=zilla.php&val='.$data['value'].'">'.$data['zone'].'</a></h2>
';
}

2 Comments

in this script i am assuming that you have stored page value also in the table with zone
i want to load val value and <a> tag value (kosi, mechi etc) from mysql table using while loop or any method but each 3 zone list should be grouped in div tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.