View Full Version : Making A Function


PunkGo
09-30-2003, 10:21 PM
hey, i save around 1000 lines of code using functions, i make a sepertae file, for it....so all i have to do is just include that file in the pages i wanna use it, then call for the function, ok...heres whut u do for a function, i usefunctions only for html, tho they can be for other things...
//BEGINNING OF FUNCTION's PAGE--
[PHP]
<?php

//lets make a simple mysql_connect function
function connect() {

mysql_connect("localhost", "username", "password")
or die(mysql_error());
mysql_select_db("dbname")
or die(mysql_error());

}
?>

now, the mysql_connect is simple, BUT functions ALWAYS must have () somewhere, i think at the end, then followed by a open braket { u do NOT need a ';' at the end until u call for the function on the page u want..ok, so lets name that...joe.php then lets go to the page that we wanna use it....lets name it... boo.php
--BEGINNING OF boo.php--
<?php

include("joe.php");

connect();
?>

ok, the include, basically includes EVERYthing thats is 'joe.php' into the other, so u can have like 100000 pages linked to one, how would u do that u ask? thats a didfferent story ;-) but i called fo the function and USED the ; ....ok hope this helps!!