Hi,
I made one file to connect to the database.
connect.php
$link;
connect();
function connect(){
global $link;
$db='dbname';
$link=mysql_connect('localhost');
if (! $link){
print "could not connect database<br>".mysql_error();
}
$selectdb=mysql_select_db($db);
if (!$selectdb){
print "could not select db<br>";
}
}
Next file to display data display.php.
include("connect.php");
function display(){
global $link;
$query="select * from mytable";
$result=mysql_query($query,$link);
if (! $result){
print ("error mysql. ");
}
while($row=mysql_fetch_array($result)){
print "$row[name]";
}
}
mysql_close($link);
}
On Index file i show the data index.php.
include("connect.php");
display();
This is working fine.
Third file to display more data with display function more.php.
include("connect.php");
display();
include("connect.php");
function displaymore(){
global $link;
$query="select * from mytable";
$result=mysql_query($query,$link);
if (! $result){
print ("error mysql. ");
}
while($row=mysql_fetch_array($result)){
print "$row[student]";
}
}
mysql_close($link);
}
One more.php it is throwing an error saying that connect() is redefined .If i remove include("connect.php"); then it says not a valid MySQL-Link resource.
Please help.
Thanks