Variable

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

Post Reply
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Variable

Post by phelpsa »

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))&#123;
    echo "<br>$row&#1111;site]";
&#125; 

?>
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Post by moiseszaragoza »

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 »

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
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Post by moiseszaragoza »

so you can not run a php include
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

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 »

phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

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))&#123;
    echo "<br>$row&#1111;site]";
&#125;';

echo "$hello"

?>
Post Reply