I am working on a simple (I thought) function to do a sql querry and loop with a template from a db. In testing I just have the template line as a variable. If I set variable inside the loop it works, but if I bring it in via a function I can not generate the results I am looking for. Note this does nor require a big cURL type template engine I hope
here is what I would like to have work
<?Php // Functions.php file
// Define Basic Functions used by Gambling Portal.
function get_while($template,$table,$where,$count,$order) {
$template=str_replace('SH[','{$get_rows[',$template);
$template=str_replace(']',']}',$template);
$i=0;
$where = $where=="" ? "" : $where;
$order = $order=="" ? "" : $order;
$count = $count=="" ? "" : $count;
$selform="Select * from `$table` $where $count $order";
echo $selform;
$data = mysql_query($selform);
While ($get_rows=@mysql_fetch_array($data)){
//$template = "<tr><td>DATA{$get_rows['id']}</td></tr>";
$values[$i]=$template;
$i++;
}
return $values;
}
?>
Disp file
<?Php
print "Starting execution of Development project.<br />";
print "...<br />";
print "..<br />";
require_once("./includes/functions.php");
require_once("./includes/config.php");
print $config['site']['name'];
require_once("./includes/database.php");
print "Now we are connected to the database";
print "<table width=700 border =2 >";
$template = "<tr><td>SH[casino]</td></tr>";
$valued = get_while($template,casino_p_casinos,"","","");
foreach ($valued as $key => $val) {
print "$val";
}
?>
This unfortunatel outputs
Starting execution of Development project.
...
..
Gambling Portal Now we are connected to the databaseSelect * from casino_p_casinos WHERE software='Rival'
This is the casino {$get_rows['casino']}
This is the casino {$get_rows['casino']}
This is the casino {$get_rows['casino']}
This is the casino {$get_rows['casino']}
This is the casino {$get_rows['casino']}
This is the casino {$get_rows['casino']}
Now, If I create the Var in the loop like this
<?Php
// Define Basic Functions used by Gambling Portal.
function get_while($template,$table,$where,$count,$order) {
$template=str_replace('SH[','{$get_rows[',$template);
$template=str_replace(']',']}',$template);
$i=0;
$where = $where=="" ? "" : $where;
$order = $order=="" ? "" : $order;
$count = $count=="" ? "" : $count;
$selform="Select * from `$table` $where $count $order";
echo $selform;
$data = mysql_query($selform);
While ($get_rows=@mysql_fetch_array($data)){
$template = "<tr><td>DATA{$get_rows['id']}</td></tr>";
$values[$i]=$template;
$i++;
}
return $values;
}
?>
NOTE I Uncommented the $template= in the loop
I get a proper result
Starting execution of Development project.
...
..
Gambling Portal Now we are connected to the databaseSelect * from casino_p_casinos WHERE software='Rival' This is the casino Club Vegas USA
This is the casino Slots of Fortune
This is the casino DaVincis Gold
This is the casino CoCoa
This is the casino Paradice 8
This is the casino This Is Vegas
This is the casino Superior
This is the casino Pantasia
This is the casino Sloto Cash
This is the casino Mayan Fortune
This is the casino Simon Says
This is the casino Absolute Slots
This pretty much kills the whole idea for the funtion if I need to hard code the $template in there. Any thoughts?
Thanks much
Chris