Jump to content

little help needed.


seany123

Recommended Posts

i currently have a page with this code in..

 

 

<?php

$strrand = rand(1,100);
$defrand = rand(1,100);
$spdrand = rand(1,100);
$bankrand = rand(1,100);
$pointsrand = rand(1,100);



//Strength success
If($strrand <= 20)
{    
echo "<br><b>Strength:</b> ". $english_format_number = number_format($enemy->strength) ."<br>";
}
//Strength fail
else if($strrand >= 21)
{	
echo "<br><b>Strength:</b> Couldn't find out!<br>";
}

//defense success
If($defrand <= 20)
{    	
echo "<b>defense:</b> ". $english_format_number = number_format($enemy->defense) ."<br>";
}
//defense fail
else if($defrand >= 21)
{	
echo "<b>defense:</b> Couldn't find out!<br>";
}

//speed success
If($spdrand <= 20)
{    	
echo "<b>speed:</b> ". $english_format_number = number_format($enemy->speed) ."<br>";
}
//speed fail
else if($spdrand >= 21)
{	
echo "<b>speed:</b> Couldn't find out!<br>";
}

//bank success
If($bankrand <= 20)
{    	
echo "<b>bank:</b> ". $english_format_number = number_format($enemy->bank) ."<br>";
}
//bank fail
else if($bankrand >= 21)
{	
echo "<b>bank:</b> Couldn't find out!<br>";
}

//points success
If($pointsrand <= 20)
{    	
echo "<b>points:</b> ". $english_format_number = number_format($enemy->points) ."<br><br>";
}
//points fail
else if($pointsrand >= 21)
{
echo "<b>points:</b> Couldn't find out!<br><br>";
}
$query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money - $moneyloss, $player->id));	

echo "<a href=\"home.php\">Back</a>";
?>

 

 

what i want to do is put that information into a database... but i dunno the best way of doing it... i dont wanna have to do something like this...

 

<?php
if ($strrand >= x && $defrand <= x && $spdrand <= x && $bankrand <= x && $pointsrand <= x){

Then do query.
}
else if ($strrand <= x && $defrand >= x && $spdrand <= x && $bankrand <= x && $pointsrand <= x){

then do query
}

else if ($strrand <= x && $defrand <= x && $spdrand >= x && $bankrand <= x && $pointsrand <= x){

then do query
}
?>

 

because as you can see that could take forever... but i cant think of how i can do it.

Link to comment
Share on other sites

i don't understand where the 'x' comes into play...but would it help if you put them in an array and sorted them? that way $array[0] would give you the lowest and $array[4] would give you the highest?

 

 

i dont understand what you mean..

 

as for the X.. its just to show where a value is...

 

in my case

 

>= 21

 

<= 20

Link to comment
Share on other sites

We have no idea how these values relate to each other which makes it difficult to suggest any other alternatives. You should try to find a pattern if possible. It seems as if the whole logic behind ending up in this situation is the actual problem.

Link to comment
Share on other sites

these values dont relate to each other.

 

for example

 

$strrand

$defrand

 

dont relate to eachother....

 

 

all im doing is getting

 

$strrand = rand(1,100);

 

 

then echoing something if its >= 21 and something else if its <= 20.

 

but i wanna update the answers the a table..

Link to comment
Share on other sites

also in mysql how can i make it so the same row can store int and varchars?

 

You can have whatever columns you want in a table.  Each individual column can have it's own datatype.

 

Other than that, we don't really have enough information about this application to understand what you're trying to do, or suggest alternatives. 

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.