Jump to content

[SOLVED] Randomiseing and such likes


burtybob

Recommended Posts

I have a code that should update a table named drugs after 2 hours however when i try the code i get the data from the database but it then goes into minus plus can some one look at my code and tell me why it goes minus instead?

 

<?php
$con = mysql_connect("sql address","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$londonpdp=mt_rand(99,999);
$oslopdp=mt_rand(98,999);
$cairopdp=mt_rand(99,999);
$shanghaipdp=mt_rand(99,999);
$parispdp=mt_rand(99,999);
$dublinpdp=mt_rand(99,999);
$riopdp=mt_rand(99,999);
$stockholmpdp=mt_rand(99,999);
$athenspdp=mt_rand(99,999);
$montrealpdp=mt_rand(99,999);
$washingtonpdp==mt_rand(99,999);
    $time1=mysql_query("SELECT pricetime FROM drugs");
    $outtime=time()+(24*60*60); //24hours
    $time4= $time1-time();
if ($time4<=0) {
mysql_query("UPDATE drugs SET londonprice = '$londonpdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET osloprice = '$oslopdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET cairoprice = '$cairopdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET shanghaiprice = '$shanghaipdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET washingtonprice = '$washingtonpdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET dublinprice = '$dublinpdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET parisprice = '$parispdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET rioprice = '$riopdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET stockholmprice = '$stockholmpdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET athensprice = '$athenspdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET montrealprice = '$montrealpdp' WHERE drugname = 'pot'");
mysql_query("UPDATE drugs SET pricetime = '$outtime' WHERE drugname = 'pot'");
}
mysql_close($con);

echo "$outtime <br>";
echo "Time 4: $time4 <br>";
?>
d

Link to comment
Share on other sites

Try this

<?php
$con = mysql_connect("sql address","username","password") or die('Could not connect: '.mysql_error());
mysql_select_db("database", $con);

$prices = array();
foreach(array('london', 'oslo', 'cairo', 'shanghai', 'paris', 'dublin', 'rio', 'stockholm', 'athens', 'montreal', 'washington') as $city)
{
$prices[$city] = mt_rand(99, 999);
}

list($time1) = mysql_fetch_array(mysql_query("SELECT pricetime FROM drugs"));
$outtime = time()+(24*60*60); //24hours
$time4= $time1-time();
if($time4<=0)
{
$sets = array();
foreach($prices as $city => $price)
{
	$sets[] = "{$city}price='{$price}'";
}
mysql_query("UPDATE drugs SET ".join(',',$sets)." WHERE drugname = 'pot'");
}
mysql_close($con);

echo "$outtime <br>";
echo "Time 4: $time4 <br>";
?>

 

You might want to reconsider your database layout. It's better to store each city as an entry for itself rather than having a lot of fields.

Link to comment
Share on other sites

What goes into "minus"? The prices?

No the prices are fine but the time goes into minus when i go on the page the time from the DB - Current time for some reason seem to go into minuse.

1189102314 <---- Time now

Time 4: -1189015805 <------ Time in DB - Time now

 

So because it never hits 0 it never automatically updates the DB.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.