Jump to content

apw

Members
  • Posts

    96
  • Joined

  • Last visited

Posts posted by apw

  1. Hello

     

      Hello, when a member logins into my game, I'm pulling information from my database and this information, depending on what actions the member does, either

    increases or decrease certin information in the database, this in turn is displayed to the member.  However, in order for this information to be displayed, the member

    must refresh the screen.  Is there ANY way I can display the new, current information to the member without them constantly hitting the refresh button?  The member

    usually sits on one section of the screen but I am aware that if they leave that screen and go to something else and return the new information will appear, but what

    if the member just sits on one screen, without hitting the refresh can I still display the new updated information to them?

     

    Thanks

  2. Hello

     

      Hello, I was wondering if you could give me your suggestions on simplifying some code I had written.  What I'm attempting

    to do is the following:

     

      I created a database table called barn, I added a few rows in the barn (as tests) called ..

    slot1_name to slot5_name

     

    in each of these i filled as different foods such as potatoes, carrots, tomatoes, pumpkins and grapes (as examples)

     

    now my question is, after i query my DB as follows:

      

    $barnstats="SELECT * from fw_barn where playername='$player'";
    
        $barnstats2=mysql_query($barnstats) or die("Could not get user stats");
    
        $barnstats3=mysql_fetch_array($barnstats2);

     

    I now have all my slots loaded into my $barnstats3 (i think) but my question is ...

     

    Say player A wants to buy another food from the vendor, the script has all the current foods that player A has in their barn ..

    but needs to check to see if any available slot1 to slot5 are empty .. what I did was I wrote 5 different if statements checking

    to see if those slots are already filled .. is there just one if statement I can write instead to check all slot1 to slot5 to see if

    they are either empty OR have something already inside them?

     

    Thanks in advance for your help

  3. Hello

     

    I wrote a simple but effective countdown script .. you simply plug in the time (*nix time) that you

    want the script to end and it will countdown from now using the time(); function .. which is all good

    in a way, however here is what I'm running into the problem. I included the code below that I use

    for this simple script but as the time goes on, poor player has to keep hitting refresh for the time

    to update. This is because I store the time(); in my database along with the future time.

     

    Instead of poor player A having to keep hitting the refresh button is there a way I can script this

    to where no refresh is needed and the time continues to update then when the $ctime (current time)

    hits $etime (future time) the script stops and say it updates the database?

     

    I figured $etime by taking this and doing a simple:

    $etime = 30; Time I want to advance the current real time.

    So .. then I subtracted $etime - $ctime to get the difference

     

    But you already knew that ..

     

    If you could give me a hand, I'd greatly appreciate it, even simpilify my messy code to possibly

    get the result I'm looking for ..

     

    How about a javascript .. would that work as well? I have an exaple below the first set of code

    the code runs until the timer reaches 0 then restarts .. instead of restarting maybe have the code

    just end and preform a DB update?

     

    // Sets and posts current time to DB
    
    $my_time=time(); // current time
    $update_time="update bbg_timers set ctime='$my_time' where username='$username'";
    mysql_query($update_time) or die("could not query");
    
    $time_remain2=$etime-$ctime;
    // $time_remain2=$ctime-$etime;
    
    $difference=$time_remain2;
    
    
    $difference=$time_remain2;
    $hours_difference = floor($difference / 3600);
    $difference = $difference % 3600;
    $minutes_difference = floor($difference / 60);
    $seconds_difference = $difference % 60;
    $secshow = false;
    $timeleft = '';
    if ($hours_difference > 0)
    {
    $timeleft .= $hours_difference . 'h ';
    }
    else
    {
    $secshow = true;
    }
    if ($diff > 60)
    {
    $timeleft .= $minutes_difference . 'm ';
    }
    elseif ($diff > 60 && !$seconds)
    {
    $timeleft = '<1m';
    }
    if ($secshow)
    {
    $timeleft .= $seconds_difference . 's ';
    }
    if ($diff < 0)
    {
    print "Diff is < 0";
    }
    if (($diff * 60) < 15)
    {
    // print "You have $hours_difference hours, $minutes_difference minutes, and $seconds_difference remaining";
    }
    }
    

     

    Here is the other javascript code I was talking about -- I took this from the footer file of my bnt game (giving credit)

    so I'm not exactly sure what some of the code means

     

    // Update counter
    
    $res = $db->Execute("SELECT last_run FROM $dbtables[scheduler] LIMIT 1");
    $result = $res->fields;
    $mySEC = ($sched_ticks * 60) - (TIME()-$result[last_run]);
    ?>
    <script language="javascript" type="text/javascript">
    var myi = <?=$mySEC?>;
    setTimeout("rmyx();",1000);
    
    function rmyx()
    {
     myi = myi - 1;
     if (myi <= 0)
     {
     myi = <? echo ($sched_ticks * 60); echo "\n";?>
     }
     document.getElementById("myx").innerHTML = myi;
     setTimeout("rmyx();",1000);
    }
    </script>
    <?
    echo " <b><span id=myx>$mySEC</span></b> $l_footer_until_update <br>\n";
    // End update counter
    

     

    Thanks again

  4. Hello

     

    Hello i have 2 quesstions that maybe someone can assist

    me with.

     

    I have a register and login page on my site and was wondering

    how do I get the persons IP address?  My second question is

    Once i have this IP how do I use php to store this ip into

    my sql database?

     

    Thanks

  5. Hello

     

    How do i use preg_match to keep people from directly accesssing

    files?

     

    I have this so far but it comes up to blank screen with no error:

     

    If (preg_match("/test.php/i", $PHP_SELF)) {

    print "you cannot view this file directly";

    die();

     

    }

     

    Thanks again

  6. The exact error message iis:

     

    Warning: cannot send header information - headers already sent by (output startpotato.phped at potato.php:60) in potato.php on line 118.

     

    If its refering to line 60 this line has a <?php to start

    a new batch of php code

     

    Line 118 has this:

    header("location: sell.php"); die();

  7. I have the session_start() posted at the very top of the

    page where the form is located and when i went to click on

    the link i got the cannot modify headers ...

     

    The session_start is before any othwr code is even started including

    where i tell the script the database name and info.

     

    Im not sure now what the problem iis

  8. Hello

     

    I have a php page called potato for.php with 3 different submit buttoms on it

    which are called auction, sell and cancel.

     

    At the bottom of the page i have this for each of the 3 submit buttoms:

    To tell the code what to do after the user selects one of the forrms buttons

     

    If (isset($_post["auction"])) {

     

    Now that i have this my question is with these how do i redirect the user to

    a page like auction.php or to barn.php without using a javascript to do so

     

    Thanks

    I

  9. Hello

     

    I have on my website login page this:

     

    Sessionn_start();

    if(isset($_session['player']))

    {

    Session_destroy();

     

    Even with the cache cleared im getting cannot send session cache limiter

    headers already sent

     

    How i fix this?

     

    Thanks

  10. Hello

     

    I had 2 questions that maybe someone can help me with.

     

    My first question is about restricting certin names when someone registers

    on my website such as admin or guest.  However I may get the occasional

    person who may try names such as admin2 or guest2.  How do I setup some

    sort of restriction that not only blocks names such as admin or guest but also

    any other names that may have the word admin or guest in the name?

     

    My second question is about adding commas in numbers over 999.  My script

    looks very funny with numbers over 999 that have no comma in them.  How

    would you do this?

     

    Thanks

  11. Hello

     

      Hello, I wrote a search engine script using some php, sql as the database and a exe file (to run the search bot) and was wondering if PHP could actually execute the exe file created?  I also created a batch file that would execute the .exe file .. or could i get php to execute the batch file?

     

    Thanks

  12. How would I compare 2 random numbers to rows in a table.  The table has 4 rows and 2 colums.  My table is setup like this: ID hp mp then has just randomly placed numbers from 0 to 5.  So far my script looks like this: I have $new_hp=rand(0,5); $new_mp=rand(0,5).  Then i query the db by $myquery=doquery("select hp,mp from users";  $myrow=mysql_fetch_array($myquery); once this is done would a while statement like while ($myrow = mysql_fetch_array($myquery) to what each line in the table has?  I would then need to compare the random numbers to those entries in the database.  Something like if($myrow[hp] == $new_hp && $myrow[mp] == $new_mp) { ?  But if the if statement isnt true it needs go back choose another random number and run same again and again until the statement is true and that is where im stuck at so any help would be greatly appreciated

  13. I created a $latquery do select only the latitude from my locations table and a $lonquery to select only the longitude from locations table.  Then did a $latrow = mysql_fetch_array($latquery) and a $lonrow to fetch the array.  I did a $new_lat and a $new_lon with random numbers from 0 to 5.  What would be the best way to compare the $latrow to $new_lat and $lonrow to $new_lon to where IF $latrow was equal to $new_lat and $lonrow was equal to $new_lon then how would i keep telling $new_lat and $new_lon to keep searching for a random number that isnt in $latrow or $lonrow?

  14. No the info was already in the table i put 3 sets of latitude and longitude numbers to test then did a $new_lat=rand(0,5) and $new_long=rand(0,5) but with the posted code the with the count and lat[0] and lon[0] always returned something like 0 or 1 but how do i compare the 3 sets of latitude and longitude to the lat[0] and lon[0]?

  15. Hello im trying to write a simple latitude and longitude script for my game.  So far i have a my users and locations tables set.  I have in the users table 2 entries called latitude and longitude and also in  locations table 2 entries called latitude and longitude.  When player finishes registering and everything is ok i placed a $new_lat and had it choose a random number between 0 and 5.  I did the same with $new_long had random choose a number between 0 and 5. Now i query the the locations table (after placing a few random latitude and longitude numbers between 0 and 5) and here is where im stumped.  I need assign the latitudes and longitudes that are in the locations table into possibly 2 variables and then run a check to see if the random numbers chosen match and if they do keep doing new random numbers until the randomly chosen numbers do NOT match any those in the locations table.  Can someone help me out with this?

  16. The reason for the blank page was my dumba*s didn't add the necessary fields to the

    SQL database .. thank you much for your help .. just one or two more questions about

    this if you don't mind?

     

    1. does the snipplet take into account the amount of food and the number of say labors

      needed to train a farmer ..

    print "Farmers<br>";
    print "Provides food for your growing empire<br>";
    print "-------";
    print "<br>";
    print "Base Output:<br>";
    print "+20 Food <br><br>";
    
    print "Cost Each:<br>";
    print "10 food<br>";
    print "1 labor<br>";
    print "<br>";
    print "MAX: $max_train<br>";
    

     

    2. Can and how could this script be reworked to check for three different variables as in the following for

    manpower, wood and stone:

     

    print "School<br>";
    print "Provides more research for your empire<br>";
    print "Max peasants: 10<br>";
    print "-------<br>";
    print "Cost Each:<br>";
    print "10 wood<br>";
    print "10 stone<br>";
    print "Manpower: $manpower<br>";
    print "MAX: $max_train<br>";
    

     

    Thanks again

  17. I was changing the numbers to the snipplet you gave:

     

    $food=$userstats3[food];
    $peasants=$userstats3[peasants];
    
    $food_per_peasant = 10;
    $max_train = (($total = ($food / $food_per_peasant)) > $peasants) ? $peasants : $total;
    echo $max_train;
    

     

    By doing so, max_train is blank .. what went wrong?

     

    if the code is done like your example the $max_train echoes however if the code is fed using the

    example above the max_train does not echo ..

  18.  

    The $max_train coes from labor.php it is the maxinum number of labors that the player may train.

     

    The $max_train also is in the labor2.php file, I just recopied the same lines from labor.php into the

    other file.  But what I cannot figure out is getting the right numbers for the $max_train such as:

     

    mypeasants: 50

    myfood: 50

     

    $chk1=round($myfood/10,0); // Check food / 10
    
    if(chk1>$mypeasant)
    {
    $max_train=$mypeasant;
    }
    
    if($chk1<$mypeasant)
    {
    $max_train=$chk1;
    }
    

     

     

  19. Hello

     

      I've got code below that I'm needing help with.  The SQL database is as follows :

    Food: 100

    Labor: 50

    Peasants: 50

     

    The object of this set of code is to tell the player how many labors they may train

    based on the amount of food and peasants they player has available at the time.

    The "cost" of this exchange is 10 food and 1 peasants per labor that needs training...

     

    Code below:

    print "Labors<br>";
    print "Basic working persons for the empire<br>";
    print "-------";
    print "<br>";
    print "Base Output:<br>";
    print "+2 Manpower<br>";
    print "+2 Research<br><br>";
    
    print "Cost Each:<br>";
    print "10 food<br>";
    print "1 peasant<br>";
    print "<br>";
    print "MAX: $max_train<br>";
    
    
    
          print "<br>Train:";
          print "<form action='labor2.php' method='post'>";
          print "<input type='text' name='train' size='16'><br>";
          print "<input type='submit' name='submit' value='Train'></form>";
    

     

    labor2.php code takes the input of the player, checks to see if the player hasn't gone over the

    amount of max_train and changes the labor, peasant and food..

     

    labor2.php code below:

     

    <?php
    include('lib.php');
    include('g1.php');
    
    session_start();
    $link = opendb();
    ?>
    
    <link rel="stylesheet" href="style.css" type="text/css">
    <?php
    if (isset($_SESSION['player'])) 
      {
        $player=$_SESSION['player'];
        $userstats="SELECT * from km_users where playername='$player'";
        $userstats2=mysql_query($userstats) or die("Could not get user stats");
        $userstats3=mysql_fetch_array($userstats2);
    
        if(isset($_POST['submit']))
        {
           
         
           $train=$_POST['train'];
           $train=strip_tags($train);
    
    // Loads stats below
    
    $myfood=$userstats3[food];
    $mypeasant=$userstats3[peasant];
    $mylabor=$userstats3[labor];
    
    
    // End stat loading
    
    
           if($train<0)
           {
              print "You cannot train negative workers.<br> <A href='trainworkers.php'>Back</a>.";
           }
           else if($train>$max_train)
           {
              die("You cannot train that many workers!<br> <A href='trainworkers.php'>Back</a>");
           }
          
           else if($train<=$max_train)
           {
               
    $newfood=$train*10;
    
    
              $new1="update km_users set labor=labor+'$train', food=food-'$newfood', peasant=peasant-'$train' where ID='$userstats3[iD]'";
              mysql_query($new1) or die("Try Again");
    
    // Announce new stats
    $myfood=$userstats3[food];
    $mypeasant=$userstats3[peasant];
    $mylabor=$userstats3[labor];
    
    print "TRAINING COMPLETE!<br>";
    print "------<br>";
    print "Labor: $mylabor (-$train)<br>";
    print "Peasants: $mypeasant (-$train)<br>";
    print "Food: $myfood (-$newfood)<br>";
    print "------<br>";
    print "<a href='trainworkers.php'>Back</a><br>";
    print "<a href='index.php'>Main</a><br>";
    
           }       
       
       
        }
      }
    else
      {
        print "Sorry, not logged in  please <A href='login.php'>Login</a><br>";
      
      }
    
    ?>
    

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