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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.