keep looping the first row
Posted: Fri Aug 28, 2009 12:32 pm
so I created a function in a separate functions.php file that looks like this:
function getEmails() {
global $host,$username,$password,$db_name,$tbl_name;
$tbl_name="emails"; // Table name
ob_start();
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
mysql_close();
return $row;
}
now on a seperate php page where I want to print all the email address I have this code:
<?php
include_once('functions.php');
while($row = getEmails()){
echo $row['emails'];
echo "<br />";
}
?>
this gets me the first row of my table and repeats it over and over again until I get an error saying:Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40961 bytes)
can anyone help me with this? thanks
Newbie
function getEmails() {
global $host,$username,$password,$db_name,$tbl_name;
$tbl_name="emails"; // Table name
ob_start();
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
mysql_close();
return $row;
}
now on a seperate php page where I want to print all the email address I have this code:
<?php
include_once('functions.php');
while($row = getEmails()){
echo $row['emails'];
echo "<br />";
}
?>
this gets me the first row of my table and repeats it over and over again until I get an error saying:Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40961 bytes)
can anyone help me with this? thanks
Newbie