View Full Version : Disable a Button Until 0 Becomes >= 1

02-08-2010, 06:48 PM
Hey everyone, I have this snip of code below, what it does is work off a timer, when a user first opens this "store" up they start out with 0/1, and can grow by upgrading the store up to the max of 0/6. Every few hours +1 is added to their inventory which they can then collect by hitting the Collect button..

factoryStore is where the amount they can collect is stored, it starts off as 0 and then when the timer hits the mark, it adds +1 to the factorystore column in the database.

I would like the Collect button to be disabled while there is 0 inside so they can not Collect 0 as an amount, when 1 is ran I would like the button to show back up and then when they collect for the button to disappear.

I have tried everything from adding an if command to it

if ( $res2 == 0 ) {
no button
else {

but no luck and this is driving me insane.. Any suggestions to how to get this to work before I pull out all my hair!

if ( $totalOwn > 0 ) {
$res2 = mysql_fetch_row(query("SELECT `factoryStore` FROM `factory_log` WHERE `userid`=$user && `factoryId`=$row[factoryId]"));
$max = ($totalOwn);
$pos = (($res2[0] * 141) / $max) - 141;
echo '<P style="color: green; font-weight: bold;">Container: '.number_format($res2[0],0).' / ' . number_format($max,0) .' <br /> ';
echo '
<div style="width:141px; height:12px; background-color: #333333; border:#0000FF solid 1px; overflow:hidden;">
<div class="aa" style="left: '.$pos.'px;">
</div><br />';

echo '<form ACTION="'.$appCanvasUrl.'factory/" method="POST">';
echo '<input type="hidden" name="fid" value="'.$row[factoryId].'">';
echo '<input type=hidden name=sa value="'.$weaponAttack.'">';
echo '<input type=hidden name=sd value="'.$weaponDefense.'">';
echo '<input type="submit" name="getFactoryContent" value="Collect Your Weapon" class="buysupplies">';
echo '</form>';
echo '</P>';

Thanks in advance

Len Whistler
02-08-2010, 07:35 PM
I think the problem is:

This line:

if ( $res2 == 0 ) {
no button

Should be:

if ( $res2[factoryStore] == 0 ) {
no button


02-08-2010, 07:41 PM
$res2 is an array, so you can't use it like what you show in that "if" statement.