Jump to content

Help.. just cant get it this time.


ViciousC

Recommended Posts

Cant figure out how to get the random choices when fallen on money to update the database. I have tried MANY different options but still cant get it! Can someone fill in the blanks please. ???

 

 

 

<?php

 

function search() {

global $userrow, $numqueries;

if (isset($_POST['explor'])) {

$title = "Search";

 

$my_array = array("$page <font color=#C0C0C0>Burnt buildings and rubble everywhere.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>You come across a old man looking for food.<br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>The sound of bombs going off in the distance.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>You can smell a faint gas oder from a main line under the street.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>You feel eyes upon you.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>Your being followed.</font><br><br>",

"<font color=#00CE00>You found Money...</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>You have no idea where you are right now.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#0000FF>What a long day.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>As you walk you see lifeless bodies you use to call friends.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=#CB5634>There is a noise ... just a rat.</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>",

"<font color=yellow> You Found a Stone</font><br><br>",

"<font color=#C0C0C0>You found Nothing...</font><br><br>");

for ($i=0; $i<=10; $i++)

 

{$random = array_rand($my_array);$parola .= $my_array[$random];}}

 

if (isset($_POST['submit'])) {

$title = "Search";

}

 

 

else {

$title = "Search";

$page .= "<form action=index.php?do=search method=post>";

$page .= "<table align=center width=100%><tr><td align=center bgcolor=red valign=top>SEARCH</td></tr>";

$page .= "<tr><td align=left><br>$parola<br><br><center><input align=center name=explor type=submit value=SEARCH /></center><br><br><br><br></td></tr></table>";

$page .= "<center><a href=index.php?do=towninf>GO BACK</a></center>";

$page .= " </form>";

}

display($page, $title);

}

?>

 

Link to comment
Share on other sites

try this

 

<?php

function search() {
  global $userrow, $numqueries;
  if (isset($_POST['explor'])) {
    $title = "Search";

    $my_array = array("$page <font color=#C0C0C0>Burnt buildings and rubble everywhere.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>You come across a old man looking for food.

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>The sound of bombs going off in the distance.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>You can smell a faint gas oder from a main line under the street.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>You feel eyes upon you.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>Your being followed.</font>

",
"<font color=#00CE00>You found Money...</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>You have no idea where you are right now.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#0000FF>What a long day.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>As you walk you see lifeless bodies you use to call friends.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=#CB5634>There is a noise ... just a rat.</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

",
"<font color=yellow> You Found a Stone</font>

",
"<font color=#C0C0C0>You found Nothing...</font>

");
    for ($i=0; $i<=10; $i++) {
  $count=count($my_array);
      $random = rand(0,$count);
      $parola .= $my_array[$random];
    }
  }

  if (isset($_POST['submit'])) {
    $title = "Search";
  }
  else {
    $title = "Search";
    $page .= "<form action=index.php?do=search method=post>";
    $page .= "<table align=center width=100%><tr><td align=center bgcolor=red valign=top>SEARCH</td></tr>";
    $page .= "<tr><td align=left>
$parola

<center><input align=center name=explor type=submit value=SEARCH /></center>



</td></tr></table>";
    $page .= "<center><a href=index.php?do=towninf>GO BACK[/url]</center>";
    $page .= " </form>";
  }
  display($page, $title);
}
?>

 

 

i take it display() is another function you have created?

 

I've changed array_rand to rand 0,$count to choose a number randomly between 0 and the maximum number the array value could be.

 

 

If you would rather use array_rand have a look at the manual below as it doesn't seem you thought it wokred in the same way..

 

http://uk2.php.net/array_rand

 

Regards

Liam

Link to comment
Share on other sites

Ok maybe i was unclear with what i wanted to do sorry about that... BUT you helped me figure another question i had thanks.. ok let me try to explain again.

 

Say the array ia 1-5....

$input = array("1","2","3","4","5",);

 

 

$rand_keys = array_rand($input, 2);

echo $input[$rand_keys[0]] . "\n";

echo $input[$rand_keys[1]] . "\n";

 

you  have only a echo of two.

 

Say one of those two you win points

 

now how would you put in a update query on the random choice if it was say #3?

Link to comment
Share on other sites

you nould just set a variable to hold the temp values and then update

 

$input = array("1","2","3","4","5",);
$rand_keys = array_rand($input, 3);
$rand1 = $input[$rand_keys[0]] . "\n";
$rand2 = $input[$rand_keys[1]] . "\n";
$rand3 = $input[$rand_keys[2]] . "\n";

$updaterandoms=mysql_query("UPDATE tablename SET rand1 = '".$rand1."', SET rand2 = '".$rand2."', SET rand3 = '".$rand3."' WHERE ID = ".$id." ") or die('Update random numbers: '.mysql_error());

 

 

 

Do you mean like that?

 

Regards

Liam

Link to comment
Share on other sites

I know alot of stuff about alot of things but feel dumb as a rock at times. 

 

Say the array is 1-5....

$input = array("1","2","3","4","5",);

                              |_______________$updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");

 

$rand_keys = array_rand($input, 2);

echo $input[$rand_keys[0]] . "\n";

echo $input[$rand_keys[1]] . "\n";

 

you  have only a echo of two.

 

Say one of those two you win points

 

now how would you put in a update query on the random choice if it was say #3? Isnt there a way to only update IF the echo is #3?

 

Sorry but stupid here.

Link to comment
Share on other sites

$input = array("1","2","3","4","5",);
$rand_keys = array_rand($input, 3);
$rand1 = $input[$rand_keys[0]] . "\n";
$rand2 = $input[$rand_keys[1]] . "\n";
$rand3 = $input[$rand_keys[2]] . "\n";
$winningnumber=3;

if (($winningnumber == $rand1) || ($winningnumber == $rand2) || ($winningnumber == $rand3)) {
  $updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");
}

 

 

Like that you mean?

 

Liam

Link to comment
Share on other sites

try this

 

<?php
$input = array("1","2","3","4","5",);
$rand_keys = array_rand($input, 3);
$rand1 = $input[$rand_keys[0]] . "\n";
$rand2 = $input[$rand_keys[1]] . "\n";
$rand3 = $input[$rand_keys[2]] . "\n";
$winningnumber=3;

if ($winningnumber == $rand1) {
  $updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");
  echo 'You win';
} else {
  echo 'You didnt win';
}
if ($winningnumber == $rand2) {
  $updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");
  echo 'You win';
} else {
  echo 'You didnt win';
}
if ($winningnumber == $rand3) {
  $updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");
  echo 'You win';
} else {
  echo 'You didnt win';
}

?>

 

 

You could also shorten your code by using a function

 

<?php
function checkrand($rand) {
  $winningnumber=3;
  global $userrow;
  if ($winningnumber == $rand) {
    $updatequery = doquery("UPDATE {{table}} SET gold=gold+100 WHERE id='".$userrow["id"]."' LIMIT 1", "users");
    echo 'You win<Br>';
  } else {
    echo 'You didnt win<Br>';
  }
}
$input = array("1","2","3","4","5",);
$rand_keys = array_rand($input, 3);
checkrand($input[$rand_keys[0]]);
checkrand($input[$rand_keys[1]]);
checkrand($input[$rand_keys[2]]);
?>

 

alot shorter and neater coding

 

 

Regards

Liam

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.