Can I store this PHP code in another page, then refernece it on
multiple pages using Require or Include ???
//results from sql query
for ($i=0; $i<$number; $i++) {
$ID = mysql_result($r esult,$i,"ID");
$CompanyName = mysql_result($r esult,$i,"1");
$ContactName = mysql_result($r esult,$i,"2");
$Phone = mysql_result($r esult,$i,"3");
$HomePhone = mysql_result($r esult,$i,"4");
$MobilePhone = mysql_result($r esult,$i,"5");
$AltPhone = mysql_result($r esult,$i,"6");
$SecondContact = mysql_result($r esult,$i,"7");
$SecondPhone = mysql_result($r esult,$i,"8");
$ThirdContact = mysql_result($r esult,$i,"9");
$ThirdPhone = mysql_result($r esult,$i,"10");
$Notes = mysql_result($r esult,$i,"11")
This will save me having to have all that on the pages its needed if I
can be used from another page ! 4 5751
On Tue, 15 Jul 2003 08:05:27 -0500, Frank wrote: Can I store this PHP code in another page, then refernece it on multiple pages using Require or Include ???
//results from sql query for ($i=0; $i<$number; $i++) { $ID = mysql_result($r esult,$i,"ID"); $CompanyName = mysql_result($r esult,$i,"1"); $ContactName = mysql_result($r esult,$i,"2"); $Phone = mysql_result($r esult,$i,"3"); $HomePhone = mysql_result($r esult,$i,"4"); $MobilePhone = mysql_result($r esult,$i,"5"); $AltPhone = mysql_result($r esult,$i,"6"); $SecondContact = mysql_result($r esult,$i,"7"); $SecondPhone = mysql_result($r esult,$i,"8"); $ThirdContact = mysql_result($r esult,$i,"9"); $ThirdPhone = mysql_result($r esult,$i,"10"); $Notes = mysql_result($r esult,$i,"11")
This will save me having to have all that on the pages its needed if I can be used from another page !
Why not just use mysql_fetch_arr ay() and access
the fields by name? Try this:
$myrow = mysql_fetch_arr ay ($result, MYSQL_BOTH);
Now all of the fields will be in the $myrow array.
You can access the values by number or name. So this
code will print the company name.
echo $myrow['1'];
HTH
<Frank @ MyPlace.Com (Frank)> wrote in message
news:3f******** ********@news.b tclick.com... Can I store this PHP code in another page, then refernece it on multiple pages using Require or Include ???
//results from sql query for ($i=0; $i<$number; $i++) { $ID = mysql_result($r esult,$i,"ID"); $CompanyName = mysql_result($r esult,$i,"1"); $ContactName = mysql_result($r esult,$i,"2"); $Phone = mysql_result($r esult,$i,"3"); $HomePhone = mysql_result($r esult,$i,"4"); $MobilePhone = mysql_result($r esult,$i,"5"); $AltPhone = mysql_result($r esult,$i,"6"); $SecondContact = mysql_result($r esult,$i,"7"); $SecondPhone = mysql_result($r esult,$i,"8"); $ThirdContact = mysql_result($r esult,$i,"9"); $ThirdPhone = mysql_result($r esult,$i,"10"); $Notes = mysql_result($r esult,$i,"11")
This will save me having to have all that on the pages its needed if I can be used from another page !
Not only can you, but you should. Code duplication should be avoided at all
costs. It will save you so much time later if you consolidate repeated code
into a single file. Just think of include() as a way of inserting an entire
file in-line with your current file.
Also, read the PHP manual about the mysql_result() function. It says:
"When working on large result sets, you should consider using one of the
functions that fetch an entire row (specified below). As these functions
return the contents of multiple cells in one function call, they're MUCH
quicker than mysql_result(). "
"Recommende d high-performance alternatives: mysql_fetch_row (),
mysql_fetch_arr ay(), and mysql_fetch_obj ect()."
HTH,
Zac
Tony, I'm new to this, can you point me in the right direction ??
Thanks ! I would strongly recommend that you use a function which returns the result set as an associative array so that you can access field values using the field name rather than its sequence number in the array. Not only does it make it easier to code, it also gets around the problem that can be caused if the fields get returned in a different sequence.
That's just my opinion.
Tony Marston http://www.tonymarston.net/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Cocker |
last post by:
Hello,
I'm quite weak at PHP, so I was hoping to get some help understanding the
below code. First off, I'm trying to create a "query form" that will allow
me to display the results on my screen. I grabbed this code from the net
hoping that I could tweak it for my needs. I'm using MySQL, PHP and IIS and
they all are running fine. As the...
|
by: Bob Bedford |
last post by:
I've a query quite important to execute.
I've to fill an array with all result, so the query is called once wich
returns all ID's
Then I call the same query a second time as I shown only 10 results in my
page.
How can I avoid to call the query twice ?
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also...
|
by: david liu |
last post by:
access 2000 query:
here's what i want to do. from an asp page, perform a search on a
table in access. i have used sql code in the asp page itself, but i'd
rather execute a query in access. i have success in running any query
(basic SELECT, SELECT with conditions _other_ than LIKE, etc..) for
some reason, when i execute the query below from...
|
by: Mattyboy |
last post by:
Guys
I have built a database with saved queries that runs fine in Access
but when I call it from the web using ASP, an exception occurs. I
have tried multiple ways of testing the databases with the following
results. www.brinkster.com has a tool on their free asp hosting where
you can dump an access .mdb database on there and then run SQL...
| |
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID SalesManName
AT Alan Time
|
by: webhead74 |
last post by:
Hi,
I'm having intermittent problems with queries from my php script to a
postgresql database.
I have a form where I can enter a search query - for instance a last
name. This leads to a results page with a brief bit of information
about each of the matching results. From there, I can click a link
associated with any of the results...
|
by: milo1955 |
last post by:
I have a form that passes a single variable via the GET function to a mysql databse query with the results paginated. The first page of the results work fine, but the link to the second page yields the page 2 results of the entire table. I'm guessing that the variable hasn't passed to page2 query? Please excuse my ignorance. Here's my code:
...
|
by: bugboy |
last post by:
Hi, I'm just learning PHP. I want to redirect the user, after hitting submit, either to the same page displaying the results (as it is now) or if no results are found then send them to a new page passing on the original form data there instead.
Below is a simplified version of what i'm trying to do. The user sumits a word. If it's in the DB...
|
by: Lloyd Harold |
last post by:
I'm very new to PHP and attempting to put together a simple script for
retrieving MySQL data of personal records.
The MySQL table I'm using consists of:
0: id
1: name
2: location (an integer relating to a separate table of locations).
3: details
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |