Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
where in the html output ? you want replace val ? or the names ?what result you want – echo_Samir 30 mins ago

2 Answers

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>
';
}
share|improve this answer
in this script i am assuming that you have stored page value also in the table with zone – user2488557 23 mins ago

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%2==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)
       {   echo '</div>';  $j++; }

       $i++;

    }



 ?>
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.