-2

I know this question was asked many times but still.. i'm not an expert. Below is my code :

  <?php
  $result=mysqli_query($con, $sql)or die(mysqli_error($con));    
  $search_result = "";
  $search_result .= " <table border='0' cellspacing='0' cellpadding='0'><tr>";
    while($row=mysqli_fetch_array($result))
    {
    $id=$row['id'];
    $department=$row['department'];
    $name=$row['name'];
    $extension=$row['extension'];
    $hpno=$row['hpno'];
    $staff_no=$row['staff_no'];
    $birthdate=$row['birthdate'];
    $position=$row['position'];
    $email=$row['email'];
    $image=$row['image'];
    $status=$row['status'];

  $search_result .= " <td height='250' valign='top'><img src='" . $image . "'>&nbsp;</td>
                      <td><table border='0' width='250'>
                           <tr><td height='40' valign='top'><font size='3'><strong>" . $staff_no . "&nbsp;" . $name . "</strong></font></td></tr>
                           <tr><td height='32' valign='top'><i>" . $position . "</i></td></tr>
                           <tr><td height='32' valign='middle'><font color='blue'>" . $email . "</font></td></tr>
                           <tr><td height='32' valign='middle'><img src='mobile.png'>&nbsp;" . $hpno . "&nbsp;|&nbsp;Office Ext : <strong>" . $extension . "</strong></td></tr>
                           <tr><td height='32' valign='middle'>Department : " . $department . "</td></tr>
                           <tr><td height='32' valign='middle'>DOB : " . $birthdate . "</td></tr>
                           <tr><td height='32' valign='middle'>Status : " . $status . "</td></tr>       
                         </table>
                      </td>
                      <td width='20'>&nbsp;</td>";

$table=$table + 1;
if ($table=='3')
{
$search_result .= "</tr><tr>";
$table=0;
}
}
$search_result .= "</table>";
$search_result .= "<br />";
echo $search_result;
?>
<center><?=$pagination?></center>

I put certain part of the code for better understanding. My ideas is to put a table that can replicate 3 rows & 3 column record per page but when i declare $table=0; before $table=$table + 1; its return 9 record vertically

Rizal
  • 5
  • 5
  • 5
    In the first line `$table=$table + 1;`, do you have `$table` defined before using it on RHS. If not, you'll get this – Haridarshan Feb 25 '16 at 06:54
  • This won't solve your problem (you got answers that will), but I just want to point out that you shouldn't wrap your integers in quotes. Quotes means strings (even though this works in a loosly typed language like PHP). It's just bad practice. – M. Eriksson Feb 25 '16 at 07:02
  • thanks for pointing it out – Rizal Feb 25 '16 at 07:17

3 Answers3

0

You should use this

    $table=0;
    $table++;
    if ($table==3)
    {
    $search_result .= "</tr><tr>";
    $table=0;
    }
Rahul
  • 763
  • 1
  • 12
  • 45
  • when i put $table=0 in the first line, my database only return 3 record instead of all records. As i define in my pagination page, the limit of data per page is 9 – Rizal Feb 25 '16 at 07:05
  • I just edit my question for better understanding. Mind to share your idea regarding changing the condition? – Rizal Feb 25 '16 at 07:15
0

This is a warning that you can ignore the error_reporting setting in your php document error_reporting (E_ERROR | E_PARSE);

Ok, ignoring a notice is never a good idea, we explain the error. In this case you are calling a $table variable that you have not declared. You need to declare it like this:

$table = 0;
$table=$table + 1;
if ($table=='3')
{
   $search_result .= "</tr><tr>";
   $table="0";
}
Mirko Brombin
  • 1,002
  • 3
  • 12
  • 34
  • The page will display 9 records vertically instead of 3*3 per page as what i define in pagination – Rizal Feb 25 '16 at 07:31
0

did you define $table variable before using it? seems like you didn't. i think it should be something like this

$table = some value; //first define it, and then use

and then

$table=$table + 1;
if ($table=='3')
{
$search_result .= "</tr><tr>";
$table="0";
}
nooby
  • 294
  • 4
  • 17
  • supposedly my pagination will display the page 9 records (3*3) per page. when i define $table=some value; my page display 9 records in a row instead of 3*3 – Rizal Feb 25 '16 at 07:28
  • use $table==3 (without quotes). did it return last 3 records from db or first 3? are you sure that your $table variable is not being overridden? – nooby Feb 25 '16 at 07:30
  • my pagination.php define $limit=9 which is it will display 9 records per page. Before i define $table=0; the page show the records 3 rows & 3 column as what i wanted but after i define $table=0; my page display the 9 records in a rows – Rizal Feb 25 '16 at 07:36
  • that's because you close row(i mean ) only when $table == 3 – nooby Feb 25 '16 at 07:53