1

I have two pages index4.php and generate.php. User have to select a date range and click on button in index4.php to generate user report in generate.php.

index4.php
index4.php

database table
database table

And I wish to display those results in generate.php something like this:
result table

Here is my coding for both pages:
index4.php

<form action="generate.php" method="post" target="_blank">
    <table width="528" align="center" boder="0">
    <tr>
        <td width="109">Select date :</td>
        <td width="202">FROM&nbsp;&nbsp;<input type="date" name="start_date" required/></td>
        <td width="24">TO</td>
        <td width="173">&nbsp;<input type="date" name="end_date" required/></td>
    </tr>
    <tr>
        <td colspan="4"><i><font color="#FF0000">*</font>&nbsp;Required field.</i></td>
    </tr>
    <tr>
    <td colspan="4" align="center"><input type="submit" value="Generate User Report"/></td>
    </tr>
    </table>
</form>

generate.php

<table align="center" border="1">
<tr>
    <td align="center">Date</td>
    <td align="center">Page Name</td>
    <td align="center">Page Viewed</td>
</tr>
<?php
    if(mysql_num_rows($select_page_view) > 0)
    {
        $row = mysql_fetch_array($select_page_view); ?>
        <tr>
            <?php $num_rows = mysql_num_rows($select_page_view); ?>
            <td rowspan="<?php echo $num_rows; ?>"><?php echo $row['page_view_date']; ?></td>
        </tr>
        <?php
        while($row)
        {?>
            <tr>
            <td><?php echo $row['page_name'];?></td><td><?php echo $row['visited_times']; ?></td>
            </tr>
  <?php } ?>
<?php }?>
</table> 

When I test my generate.php and the page shows infinite loop for page_name... any solution to solve it?

1

1 Answer 1

1

You have to change the loop in this way:

while( $row = mysql_fetch_array($select_page_view) )
{
    (...)
}

In your original syntax:

$row = mysql_fetch_array($select_page_view);
(...)
while( $row )
{
    (...)
}

$row is fetched one, then it doesn't change, so the loop doesn't stop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.