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
https://forums.phpfreaks.com/topic/167274-little-help-needed/
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
https://forums.phpfreaks.com/topic/167274-little-help-needed/#findComment-882228
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
https://forums.phpfreaks.com/topic/167274-little-help-needed/#findComment-882466
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
https://forums.phpfreaks.com/topic/167274-little-help-needed/#findComment-882475
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.