Page 1 of 1

Horizontal Looping Repeat Region

Posted: Tue Aug 07, 2012 9:47 pm
by monicaBUSGk9X
Hello!

I'm translating over from the PHP web world and have a question on how to create a horizontal looping repeat region in Live Code? I would be using a MySQL or SQLite database for my query. Then, I want to put my results on my stack with a defined column size and then it will loop horizontally that number of times and move down a row. In HTML I'd do this with table rows & columns and some PHP code.

Here is an example of what I'm trying to accomplish (see attached).

Thanks guys!
Cheers,
Monica
:wink:

Re: Horizontal Looping Repeat Region

Posted: Wed Aug 08, 2012 12:17 am
by Mark
Dear Monica,

In LiveCode, you can put lines before a list, using the syntax

put "this is a line" & cr before myList

If you have tab-delimited data, you can put another tab-delimited lines before your data using the put before syntax. You could create a field, set the tabstops of that field and put your tab-delimited data into that field. You can also update the field with the put before syntax:

put "this is a line" & cr before fld x

If you want to display multiple rows in one cell, then you might want to check out the data grid or create a group of fields, and write a script to update the data in and sizes of these fields.

Hopefully this gets you started.

Mark

Re: Horizontal Looping Repeat Region

Posted: Mon Aug 13, 2012 5:48 pm
by monicaBUSGk9X
Hi Mark,

Thanks for the suggestions. I'm not certain how that would loop an image both horizontally and vertically?

I'll work up some pseudocode to see if I can clarify. :) Any other thoughts are still welcome!

Thank you!
Monica

Re: Horizontal Looping Repeat Region

Posted: Mon Aug 13, 2012 10:05 pm
by Mark
Hi Monica,

You didn't mention the word "image" in your first post. What is it that you're really trying to do? Do you just want to position pictures evenly on a card? What does it have to with databases? Maybe I don't understand "looping repeat region". Can you explain it in plain simple English?

If you want to position objects, you could do something like this (assuming you have 16 pictures of 32px wide and a margin of 8):

Code: Select all

repeat with x = 1 to 4
  repeat with y = 1 to 4
    put x*4+y-4 into z
    put x*40-32 into myLeft
    put y*40 into myTop
    if there is an image z then
      set the topLeft of img z to myLeft,myTop
    end if
  end repeat
end repeat
Maybe this is what you're looking for?

Re: Horizontal Looping Repeat Region

Posted: Fri Aug 17, 2012 8:38 pm
by monicaBUSGk9X
Hi Mark,

Sorry! :shock: I thought the attachment would have been clear enough to read the "Image or Text" on it but now I see that's is relatively fuzzy. Yes, my intent is to position pictures, and in some cases a fixed size text block, evenly on a card.

The database comes in because the filenames are coming from a MySQL database. Think of a photogallery being generated from a table in a MySQL database and we're making the thumbnails. And when the thumbnail is clicked it does some action. Here is an example in PHP/HTML code of what I'm attempting using a table with rows/columns.

Code: Select all

<?php
// Get Records
mysql_select_db($database_connMySQL, $connMySQL);
$query_rsVideos = "SELECT * FROM tbl_videolist WHERE vid_subcatid = 100 ORDER BY vid_videoid ASC";
$rsVideos = mysql_query($query_rsVideos, $connMySQL) or die(mysql_error());
$row_rsVideos = mysql_fetch_assoc($rsVideos);
$totalRows_rsVideos = mysql_num_rows($rsVideos);
?>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
<?php
// Loop Script
$rsVideos_endRow = 0;
$rsVideos_columns = 3; // number of columns
$rsVideos_hloopRow1 = 0; // first row flag
do {
    if($rsVideos_endRow == 0  && $rsVideos_hloopRow1++ != 0) echo "<tr>";
   ?>

    <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="4">
      <tr>
        <td width="250" height="250" align="left" valign="top">
        <a href="index.php" ><img src="images/<?php echo $row_rsVideos['vid_folder']; ?>/<?php echo $row_rsVideos['vid_filename];?>"  />
        </td>
      </tr>
    </table>
</td>
    <?php  $rsVideos_endRow++;
if($rsVideos_endRow >= $rsVideos_columns) {
  ?>
  </tr>
  <?php
 $rsVideos_endRow = 0;
  }
} while ($row_rsVideos = mysql_fetch_assoc($rsVideos));
if($rsVideos_endRow != 0) {
while ($rsVideos_endRow < $rsVideos_columns) {
    echo("<td>&nbsp;</td>");
    $rsVideos_endRow++;
}
echo("</tr>");
}?>
</table>


Re: Horizontal Looping Repeat Region

Posted: Sun Aug 26, 2012 10:35 pm
by Mark
Hi,

Have you solved this problem yet? If not, then what exactly is the problem? Are you also asking how to get data from a database or do you only need to position pictures and text?

You could do something like this:

- get return and tab delimited data from database
- repeat over each line and each item of each line
- check if an item is a filename or text
- if filename, then create new image and set filename of image object
- if text then create new field and set text of field
- do a repeat loop over all new fields and images as in my example

Let me know with which part you need more help.

Kind regards,

Mark