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
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Fri Feb 18, 2005 12:11 pm
I am a bit of a newbie to php.
I want to insert a php script into a php file so that when I want to call it up all I have to do is enter the variable.
Please could someone make this script so that all I have to do is enter it in the page and I can call up the variable.
Heres the code I want to call up.
Code: Select all
<?php
$location = "localhost";
$username = "hillclim";
$password = "XIxIMeulOO";
$database = "hillclim";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "SELECT * FROM xmb_members";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
echo "<br>$rowїsite]";
}
?>
moiseszaragoza
Forum Commoner
Posts: 87 Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:
Post
by moiseszaragoza » Fri Feb 18, 2005 12:32 pm
What you need to do is save your connection in a document called connection.php that would hold your connection string
Code: Select all
<?php
$location = "localhost";
$username = "hillclim";
$password = "XIxIMeulOO";
$database = "hillclim";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
?>
Then you will just need to include it in your file
Code: Select all
<?php require_once('connection.php''); ?>
so that line will be in the top of any page that you want the connection.
and after you will write your query
I hope I was of any help
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Fri Feb 18, 2005 12:38 pm
I'll explain in more detail.
I have a forum with a portal, and I am trying to create a table in it.
The table has to go in a template, which I can't put php in, but I can put variables. These templates are part of a php file in which I can put php.
Basically I want to make it so that in the template all I have to do is insert a variable ($*****).
Adam
moiseszaragoza
Forum Commoner
Posts: 87 Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:
Post
by moiseszaragoza » Fri Feb 18, 2005 12:40 pm
so you can not run a php include
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Fri Feb 18, 2005 12:41 pm
Nope, but I can put in a $***** and it'll recognise it.
Adam
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Fri Feb 18, 2005 1:16 pm
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Fri Feb 18, 2005 1:34 pm
Soomething like this code.
Code: Select all
<?php
$hello = '$location = "localhost";
$username = "hillclim";
$password = "XIxIMeulOO";
$database = "hillclim";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "SELECT * FROM xmb_members";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
echo "<br>$rowїsite]";
}';
echo "$hello"
?>