
July 23rd, 2004, 05:24 PM
|
|
Contributing User
|
|
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,121
Time spent in forums: 2 h 43 m 44 sec
Reputation Power: 3
|
|
|
A Lesson in Functions
Just a little lesson in fonctions for everyone out there.
Say you have some deta that all the same basic look but sime different data, say a listing of books and you dont want to have to loop a file try this
php Code:
Original
- php Code |
|
|
|
// declare the function to be used function BookDisply($imageurl, $descrip, $avail, $USPrice, $CANPRICE){ /* now code it as you would normally co de the outpit for one item, rember anything theirs a varible/changeing item puta varibl in its place in the code and cocatonat e it with periods so it flows evenly, and every variable you use in the function below put its varible in the () of the function decleration above. */ echo '<table width="75%" border="0" align="center" cellpadding="0" cellspacing="3"><tr><td width="35%" align="center">'; echo '<img src="' . $imageurl . '" border="1"></td><td><p><font color="#000000" size="2" face="Arial">' . $descrip . '<br>'; echo '<font color="#FF0000">' . $avail . '</font></font>'; echo '<table width="35%" border="0" cellspacing="0" cellpadding="0">'; echo '<tr><td width="25%"><font color="#FF0000" size="2" face="Arial">Price:</font></td>'; echo '<td width="28%"><font color="#FF0000" size="2" face="Arial">' . $USPrice . '</font></td>'; echo '<td width="47%"><font color="#FF0000" size="2" face="Arial">US</font></td></tr><tr>'; echo '<td><font color="#FF0000" size="2" face="Arial"> </font></td>'; echo '<td><font color="#FF0000" size="2" face="Arial">' . $CANPRICE . '</font></td>'; echo '<td><font color="#FF0000" size="2" face="Arial">CAN</font></td>'; echo '</tr></table></td></tr></table><BR>'; }
so what does this do for us?
php Code:
Original
- php Code |
|
|
|
BookDisply("letscountSM.jpg", "Let's Count, with its attractive, vivid illustrations of amusing animals is a fun way to teach young readers to count from 1 to 10.", "Will be available in stores by August 2004", "$15.99", "$24.99");
Every time we call the function and populate its "fields" in the () they replae the variables in the function and produce you little display, now yo dont need 13 tables only 1 and just have to give it the values you want for each table!
|