ViciousC Posted October 4, 2007 Share Posted October 4, 2007 this is what i want to do... Enter amount to search click button...... The amount you entered will display that many Random lines... with certain lines say " money found" update the DB.... I have tried sooooooooo many times and changed alot but still stuck. PLEASE help. <?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); } ?> Quote Link to comment Share on other sites More sharing options...
Aeglos Posted October 4, 2007 Share Posted October 4, 2007 Use code tags in the forum, and try to organize your code a bit. There are a couple of errors in your code ($page variable inside first array element? some escaped HTML in the middle of nowhere down at the bottom?). Here I fixed it a bit. (There are still some grammar errors in your array). <?php function search() { global $userrow, $numqueries; if (isset($_POST['explor'])) { $title = "Search"; $my_array = array("<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++) { // Here you should change the '10' for the number of times the player searched. $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> <table align=center width=100%><tr><td align=center bgcolor=red valign=top>SEARCH</td></tr> <tr><td align=left>".$parola." <center><input align=center name=explor type=submit value=SEARCH /> </center></td></tr></table> <center><a href=index.php?do=towninf>GO BACK[/url]</center> </form>"; } display($page, $title); } ?> The array element that contains "You found some money" is key number 13 I believe. So you need to check inside your for loop: <?php if ($random == '13') { updateDatabaseFunctionOrOtherThing($arguments); } ?> Since I assume this is a game, and updating the database a bunch of times inside a for loop would be somewhat unwise, do something like: <?php if ($random == 13) { // if you found money $moneyGained += rand(1,69); //add some coins. } //Then OUTSIDE the for loop updateMoneyInDatabaseFunction($moneyGained); ?> Regards. Quote Link to comment Share on other sites More sharing options...
ViciousC Posted October 4, 2007 Author Share Posted October 4, 2007 Hey Thanks Im gonna work on this a little and see what happens. It looks great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.