0 Comments    Jul 19, 2002

Ever since Dreamweaver MX was released, one of the questions that I noticed was asked more often than most was how to create a horizontal looper for the PHP/MySQL server model. I have been working away at it for months and I believe what I found may help. It tried to create an extension out of it, but the Dreamweaver MX API was so complex and I could not be bothered figuring it out.

I hope this tutorial will help a lot of php programmers out there create their own horizontal looper pages for whatever purpose they wish to use it for. If you're ready. let get started.

First of all, open up Dreamweaver MX and create a new dynamic PHP page. Identify the recordset that you wish to use and create a recordset.

Create a 1x1 table. Set the border to 1 and delete the values of the cell padding and cell spacing. Drag out a column from you recordset and drop it in the middle of the table.

The next part is going to be the very trick bit so pay attention very carefully. Select the table that you create with column inside and from the server behaviors menu, create a repeat region. Do not change any values on the dialog box and click OK to close the dialog box.

Click on the Code View button the DWMX toolbar. Scroll up to the top of the page. You should see some PHP code similar to the one below:

  1. require_once('../Connections/GKaosCONN.php'); ?>
  2. $maxRows_Recordset1 = 10;
  3. $pageNum_Recordset1 = 0;
  4. if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
  5. $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
  6. }
  7. $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
  8. mysql_select_db($database_GKaosCONN, $GKaosCONN);
  9. $query_Recordset1 = "select * from gallery where PicCategory = '3D Gallery'";
  10. $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
  11. $Recordset1 = mysql_query($query_limit_Recordset1, $GKaosCONN) or die(mysql_error());
  12. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  13. if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
  14. $totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
  15. } else {
  16. $all_Recordset1 = mysql_query($query_Recordset1);
  17. $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
  18. }
  19. $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
  20. ?>

If you see something like that, then that is good. Next, we are going to define the variables that will allow us to create the horizontal looper code. Type in this code below the second line:

  1. $mainGrid = 0;
  2. $RowStart = 0;
  3. $RowEnd = 0;
  4. $numberColumns = 3;
  5. $numberRows = 3;
  6. $mainGrid = $numberColumns * $numberRows;

Replace the value of $maxRows_Recordset1 being 10 to $mainGrid. Therefore, you should have something like $maxRows_Recordset1 = $mainGrid.

That is the first part done.

For the second part, you will need to scroll down to your table still in code view. The code there should resemble something like this:

  1. do { ?>
  2. "../portfolio/thumbs/" border="0">
  3. } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

Make the modifications to that code above so that it resembles the one below:

  1. do { ?>
  2. while((($numberRows != 0) && (!($row_Recordset1 == 0))))
  3. {
  4. $RowStart = $RowEnd + 1;
  5. $RowEnd = $RowEnd + $numberColumns;
  6. ?>
  7. while((($RowStart <= $RowEnd) && (!($row_Recordset1 == 0))))
  8. {
  9. ?>
  10. "../portfolio/thumbs/" border="0">
  11. $RowStart = $RowStart + 1;
  12. $row_Recordset1 = mysql_fetch_array($Recordset1);
  13. }
  14. ?>
  15. $numberRows = $numberRows - 1;
  16. }
  17. ?>
  18. } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

If you have done this, click one Live Data View button to view the results. If you followed the tutorial properly, you should have a 3*3 grid in front of you. You can change the grid setting by changing the values of $numberColumns and $numberRows in Code View mode. Just add the values needed to suit you.

After setting your values, you can use the DWMX record navigation suite to navigate through the grid. Just make sure you use your own recordsets.

If you have any problems following this tutorial, please do not hesitate to contact me.

 
 Filed In: Web Development




Other Posts You Might Like


blog comments powered by Disqus