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:

background: url(../../images/background<?php 
mysql_query("SELECT * FROM ac WHERE state='Alaska'");
$querygetrownum0 mysql_num_rows($backgrounds);
$querygetrownum0==1){echo "1";}
$querygetrownum0==2){echo "2";}
$querygetrownum0==3){echo "3";}
$querygetrownum0==4){echo "4";}
$querygetrownum0>=5){echo "5";}
Thanks in advance for any and all help.