Hello I need some help on a project i am working on.
I have a database with a large amount of records in it. I need to get a number of records into variables to make a graph. Below is part of my code so far.
//Retrieve all data from the table
$result=mysql_query("SELECT * FROM solar_panel ORDER BY id DESC") or die(mysql_error());
$row = mysql_fetch_row($result);
$row1 = mysql_fetch_row($result);
$row2 = mysql_fetch_row($result);
$row3 = mysql_fetch_row($result);
$row4 = mysql_fetch_row($result);
$row5 = mysql_fetch_row($result);
$row6 = mysql_fetch_row($result);
$row7 = mysql_fetch_row($result);
$row8 = mysql_fetch_row($result);
$row9 = mysql_fetch_row($result);
$row10 = mysql_fetch_row($result);
$row11 = mysql_fetch_row($result);
$row12 = mysql_fetch_row($result);
$row13 = mysql_fetch_row($result);
$row14 = mysql_fetch_row($result);
$row15 = mysql_fetch_row($result);
$row16 = mysql_fetch_row($result);
$row17 = mysql_fetch_row($result);
$row18 = mysql_fetch_row($result);
$row19 = mysql_fetch_row($result);
$row20 = mysql_fetch_row($result);
$row21 = mysql_fetch_row($result);
$row22 = mysql_fetch_row($result);
$row23 = mysql_fetch_row($result);
$row24 = mysql_fetch_row($result);
As you can see this will get quiet large, i need to get every 5th row in descending order put into a separate variable but the only way i know is to put all the rows into separate variables then use the 5th one in the graph data.
I would like to do this for about 60 records so to write out all the records i would have to write the above code 300 times. Is there a quicker way to do this.
i have tried doing a loop but can't get the variables to increase with each row selected.
Any help would be much appreciated, or im writing a lot of code
if (isset($var{$x})). Awful.MySQLiorPDOinstead ofmysql_*functions, which are deprecated. More information avalible here.