I'm trying to echo a php variable within my styles.php. This variable, which I defined in a separate (and included) php file, contains several values from a database :
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT NumDep, DENS FROM france WHERE DENS BETWEEN '0' AND '45' ";
$result = mysql_query($SQL);
while ( $db_field = mysql_fetch_assoc($result) )
{
$dens = $db_field['NumDep'] . ",<BR>";
echo $dens;
When I echo the variable $dens in my index.php file, the 20 values are showing normally. But when I echo the $dens variable in my styles.php file, only the last value is printed.
<?php
echo $dens; ?> <?php echo "
{
fill: #FFC285;
fill-opacity:1;
stroke:white;
stroke-opacity:1;
stroke-width:0.5;
stroke-miterlimit: 3.97446823;
stroke-dasharray: none;
}
What I want is to print the 20 values, in the same way they are printed in the index.php file.
Can anyone help me? (Alternative solutions for printing these values from the database into the styles.php are welcome!)
Thanks in advance. Jonas
$dens = $db_field['NumDep'] . ",<BR>";- you're putting HTML in a CSS file. Did you mean to use\nrather than<br>? Also, please consider switching to MySQLi or PDO for your queries, as themysql_functions are now deprecated and considered insecure.index.phpfile you're outputting it during a loop whereas in yourstyles.phpfile you aren't, so it's just outputting the last result. I hate to think that you're going to print that CSS style for each database row, you should be assigning a class to the elements with those names and defining a single CSS class style.