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

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 August 24th, 2003, 03:58 PM
Volitics Volitics is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58 Volitics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 15 sec
Reputation Power: 6
How Do I Insert "for" Loop In Class Module?

Below are three scripts that create one page. The "TopNewsPageTwo.php" script creates an instance, the "HtmlTemplateClass.php" is the class used with the instance script, and the "TopNewsTemplateP2.php" template below displays the output in the browser.

My problem is this: How do I insert a "for" loop so that the output will display on the page (see "TopNewsTemplateP2.php" below for the desired positioning)?

The "for" loop that I'm needing to incorporate into the process is as follows:

$TextBoxes = "$Paragraphs";
for($i=1; $i<=$TextBoxes; $i++)
{
echo "<textarea rows=\"3\" cols=\"40\" name=\"Textfield\"" . "[$i]" ."></textarea><p>" . "\n";
}


What I would like to do is somehow incorporate the "for" loop in the "HtmlTemplateClass.php" class module, if possible, so that I may separate the PHP code from the HTML code.

Does anyone have any suggestions about how I might accomplish my task?
PHP Code:
// -------- TopNewsPageTwo.php ---------------
// Creates an instance "TopNewsPageTwo.php"
// This page receives the "$Year"."$Month"."$Day"."$Number" variables from an input
// form on a previous page, checks them (ref. $CheckReference) to see if there is
// an existing news article in the "TopNews" table. If no article with the same
// reference number in the "TopNews" table then this page creates an instance.
require_once "./conf/config.inc.php";
$CheckReference "$Year"."$Month"."$Day"."$Number";    
$Date "$Year"."$Month"."$Day";
$TableName "TopNews";
$Query="SELECT Reference FROM $TableName";
$Result mysql_db_query ($db_info[dbname], $Query$db_connection);
while (
$Row mysql_fetch_array($Result))
{
    if (
$CheckReference === $Row["Reference"])
    {
    
$TakenInUse="That news reference is currently in use. Please make another choice.";
    }
}
mysql_close ($db_connection);
if (isset(
$TakenInUse))
{
echo 
$TakenInUse;                                                 
}else{ 
// If the $CheckReference variable does not exist in database do the following:
require_once "HtmlTemplateClass.php"// Include the class.
$page = new HtmlTemplate(); // Create an instance.
$page->IdentifyTemplate ("TopNewsTemplateP2.php"); // Identify the template.
//----------------------
$page->SetParameter ("PAGE_TITLE""Welcome to OOP!"); 
$page->SetParameter ("PAGE_CONTENT""Here is the main part of the page."); 
$page->SetParameter ("NEWS_REFERENCE_NUMBER""$Year"."$Month"."$Day"."$Number"); 
$page->SetParameter ("MONTH""$Month"); // Set the month.
$page->SetParameter ("DAY""$Day"); // Set the day.
$page->SetParameter ("YEAR""$Year"); // Set the year.
$page->SetParameter ("DATE""$Year"."$Month"."$Day"); // Set the date.
//----------------------
$page->CreatePage(); // Send the page to the browser.
}

// -------- HtmlTemplateClass.php ---------------
// This is the class that is used with the "TopNewsPageTwo.php" script above.
class HtmlTemplate {

    
// Set the attributes.
    
var $Template;
    var 
$Html;
    var 
$Parameters = array();

    function 
IdentifyTemplate ($Template) { // This function sets which template will be used.
        
$this->Template $Template;
    }

    function 
SetParameter ($Variable$Value) { // This function sets the particular values.
        
$this->Parameters[$Variable] = $Value;
    }

    function 
CreatePage () { // Read the template into an array, then create a string.
        
$this->Html implode ("", (file($this->Template))); 
    
        
// Loop through all the parameters and set the variables to values.
        
foreach ($this->Parameters as $Key => $Value) { 
            
$TemplateName '{' $Key '}';
            
$this->Html str_replace ($TemplateName$Value$this->Html);
        }    
        echo 
$this->Html;
    }
}

// -------- TopNewsTemplateP2.php ---------------
// This is the template that is used with the "TopNewsPageTwo.php" instance
// and the "HtmlTemplateClass.php" class above.
<html>
<
head>
    <
title>{PAGE_TITLE}</title>
</
head>
<
body><center>
<
table border="1" cellspacing="5" cellpadding="5">
<
tr><td><p>
<
span class="text5">News Reference <b>{NEWS_REFERENCE_NUMBER}</b></span><p>
<
form action="PageThree.php" method="post"><p>
<
input type="hidden" name="Reference" value="{NEWS_REFERENCE_NUMBER}"><p>
<
input type="hidden" name="Month" value="{MONTH}"><p>
<
input type="hidden" name="Day" value="{DAY}"><p>
<
input type="hidden" name="Year" value="{YEAR}"><p>
<
input type="hidden" name="Date" value="{DATE}"><p>

// I need to insert the output from this loop here.
// The $Paragraphs variable is received from a form on a previous page.
$TextBoxes "$Paragraphs";
for(
$i=1$i<=$TextBoxes$i++)
  {
    echo 
"<textarea rows=\"3\" cols=\"40\" name=\"Textfield\"" "[$i]" ."></textarea><p>" "\n";
  }
// Insert output from loop immediately above.
</form></td></tr><p>
</
table>
</
center></body>
</
html>
//------------------------- 


Thanks.

Volitics
__________________
Thomas Jefferson: "Democracy will work only until the political incumbents discover they can perpetuate themselves in office by taxing the industrious to bribe the indolent."

Reply With Quote
  #2  
Old August 25th, 2003, 12:39 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
In TopNewsPageTwo.php:
PHP Code:
 $TextBoxes $Paragraphs;
for(
$i=1$i<=$TextBoxes$i++)
  {
    
$pg[] = "<textarea rows=\"3\" cols=\"40\" name=\"Textfield\"" "[$i]" ."></textarea><p>";
  }

$page->SetParameter "PARAGRAPHS"join("\n"$pg) ); 
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old August 25th, 2003, 04:11 AM
Volitics Volitics is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58 Volitics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 15 sec
Reputation Power: 6
laidbak;

Thank you for your kind help.

I've got to go to work today but will give it a try this evening.

Thanks again.

Volitics

Reply With Quote
  #4  
Old August 25th, 2003, 05:16 AM
Volitics Volitics is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58 Volitics User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 15 sec
Reputation Power: 6
laidbak;

It works great! I appreciate the help.

Best Regards;

Volitics

Reply With Quote
  #5  
Old August 25th, 2003, 10:03 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
No problem. Glad it worked.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > How Do I Insert "for" Loop In Class Module?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway