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.

PHP Code:

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.