473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

calling individual functions on a remote php page

tolkienarda
316 100+
hi all

i am building a small private school management program and i use alot of the same loops, update statements, and whatnot and i would like to put them all into one php file divided into their own functions. i was just wondering if it is possible to call an individual function on a remote php page.

thanks
eric
Jan 19 '07 #1
10 1815
cassbiz
202 100+
Of course you can,

Create all of the functions on a separate page ie function.php

then of course you list your functions on that page

Expand|Select|Wrap|Line Numbers
  1. function dbconnect()
  2. {
  3.         global $db, $t_global;
  4.         $db_con = @MYSQL_CONNECT($db['server'],$db['user'],$db['passwortd]) or die ($t_global['query_false']);
  5.         $db_check = @MYSQL_SELECT_DB($db['name']);
  6. }
  7.  
  8. blah, blah, blah
  9.  
  10.  
The in the actual php page that you are using you will need to include the function page

Expand|Select|Wrap|Line Numbers
  1. <?
  2.                 include "function.php";
  3. ?>
  4.  
And to call the function in your php page you will need to do like the following

Expand|Select|Wrap|Line Numbers
  1. $connect = dbconnect();
  2.  
Hope the above helps and Good Luck!
Jan 19 '07 #2
tolkienarda
316 100+
cool awesome thanks

eric
Jan 19 '07 #3
ronverdonk
4,258 Expert 4TB
Small correction: in order to use this command[php]$connect = dbconnect();[/php] the dbconnect function must return a value, otherwise you cannot assign it to the $connect variable.

Ronald :cool:
Jan 19 '07 #4
cassbiz
202 100+
Small correction: in order to use this command[php]$connect = dbconnect();[/php] the dbconnect function must return a value, otherwise you cannot assign it to the $connect variable.

Ronald :cool:

Hi Ronald,

I don't quite understand what you mean when you say a variable. Now I know enough to not know -- LOL

What type of variable has to be assigned?
Jan 19 '07 #5
ronverdonk
4,258 Expert 4TB
When you assign like
Expand|Select|Wrap|Line Numbers
  1. $connect = dbconnect(); 
you actually assign the result of the function dbconnect() to the variable $connect.
Since the function dbconnect() does not return anything, no data or boolean, the assignment has no meaning. You cannot properly use variable $connect. Maybe you don't want to, but then the assignment is useless.

Ronald :cool:
Jan 19 '07 #6
cassbiz
202 100+
OK, I see what you are saying.

The way I have used it has been many times as a straight function call

Expand|Select|Wrap|Line Numbers
  1. dbconnect ();
  2.  
but I have also used it as in the previous example with other functions.

thanks again.

I still have a lot to learn and just don't quite completely understand the manuals and tutorials.
Jan 19 '07 #7
ronverdonk
4,258 Expert 4TB
Yes, a straight function call is fine. But, in this case, I would have passed on a false if an error had occurred during the connect or db select, and a true when no error had occurred.

So the statement then could be [php]if (!dbconnect())
die ("Some error at connect");
else
// continue processing[/php]
Ronald :cool:
Jan 19 '07 #8
cassbiz
202 100+
kewlness!

Thanks for that snippet, I will integrate it into my own scripts.
Jan 20 '07 #9
tolkienarda
316 100+
maybe not the best place to put this post but...

I love this site. thescripts is the reason i have a job. i was hired to build php scripts with mysql database communication three months ago and i knew html and had heard of php but had never seen the code. now thanks to ron and other members I am building database driven sites without you guys and your detailed descriptions and fast replys to questions i probably wouldn't have a job

thanks
eric
Jan 21 '07 #10
ronverdonk
4,258 Expert 4TB
That is the best compliment you could give the team. Thanks.

Ronald :cool:
Jan 21 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Praveen Srinivasan | last post by:
Hi all, Are there any important issues that one should be aware of when calling C++ functions from C? In particular, I'm passing a function pointer to a C routine in a library, and in that...
10
by: reynoldscraigr | last post by:
Hi All, I am trying to call 2 functions from the 1 onMouseOver event on an anchor tag, but I can't seem to get it to work. the following should demonstrate <a...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
2
by: Rob | last post by:
Hi Gang: I have a page that loads a remote page into an IFRAME. I don't have any control over this remote page though the page is owned by the same company I work for. The problem is that all...
4
by: William Hudson | last post by:
I want to be able to ask users for a URL, open that page, change some of the contents and then display that page as if they had typed the URL into a browser. I have toyed with some of the php...
46
by: Usenet User | last post by:
I need to be able to call the same API function from VB, which will reside in different DLLs. While all of the functions have the same signature and name, DLL file names are not known at compile...
4
by: Meya-awe | last post by:
Hi, What does C# has to offer for calling system functions from within the VS .NET C# project? I want to kickoff a script or a batch file from my code. thanks, BRAMOIN *** Sent via...
2
by: Fernando Rodríguez | last post by:
Hi, How can I retrieve the "description" meta tag of a remote page? Thanks! Fernando
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.