Jump to content

[SOLVED] Quick Question


Sinikka

Recommended Posts

Can anyone see what is wrong with this? Instead of randomly choosing what to stock and dividing the max_stock in half it's stocking everything with one being the amount in stock. I've tried messing around with it but I can't figure it out. Any help would be appreciated!

 

<?php

#!/usr/bin/php


$dbh=mysql_connect ("removed", "removed", "removed") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("removed");

$findItems = mysql_query("SELECT * FROM shop_items2 WHERE game = '1'");
while ($getItems = mysql_fetch_array($findItems))
{
$id = $getItems[id];
$getItems[max_stock] = round($getItems[max_stock] / 2);
$rand[$id] = rand(0,$getItems[max_stock]);
}


$sql2="UPDATE `shop_items2` SET cur_stock=$rand[$id] WHERE game = '1'";

if(mysql_query($sql2))
{
echo $sql2;
}

?>

Link to comment
Share on other sites

not really clear what you are doing - perhaps you should print out the results of your query to see what you are actually selecting (is the result just one record or lots? - if its lots then remember that your final query will NOT hold different values for $rand[$id]; that will simply be the last value calculated in your loop!).

Link to comment
Share on other sites

The script is for one of my shop restocking crons. I need to to take the max stock possible and divide that in half but then choose the items that it pulls randomly so it's not stocking all items that can possibly stock each time.

 

When I execute the script this is what I get:  UPDATE `shop_items2` SET cur_stock=1 WHERE game = '1'

 

*edit and it would stock multiple shops at once so it would be more then one record.

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.