I want to create some random sql data with a php script
currently I get the last record, generate a random number between 1 and 2 ... if its a 1 I will add a random number to the record else if its a 2 i will subtract a random number from
the problem is it keeps spitting out minus random numbers! I only want positive random numbers.
$result = mysql_query("SELECT * FROM Data ORDER BY id DESC")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
$temp=$row['temp'];
$light=$row['light'];
};
$name="Herbi";
$date=Date("o:m:d");
$time=Date("H:i:s");
$rand =rand(1,2);
$randnu =rand(1,10);
echo " rand:".$rand;
switch($rand){
case 1:
$temprand=$temp+$randnu;
$lightrand=$light+$randnu;
break;
case 2:
$temprand=$temp-$randnu;
$lightrand=$light-$randnu;
break;
};
echo"";
echo"randnu";
echo $randnu;
echo " ";
echo"lightrand";
echo $lightrand;