Jump to content

Recommended Posts

i tried this but the page came up blank.  i want the results echoed into the table accordingly.  theres like 10 results, so i want the table to fill up with those results.

 

 

<?php

mysql_connect("localhost", "Master", "password);

mysql_select_db("Ustack");

 

$report = mysql_query("SELECT * FROM Stacks Where username='Admin' ")or die (mysql_error());

 

while($row = mysql_fetch_array( $report)) {

 

 

$id = $row['id'];

return $id;

}

?>

<table border="0">

<tr>

<td width="70" height="70">

<?php

echo $id;

?></td>

<td width="70" height="70"><?php

echo $id;

?></td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

<td width="70" height="70"> </td>

</tr>

 

</table>

Link to comment
https://forums.phpfreaks.com/topic/180298-need-help-with-table/#findComment-951129
Share on other sites

You need to build the table with the results. Are you wanting the table to always be 14 x 4 no matter how many results there are? If so, that is easily done.

 

<?php

$rows = 4;
$cols = 14;

mysql_connect("localhost", "Master", "password);
mysql_select_db("Ustack");

$maxCount = $rows * $cols;
$query = "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
$result = mysql_query($query) or die (mysql_error());

$idList = array();

while($row = mysql_fetch_assoc($result))
{
    $idList[] = $row['id'];
}

$tableOutput = '';

for($row=0; $row<$rows; $row++)
{
    $tableOutput .= "  <tr>\n";
    for($col=0; $col<$cols; $col++)
    {
        $idIndex = ($row * $cols) + $col;

        $tableOutput .= "<td>";
        $tableOutput .= (isset($idList[$idIndex]) ? $idList[$idIndex] : ' ');
        $tableOutput .= "</td>\n";
    }
    $tableOutput .= "  </tr>\n";
}

?>

<table border="0">
<?php echo $tableOutput; ?>
</table>

Link to comment
https://forums.phpfreaks.com/topic/180298-need-help-with-table/#findComment-951277
Share on other sites

THX!! i already have a pagination code, but i'm having trouble getting it to work with the table.  can you help?  on the second page it should replace the table(your code) with the next set of results in the table, instead it just shows the same thing.

 

<?php

$rows = 4;
$cols = 14;

mysql_connect("localhost", "Master", "pword");
mysql_select_db("Ustack");

$maxCount = $rows * $cols;
$query = "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
$result = mysql_query($query) or die (mysql_error());
$foundnum = mysql_num_rows($result);
$limit = 54;

       $page = $_GET['page'];

       if($page){
          $start = ($page - 1) * $limit;
       }else{
          $start = 0;
       }
$idList = array();

while($row = mysql_fetch_assoc($result))
{
    $idList[] = $row['id'];

}

$tableOutput = '';

for($row=0; $row<$rows; $row++)
{
    $tableOutput .= "  <tr>\n";
    for($col=0; $col<$cols; $col++)
    {
        $idIndex = ($row * $cols) + $col;

        $tableOutput .= "<td>";
        $tableOutput .= (isset($idList[$idIndex]) ? $idList[$idIndex] : ' ');
        $tableOutput .= "</td>\n";
    }
    $tableOutput .= "  </tr>\n";
}
echo "<table border='0'>
  $tableOutput 
</table>";
// How many adjacent pages should be shown on each side?
       $adjacents = 3;
           
        // Your file name  (the name of this file)
       $targetpage = "test2.php";

       if ($page == 0){
          $page = 1;
       }

       $prev = $page - 1;

       $next = $page + 1;

       $lastpage = ceil($foundnum/$limit);

       $lpm1 = $lastpage - 1;

       $pagination = "";
       if($lastpage > 1){
          $pagination .= "<div class=\"pagination\">";
          // Previous
          if ($page > 1){
             $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$prev\" style='text-decoration: none';> <strong>« previous</strong></a>";
          }else{
             $pagination .= "<span class=\"disabled\"> <strong>« previous</strong></span>";
          }

          // Pages

          if ($lastpage < (7 + ($adjacents * 2))){   
             for ($counter = 1; $counter <= $lastpage; $counter++){
                if ($counter == $page){
                   $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
                }else{
                   $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
                }
             }
          }elseif($lastpage > (5 + ($adjacents * 2))){
             if($page < 1 + ($adjacents * 2)){
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
                   if ($counter == $page){
                      $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
                   }else{
                      $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
                   }
                }
             }

          $pagination .= "...";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
       }elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';><strong> 1</strong></a>";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';><strong> 2</strong></a>";
          $pagination .= "...";

          for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){
             if ($counter == $page){
                $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
             }else{
                $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
             }
          }
          $pagination .= "...";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
        }else{
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';> 1</strong></a>";
          $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';> 2</strong></a>";
          $pagination .= "...";

          for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){
             if ($counter == $page){
                $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
             }else{
                $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
             }
          }
       }
               
       // Next
       if ($page < $counter - 1){
           $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$next\" style='text-decoration: none';><strong> next »</strong></a>";
       }else{
          $pagination .= "<span class=\"disabled\"><strong> next »</strong></span>";
          $pagination .= "</div>\n";
        }
       }
      echo $pagination;
   







?>



Link to comment
https://forums.phpfreaks.com/topic/180298-need-help-with-table/#findComment-951317
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.