• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Checking for last result of $offset

I'm having a script which creates tables from a MySQL query. Now it sometimes misses the last closing </tr> within a table after the last result. What I would like to do is to check for the last result of the $offset and  echo "</tr>";  in this case.

So this line should contain something like:

if($counterr==2 OR if is the last result of the $offset) echo "</tr>";


<table>
<?php
 $counterr=0;
            $result = mysql_query("SELECT bizID,bizName GROUP BY bizName ORDER BY bizName ASC LIMIT $offset,100");
while($r=mysql_fetch_array($result))
            {
....

 if($counterr==0)
                  {
                                        echo "<tr>";
                                                             }

      echo '<td>'
.............
                        <br></td>';
if($counterr==2)
                  {
                        echo "</tr>";
                        $counterr = 0;
                        continue;
                  }
                                  $counterr++;
            }
            ?>
</table>
0
seopti
Asked:
seopti
  • 3
1 Solution
 
Ray PaseurCommented:
In the code you have posted here I see this:
if($counterr==2)

Open in new window

But the only reference to the variable seems to be here
$counterr=0;

Open in new window

In other words, there is no chance that $counterr could ever be set equal to 2.  This kind of programming seems to assume that undefined variables have some inherent properties.  You might not want to make these assumptions.

I am wondering about this line:
$result = mysql_query("SELECT bizID,bizName GROUP BY bizName ORDER BY bizName ASC LIMIT $offset,100");

Open in new window

How do you know whether that query worked at all?  I do not see any test for the value in $result.  

Going forward, you might want to consider getting this excellent little book.  It will not make you a professional programmer, but it will help you get some kind of foundation in how PHP and MySQL work together.  A few weeks and you will be much better grounded in the basics, I promise!
http://www.sitepoint.com/books/phpmysql4/
0
 
seoptiAuthor Commented:
Sorry but I don't need a book, I need a simple solution. Thank you for your time. Maybe someone else here is able to give a solution? Once again, thank you.
0
 
Ray PaseurCommented:
If there were any simple simple solution that I knew about I would have offered a simple solution.  You can choose to get an understanding and write your own solution or you can choose to hire someone who already has an understanding and they can write your solution for you.  I am trying to be respectful of your time.  

If I had the time to give a solution or sell a solution I would offer that, but I am involved in a complicated real estate transaction now.  What you want may require some investigation and detailed testing.  My recommendation is to hire a professional programmer and turn over all of the information -- URL, PHP scripts, data base CREATE TABLE scripts, login credentials, etc. -- everything they ask for.  Then relax and in a few minutes you will have a good solution.  When you get the bill, you will probably think it is expensive.  But as Red Adair, the great oil well firefighter, famously pointed out, "If you think it is expensive to hire a professional, just wait until you hire an amateur!"
0
 
Ray PaseurCommented:
I have some free time this weekend, so I took another look at this question.  Rereading this code, I still cannot figure out what the purpose of $counterr could be.  Can you please post the rest of the code in the while() loop?  I would like to line up the control structures so we can see the conditional instruction paths.  If we do that, the issues may become obvious.  Please also explain what $counterr is used for.  Thanks, ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now