PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Sat May 14, 2005 8:15 am
Hi Gang,
I have the following code on a page that I have repeated ALOT of times (At least 250 (split into functions etc)).
My question is how could I code it without having to copy/paste this multiple time.
Obviously the Title (Dry Strength) and name (strength) change for each table.
Any ideas?
TIA, Wil
Code: Select all
<tr><td width=200px colspan=2 valign=top>Dry Strength</td>
<td width=50px colspan=2><input type='text' name='strength'SIZE="20"></td</tr>
Last edited by
facets on Sat May 14, 2005 9:01 pm, edited 1 time in total.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Sat May 14, 2005 8:29 am
a for or while loop
Code: Select all
$title=array('dry strength','wet strength', 'damp strength', 'moist strength');
$name = array('dry','wet', 'damp', 'moist');
for($x = 0; $x<count($title); $x++)
{
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$title[$]."</td>\n";
echo <td width=\"50px\" colspan=\"2\"><input type=\"text\" name=\"".$name[$x]." SIZE=\"20\"></td></tr>\n";
}
or you can use a 2d array it you wish
http://uk.php.net/types.array
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Sat May 14, 2005 8:56 am
thanks for the swift reply.
I'm getting an error "Parse error: parse error, expecting `T_VARIABLE' or `'$'' in c:\program files\easyphp1-8\www\materialsregister\auaddsummary.php on line 243"
(Which is the first echo line).
Any ideas?
Code: Select all
$desc=array('Description','Basis Weight');
$name = array('$description','$basisWeight');
for($x = 0; $x<count($desc); $x++)
{
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$desc[$]."</td>\n";
echo "<td width="50px\" colspan=\"2\">".$name[$x]."</td></tr>\n";
}
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat May 14, 2005 9:26 am
You forgot to escape one of your quotes.
..should be..
Code: Select all
echo "<td width=\"50px\" colspan=\"2\">".$name[$x]."</td></tr>\n";
Last edited by
John Cartwright on Sat May 14, 2005 9:35 am, edited 1 time in total.
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Sat May 14, 2005 9:27 am
You realize that this sets the array to
text , right?
Code: Select all
$name = array('$description','$basisWeight');
Here's your error.
This:
Code: Select all
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$desc[$]."</td>\n";
should be:
Code: Select all
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$desc[$i]."</td>\n";