Jump to content

Stuck combining pagination code with my HTML/PHP code.


dmacman

Recommended Posts

I am trying to implement some pre-written pagination code I found with my code. It is using a mysql_result with straight <td> </td> tags, and I have somewhat more complicated tags with an if statement enclosed in a input tag, making is near impossible for me to get the pre-written code to work for me. (for space sakes, I did not display the non-applicable code that is before and after [for the rest of the table] or the connection code).

 

Here is the pre-written example:

//The usual "Let's push elements onto an array" deal.
    $all_columns[$current_column][]=mysql_result($result,$i,'ShortName');

for($i=0; $i<$display_rows-$padding; $i++)
{    echo '<tr>';
    for($j=0; $j<$display_columns; $j++)
    {    echo '<td>',$all_columns[$j][$i],'</td>';
    }
    echo '</tr>';
} 

 

And the part I am stuck on is my equivalent of the <TD></TD> tags are...

 

<td width="196" align=left style="padding-left:40px" nowrap="nowrap">
<input name="Products[1]" id="dy_rating_chk_1" type="checkbox" tabindex="29" value="1" <?php if(isset($_SESSION['products'][1])) { echo ' checked'; } ?>>
The Great Depression</td>

 

And my attempt to mix my code with the $display_columns was a feeble disaster.

 

here...

 

for($i=0; $i<$display_rows-$padding; $i++)
{    echo '<tr>';
    for($j=0; $j<$display_columns; $j++)
    {    echo '<td width="196" align=left style="padding-left:40px" nowrap="nowrap"><input name="Products['.$i.']" id="dy_rating_chk_'.$i.'" type="checkbox" tabindex="29" value="'.$i.'"';
    if(isset($_SESSION['products'][$i])) { echo ' checked'; }
    echo $all_columns[$j][$i].'</td>';
    }
    echo '</tr>';
} 

 

Which should have gave me 3 colums, 11 items all with names and check boxes.

 

What I got 3 columns, 6 check boxes in the top 2 row with no names, and 4 names in the bottom 2 rows with no check boxes.

 

As always, I appreciate the guidance, and help.

 

Regards,

Don

Link to comment
Share on other sites

Well I got closer with this...

 

// Handle the last $padding rows specially, by ignoring the last column.
for(/*$i already has the correct value*/; $i<$display_rows; $i++)
{    echo '<tr>';
    for($j=0; $j<$display_columns-1; $j++)
    {    echo '<td width="250 align=left style="padding-left:10px" nowrap="nowrap"><input name="Products['.$i.']" id="dy_rating_chk_'.$i.'" type="checkbox" tabindex="29" value="'.$i.'"';
if(isset($_SESSION['products'][$i]))
     {
      echo ' checked="checked" >';
     } else {
     echo ' >';
     }
     echo $all_columns[$j][$i];
     echo '</td>';
    }
    // Empty padding cell.
    echo '<td></td>';
    echo '</tr>';
}
echo '</table>'; 

 

But if the user comes back to the page to fix an error, all the item are now checked. NOTE, I am using a SELF form.

 

I still could use some help though.

Thanks,

Don

Link to comment
Share on other sites

Sorry,

 

{
      echo ' checked>';
     } else {
     echo 

 

Should have been this.

 

But still not retaining the $_SESSION['products'][$i] like in the

 

if(isset($_SESSION['products'][1])) { echo ' checked'; }

 

version before the pre-written version.

 

Don

Link to comment
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.