Author Topic: Manupulate data before loop  (Read 1097 times)

0 Members and 1 Guest are viewing this topic.

BM

  • Guest
Manupulate data before loop
on: Fri, 01. November 2002 - 18:37:15
I've had a look at the docs,  but can't see anything that shows me how to do this.  

I'm hoping to grab xxxx rows from the db and compare values then output the difference between timestamps.  I just can't work out how to do this  :cry:


Any examples or a nudge in the right direction will be greatly appreciated.

Thanks.

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Manupulate data before loop
Reply #1 on: Fri, 01. November 2002 - 23:40:07
Imho it is not working with
setdbloop

but that is no problem, since you can use a normal loop:

Look at this two examples:

http://lamp.clausvb.de/examples/vlibTemplate_db.php
You want to add extra fields to your LOOP? This example shows you how.

http://lamp.clausvb.de/examples/vlibTemplate_db_adv.php
If you want to "SELECT * FROM $dbtable" you possibly need a dynamic LOOP structure. Click here and you will soon know how to accomplish your goal.

And I have one just for you (:D) in storage:

Code: [Select]

$perDayGraphics = array;



while $row = mysql_fetch_array$result



   array_push$perDayGraphics, array

   'gifHeight' = 5*$rowcount,

   'count' = $rowcount,

   'descr' = $date-formatDate$rowday, '%A, %d. %B %Y';





$tpl-setloop'perDayGraphics', $perDayGraphics;



Look at the lines, where the DB content gets changed:
You can use "5*" or substraction or a function (like "formatDate") or ... or ... or
it does not matter. You can program whatever you like.

Best regards,
Claus

releasedj

  • Guest
Manupulate data before loop
Reply #2 on: Sat, 02. November 2002 - 00:04:53
It's difficult to give an informed response without further elaboration.

The easiest way to set rows 'on the fly' is to use the 3-step-process of adding a loop.. look again at the <tmpl_loop> section of the docs.

If you give more detailed information then someone may be able to help you do what you need.

Regards,

Kelvin

BM

  • Guest
Manupulate data before loop
Reply #3 on: Mon, 04. November 2002 - 13:04:06
Thanks for your response guys.

I'm tearing my hair out now!   I've never used templates before, yet this current project I'm working on must be completed with them.


I've used and modified Claus' code,  but I'm not getting any output from the database.   Maybe my syntax is wrong?

Below is what I've got already...

Code: [Select]

$loopRestaurant = array;



while$row = mysql_fetch_array$result



    array_push$loopRestaurant, array

    'txtRestaurantName' = $rowtxtCity,

      'isOpen' = hourDiff$rowtimeOpen,$rowtimeClose;





$tmpl-setloop'loopRestaurant', $loopRestaurant;


releasedj

  • Guest
Manupulate data before loop
Reply #4 on: Mon, 04. November 2002 - 13:47:05
The syntax looks correct.

Are you sure that the mysql result is returning data?
To check that the loop is being inserted, you can use the vlibTemplateDebug class... in your php, change your class instantiation to:

Code: [Select]

?php

// .. whatever goes before

    $tmpl = new vlibTemplateDebug'/path/to/template/file';

// .. whatever goes after

?



This will output a debug console which will give you details of all variable and loops that have been set.

You can then see exactly what vlibTemplate is working with!

I hope this helps, if not then let me know, I'm more than happy to help.

Regards,

Kelvin

BM

  • Guest
Manupulate data before loop
Reply #5 on: Mon, 04. November 2002 - 14:22:49
Thanks again!

I have managed to get it doing what I want after going through all the posts on the vlibTemplate forum and getting my head around the logic of it (very logical!).

Again,  thanks very much.

releasedj

  • Guest
Manupulate data before loop
Reply #6 on: Mon, 04. November 2002 - 14:31:52
No problem, I'm happy to see that you got it working.