been trying to save my data from my while loop to script variables but no success. Did an example if how I want to save my php data to script variables. This doesn't work for me. Anyone have any idea? Don't want to save all data manually. Very greatful for answers! Ask if you don't understand :) Right now it only saves the last variable in the row2.
$id = 0;
while($rows = mysql_fetch_array($data)){
$id = $id + 1;
$data = $rows['data'];
$id2 = 0;
$sql = mysql_query("select * from table where id = '".$data."'");
while($row2 = mysql_fetch_array($sql)){
$id2 = $id2 + 1;
$var = $row2['var']; //lets say this one is HT123
}
$savethis = "var data" . $id . "_" . $id2 . " = '" . $var . "';";
}
echo "<script>";
echo $savethis;
//I want it to equal like "var data1_1 = 'HT123';
//And then do this for each row, so:
//var data1_2 = 'HW132';
//var data1_3 = 'PQ542';
//var data2_1 = 'SA210';
//Etc
echo "</script>";
mysql_xxx()functions are officially deprecated. They will probably be removed entirely from PHP in a future release. It is recommended to switch to an alternative API. PHP provides either themysqliorPDOlibraries which can be used instead.