I am attempting to change the background of a page based off of the number of variables echoed from a Mysql database. I have successfully changed the background using the code below in my page styles, but because I am also using pagination this code understandably only works properly on the first page, every page after would echo the background number 5.
The code below is what I am currently using, but I know it does not make sense to use it if there is multiple pages unless there is a way to identify how many variables are posted on that specific page… please assist me.
[code=php]
body{
background: url(../../images/background<?php
$backgrounds = mysql_query(“SELECT * FROM ac WHERE state=’Alaska'”);
$querygetrownum0 = mysql_num_rows($backgrounds);
if($querygetrownum0==1){echo “1”;}
if($querygetrownum0==2){echo “2”;}
if($querygetrownum0==3){echo “3”;}
if($querygetrownum0==4){echo “4”;}
if($querygetrownum0>=5){echo “5”;}
?>.jpg
}
Thanks in advance for any and all help.
[code=php]
<?php
$backgrounds = mysql_query("SELECT * FROM ac WHERE state='Alaska'");
$querygetrownum0 = mysql_num_rows($backgrounds);
if($querygetrownum0==1){$back_val = "1";}
if($querygetrownum0==2){$back_val = "2";}
if($querygetrownum0==3){$back_val = "3";}
if($querygetrownum0==4){$back_val = "4";}
if($querygetrownum0>=5){$back_val = "5";}
?>
<style>
body
{ background: url(../../images/background<?php echo $back_val; ?>.jpg }
</style>
[/code]
[code=php]$backgrounds = mysql_query("SELECT * FROM ac WHERE state='Alaska' LIMIT 0,5"); [/code]
[code=php]$backgrounds = mysql_query("SELECT * FROM ac WHERE state='Alaska' LIMIT 6,5"); [/code]
[code=php]
$totalRows = mysql_num_rows($backgrounds);
$postsPerPage = 5;
$currentPage = 4; // have to figure out where to get this value from pagination
$back_val = ($currentPage <= round($totalRows / $postsPerPage))
? $num = $postsPerPage
: $totalRows % $postsPerPage;
[/code]
I'm not sure we can provide a meaningful solution without knowing how you are doing the pagination.[/QUOTE]
[code=php]
$per_page = 5;
$start = $_GET['start'];
$record_count = mysql_num_rows(mysql_query("SELECT * FROM ac WHERE state='Alaska'"));
$max_pages = $record_count / $per_page;
if (!$start)
$start = 0;
$get = mysql_query("SELECT * FROM ac WHERE state='Alaska' ORDER BY datetime DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get)){
$city = $row['city'];
echo "$city<br>";}
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href='testlead2.php?start=$prev'>Previous</a>";
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='ac_alaska.php?start=$x'>$i</a>";
else
echo " <a href='ac_alaska.php?start=$x'><b>$i</b></a>";
$i++;}
if (!($start>=$record_count-$per_page))
echo "<a href='ac_alaska.php?start=$next'>Next</a>";
[/code]
[code=php]
$per_page = 5;
$start = $_GET['start'];
$record_count = mysql_num_rows(mysql_query("SELECT * FROM ac WHERE state='Alaska'"));
$max_pages = $record_count / $per_page;
if (!$start)
$start = 0;
$get = mysql_query("SELECT * FROM ac WHERE state='Alaska' ORDER BY datetime DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get)){
$city = $row['city'];
echo "$city<br>";}
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href='testlead2.php?start=$prev'>Previous</a>";
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='ac_alaska.php?start=$x'>$i</a>";
else
echo " <a href='ac_alaska.php?start=$x'><b>$i</b></a>";
$i++;}
// Pagination Background Change
if($i == 1){ $back_val = "1"; }
if($i == 2){ $back_val = "2"; }
if($i == 3){ $back_val = "3"; }
if($i == 4){ $back_val = "4"; }
if($i >= 5){ $back_val = "5"; }
if (!($start>=$record_count-$per_page))
echo "<a href='ac_alaska.php?start=$next'>Next</a>";
[/code]
<i>
</i><style>
body { background: url(../../images/background<?php echo $back_val; ?>.jpg }
</style>
[code=php]
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='ac_alaska.php?start=$x'>$i</a>";
else
echo " <a href='ac_alaska.php?start=$x'><b>$i</b></a>";
$i++;}
// Pagination Background Change
if($i == 1){ $back_val = "1"; }
if($i == 2){ $back_val = "2"; }
if($i == 3){ $back_val = "3"; }
if($i == 4){ $back_val = "4"; }
if($i >= 5){ $back_val = "5"; }
[/code]
[code=php]
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='ac_alaska.php?start=$x'>$i</a>";
else
echo " <a href='ac_alaska.php?start=$x'><b>$i</b></a>";
$i++;}
// Pagination Background Change
$back_val = "$i";
[/code]
[code=php]
$back_val = ($i<5) ? $i : 5;
[/code]
[code=php]
$per_page = 5;
$start = $_GET['start'];
$record_count = mysql_num_rows(mysql_query("SELECT * FROM ac WHERE state='Alaska'"));
$max_pages = $record_count / $per_page;
if (!$start)
$start = 0;
$query="SELECT * FROM ac WHERE state='Alaska' ORDER BY datetime DESC";
$result=mysql_query($query);
$c=0;
while ($c <= $per_page) {
$city=mysql_result($result,$c,"city");
echo "$city<br>";
$c++;
}
// Pagination Background Change
if($c == 1){ $back_val = "1"; }
if($c == 2){ $back_val = "2"; }
if($c == 3){ $back_val = "3"; }
if($c == 4){ $back_val = "4"; }
if($c >= 5){ $back_val = "5"; }
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href='testlead2.php?start=$prev'>Previous</a>";
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='ac_alaska.php?start=$x'>$i</a>";
else
echo " <a href='ac_alaska.php?start=$x'><b>$i</b></a>";
$i++;}
if (!($start>=$record_count-$per_page))
echo "<a href='ac_alaska.php?start=$next'>Next</a>";
[/code]
[code=php]
$per_page = 5;
$start = $_GET['start'];
$record_count = mysql_num_rows(mysql_query("SELECT * FROM ac WHERE state='Alaska'"));
$max_pages = $record_count / $per_page;
if (!$start)
$start = 0;
$query="SELECT * FROM ac WHERE state='Alaska' ORDER BY datetime DESC";
$result=mysql_query($query);
$c=0;
while ($c <= $per_page) {
$city=mysql_result($result,$c,"city");
echo "$city<br>";
$c++;
}
// Pagination Background Change
if($c == 1){ $back_val = "1"; }
if($c == 2){ $back_val = "2"; }
if($c == 3){ $back_val = "3"; }
if($c == 4){ $back_val = "4"; }
if($c >= 5){ $back_val = "5"; }
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href='testlead2.php?start=$prev'>Previous</a>";
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='testlead2.php?start=$x'>$i</a>";
else
echo " <a href='testlead2.php?start=$x'><b>$i</b></a>";
$i++;}
if (!($start>=$record_count-$per_page))
echo "<a href='testlead2.php?start=$next'>Next</a>";
[/code]
[CODE]
<style type="text/css">
body{
background: url(../../images/background<?php echo $back_val; ?>.jpg)
}
</style>
[/CODE]
[code=php]
$per_page = 5;
$start = $_GET['start'];
$record_count = mysql_num_rows(mysql_query("SELECT * FROM ac WHERE state='Alaska'"));
$max_pages = $record_count / $per_page;
if (!$start)
$start = 0;
$current_rows = 0;
$get = mysql_query("SELECT * FROM ac WHERE state='Alaska' ORDER BY datetime DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get)){
$city = $row['city'];
$current_rows = $current_rows + 1;
echo "$current_rows. $city<br>";}
// Pagination Background Change
if($current_rows == 1){ $back_val = "1"; }
if($current_rows == 2){ $back_val = "2"; }
if($current_rows == 3){ $back_val = "3"; }
if($current_rows == 4){ $back_val = "4"; }
if($current_rows >= 5){ $back_val = "5"; }
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href='testlead2.php?start=$prev'>Previous</a>";
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page){
if($start!=$x)
echo " <a href='testlead2.php?start=$x'>$i</a>";
else
echo " <a href='testlead2.php?start=$x'><b>$i</b></a>";
$i++;}
if (!($start>=$record_count-$per_page))
echo "<a href='testlead2.php?start=$next'>Next</a>";
[/code]
0.1.9 — BETA 5.19