Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 30th, 2002, 11:32 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Article Discussion: Simple PHP Templates With PatTemplate

Simple PHP Templates With PatTemplate

Phew, finally able to visit devarticles.com again.. The DNS server I was using never updated itself.. so all I got was a blank page.. oh well..

If you have any questions or comments for this article or topic, please post them here.

You can read the article here .
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #2  
Old July 6th, 2002, 02:42 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Havard,

I'm having a little trouble with alternating my row colors.... I'm starting to lose my mind!

Here's the code:
Table
PHP Code:
<patTemplate:tmpl name="list" type="OddEven">
<
patTemplate:sub condition="odd">
<
tr>
        <
td bgcolor="#d5dfef"><a href="editclient.php?id={CLIENTID}">{CLIENTNAME}</a></td>
        <
td bgcolor="#d5dfef"><a href="mailto:{CLIENTEMAIL}">{CLIENTCONTACT}</a></td>
</
tr>
</
patTemplate:sub>
<
patTemplate:sub condition="even">
<
tr>
        <
td bgcolor="#d9d9d9"><a href="editclient.php?id={CLIENTID}">{CLIENTNAME}</a></td>
        <
td bgcolor="#d9d9d9"><a href="mailto:{CLIENTEMAIL}">{CLIENTCONTACT}</a></td>
</
tr>
</
patTemplate:sub>
</
patTemplate:tmpl


Script
PHP Code:
while ($row mysql_fetch_array($result)){
    
$clientId $row["clientId"];
    
$clientName $row["clientName"];
    
$clientContact $row["clientContact"];
    
$clientEmail $row["clientEmail"];

    
$template->addVar("list""CLIENTID"$clientId);
    
$template->addVar("list""CLIENTNAME"$clientName);
    
$template->addVar("list""CLIENTCONTACT"$clientContact);
    
$template->addVar("list""CLIENTEMAIL"$clientEmail);

    
$template->parseTemplate("list""a");
                                    
}

$template->DisplayParsedTemplate("listclients"); 


Any help would be appreciated. I only have it displaying in one color. Any ideas?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old July 6th, 2002, 03:25 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Hi Frank,

I've had problems with that too.. A solution might be to dynamically generate an array with all of the values, then use the addVars() function..

the array has to be an associative array like this:

array(CLIENTID => array(1, 2, 3),
CLIENTNAME => array("Client1", "Client2", "Client3")
);

Hope it works out for you

Reply With Quote
  #4  
Old July 6th, 2002, 03:30 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Quote:
Originally posted by Lindset
Hi Frank,

I've had problems with that too.. A solution might be to dynamically generate an array with all of the values, then use the addVars() function..

the array has to be an associative array like this:

array(CLIENTID => array(1, 2, 3),
CLIENTNAME => array("Client1", "Client2", "Client3")
);

Hope it works out for you


I'm not sure if I know what you mean... What would replace "Client1", "Client2", etc? Are those the hardcoded values, or variables?

I'm somewhat in a bind... using the templates has made certain aspects so much easier, but in other respects, it's a pain in the a*s! :P

Any help would be great! TIA!

Reply With Quote
  #5  
Old July 6th, 2002, 03:32 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Here's something you can do.. just an example

PHP Code:
while ($row mysql_fetch_array($result)) {
    
$return['username'][] = $row['username'];
    
$return['password'][] = $row['password'];
}
    
$tmpl->addVars("namelist"$return); 


I just had to test it myself before I posted it here

Last edited by Lindset : July 6th, 2002 at 03:35 PM.

Reply With Quote
  #6  
Old July 6th, 2002, 03:36 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Quote:
Originally posted by Lindset
Here's something you can do.. just an example

PHP Code:
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
    
$return['username'][] = $row['username'];
    
$return['password'][] = $row['password'];



I just had to test it myself before I posted it here


Does that assign $row['username]' to the 2nd [], and so on? I get too confused when dealing with multi-dimensional arrays....

Reply With Quote
  #7  
Old July 6th, 2002, 03:40 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
If you execute these lines of code:
$array['somename'][] = "Yes";
$array['somename'][] = "Sir";
$array['blah'][] = "Test";
$array['blah'][] = "Me";

The value of:
$array['somename'][0] would be "Yes"
$array['somename'][1] would be "Sir"
$array['blah'][0] would be "Test"
$array['blah'][1] would be "Me"

When you use [] it will be applied at the end of the array..

Reply With Quote
  #8  
Old July 6th, 2002, 03:44 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Here's the code that would make the alterning colors work for you.

PHP Code:
while ($row mysql_fetch_array($result)){
    
$clientId $row["clientId"];
    
$clientName $row["clientName"];
    
$clientContact $row["clientContact"];
    
$clientEmail $row["clientEmail"];
    
    
$list['CLIENTID'][] = $clientId;
    
$list['CLIENTNAME'][] = $clientName;
    
$list['CLIENTCONTACT'][] = $clientContact;
    
$list['CLIENTEMAIL'][] = $clientEmail;                                    
}

$tmpl->addVars("list"$list);
$template->DisplayParsedTemplate("listclients"); 


It should work..

Reply With Quote
  #9  
Old July 6th, 2002, 03:45 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Ahh... Okay, so in the case of:

PHP Code:
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
    
$return['username'][] = $row['username'];
    
$return['password'][] = $row['password'];



It's taking the value of "username" and "password" in each row, and assigning it to "$return['username'][0], $return['password'][0]" and "[1][1]" for the next row and so on?

Now when you called:

PHP Code:
 tmpl->addVars("namelist"$return


Does it automatically assume ALL arrays with the prefix "$return" to replace those values?

Reply With Quote
  #10  
Old July 6th, 2002, 03:46 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Quote:
It's taking the value of "username" and "password" in each row, and assigning it to "$return['username'][0], $return['password'][0]" and "[1][1]" for the next row and so on?


Correct

Reply With Quote
  #11  
Old July 6th, 2002, 03:49 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Quote:
Originally posted by Lindset
Here's the code that would make the alterning colors work for you.

PHP Code:
while ($row mysql_fetch_array($result)){
    
$clientId $row["clientId"];
    
$clientName $row["clientName"];
    
$clientContact $row["clientContact"];
    
$clientEmail $row["clientEmail"];
    
    
$list['CLIENTID'][] = $clientId;
    
$list['CLIENTNAME'][] = $clientName;
    
$list['CLIENTCONTACT'][] = $clientContact;
    
$list['CLIENTEMAIL'][] = $clientEmail;                                    
}

$tmpl->addVars("list"$list);
$template->DisplayParsedTemplate("listclients"); 


It should work..


BEEEEUUUUUUTTTTTIIIIIIFFFFFUUUUULLLL!!

It worked... i understand that a lot more now! So by using multi-dimensional arrays, I can store the value of each row's column into a separate element?

Thank you for the help! I would have gone bald soon!

Reply With Quote
  #12  
Old July 8th, 2002, 02:03 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
To everyone that's interested in patTemplate:
http://www.php-tools.de/xena/apps/f...aarticleid=----