Bir id-parametre ile Sayfası Filtre sonuçları

1 Cevap php

I use a SELECT to get all the rows from the table tblnavigation. The rows are: idnav, idnavcat, prognav, progurl

$rsnav = mysql_query($query_rsnav, $concat) or die(mysql_error()); $row_rsnav = mysql_fetch_assoc($rsnav);

Idnavcat navigasyon kategori için duruyor. Şimdi ben bu "idnavcat" filtrelemek istiyorum; ve bir tablodaki kategori başına sonuçlarını göstermektedir.

        <?php do { ?>
        <tr>
          <td width="10%"><div align="center"><?php echo $row_rsnav['idnav']; ?></div></td>
          <td width="70%"><?php echo $row_rsnav['navprog']; ?></td>
          <td width="11%"><a href="nav_adj.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/edit.png" alt="" width="32" height="32" border="0" /></a></td>
          <td width="8%"><p><a href="nav_del.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/delete.png" alt="" width="32" height="32" /></a></p>              </td>
        </tr>
        <?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>

I know it's possible with multiple selects; but i know it's slower. Has something to do with "while do" ? Or array ? Not sure; newby here ! :-)


Ben bir dizi üzerinde adım attı; ve bir foreach döngüsü aracılığıyla bunu okudum.

while ($row_rsprog = mysql_fetch_array($rsprog)) {
  $data[$row_rsprog['idprog']] = array(
'idprog' => $row_rsprog['idprog'],
'progtitel' => $row_rsprog['progtitel'],
'idnavcat' => $row_rsprog['idnavcat']
);
}

Ve ben onu okudu:

foreach ($data as $id => $va){
echo 'blablabla';
}

But it reads the whole array. I want only to display the arraylines with a specific idnavcat-value. How can this be done ? Thanks for your help !

1 Cevap

Ne yapmak istediğinizi tam olarak alamadım. Eğer haklıysam, bir kod-break yapısını uygulamak istiyor.

Sen idnavcat tarafından sorgu sıralamak ve bu gibi kod çalıştırmak için denemek için ilk gerekir:

<?php

[...]

$query = "SELECT * FROM tblnavigation ORDER BY idnavcat;"; 

[...] // you execute the query here and do the rest of the stuff


// fetch the row
$row_rsnav = mysql_fetch_assoc($rsnav);
// stablish a default current category to force headers to be written
$current_category = -1;
do {

    if ($current_category != $row_rsnav['idnavcat']) 
    {
        $current_category = $row_rsnav['idnavcat'];

        // print headers (for example)
        ?>
        <tr>
          <td width="10%">ID NAV</td>
          <td width="70%">NAV PROG</td>
          <td width="19%" colspan="2">CATEGORY: <?php echo $current_category ?></td>
        </tr>
        <?
    }
?>
    <tr>
      <td width="10%"><div align="center"><?php echo $row_rsnav['idnav']; ?></div></td>
      <td width="70%"><?php echo $row_rsnav['navprog']; ?></td>
      <td width="11%"><a href="nav_adj.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/edit.png" alt="" width="32" height="32" border="0" /></a></td>
      <td width="8%"><p><a href="nav_del.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/delete.png" alt="" width="32" height="32" /></a></p></td>
    </tr>
<?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>

Programlama bu şekilde daha fazla ya da daha az çirkin olduğunu çünkü Ama MEZUNLARI biz çok işlevselliği etkilemeden hızlı bir şekilde modificate edebilmek için bizim Sourcecode sonuçlarını biçimlendirmek için smarty veya herhangi bir şablon sistemi kullanmak için düşünmelisiniz.