Jump to content

Phpfr3ak

Members
  • Posts

    110
  • Joined

  • Last visited

    Never

Posts posted by Phpfr3ak

  1. Sorry basically its something along the lines of, Player A buys x amount from player B, the cron runs every :10 on the hour, and essentially sells that resource, resourses have different values, for example at :10 player A sells 100 resourses, 50 of those resources would be in 1 row, and 50 in another, if that makes sense it can vary, hope that explains it somewhat better?

  2. Just need a basic loop making. Easier to show as an example so please see below. this will be used as a Cron job and will update each player in the database.

     

    Table: drug_inventory

     

    columns: player_id quality weight

     

    we will base this off 500 weight as an example if its not in 1 colum i need it to loop until the rate is met based on the player_id, and then delete the said amount from the database. if it falls short and say it only all ads up to for example lets say 470 it wont error out.

     

    player_id quality weight

    1        180          250

    1        120          200

    1          80          150

    1        180          100

    1        180          50

     

    Pm me on here for details or fire an email over to arron91@live.co.uk cheers

  3. also tried:

     

    $addIDs_ary = array_filter($addIDs_ary);
    foreach ($result as $hit_id) { 
    $req = "SELECT * FROM hitlist WHERE hit_id ='$addIDs_ary' and player_id = '$playerID'";
    $result = mysql_query($req) or die ('Error :'.mysql_error());
    if (mysql_num_rows($result)){
    $str = "";
        }
        else

     

    For some odd reason that just loops the whole results about 500x :/

     

    (4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.(4,17),(5,17)2 of 2 Investigated player(s) were successfully Removed.

  4. Example of the page, 3 boxes ticker, the id's vary (the first number is $addIDs_ary, the second $playerID)

     

    (2,17),(3,17),(4,17)3 of 3 Investigated player(s) were successfully added.

     

    before inserting them into the database, id like to check each $addIDs_ary to see if its already in the database, $addIDs_ary is stored under hit_id in hitlist, if it already exists id like to set $str = ""; if it doesnt exist it will go to else and continue with the other validation, best i can explain it really, unsure if that will fill you in more or not? worth a try anyhow

     

  5. Sorry basically for a page with checkboxes, where you can "investigate" multiple people on the page, all that works fine, id just like to throw it in so you cannot "investigate" the same person twice, the said code is supposed to loop and check if each id, in this case the variable for the id's is $addIDs_ary is already present under the hit_id column in the table hitlist.

     

    error wise i'm getting

     

    Warning: mysql_query() expects parameter 1 to be string, resource given in C:\Program Files\EasyPHP-5.3.3\www\public_html\PlayerRanks.php on line 21

     

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\Program Files\EasyPHP-5.3.3\www\public_html\PlayerRanks.php on line 22

     

    which would be the lines

     

    $result = mysql_query($query);
    while ($result = mysql_fetch_assoc($result))

     

    sorry for the terrible explanation hope this clears it up a bit more? as i say im terrible with loops and such so it is potentially wrong, id just like to confirm, and if its incorrect know what im doing wrong, Thanks

  6. Does anybody know how to make the following code correct? real sorry but its just absolutely blowing my mind im awful with loops and have pretty much no clue what the hell im doing in honesty, any help would be great, Thanks

     

    $addIDs_ary = array_map('intval', $_POST['chkInv']);
    $addIDs_ary = array_filter($addIDs_ary);
    $value = $addIDs_ary;
    //Check if hit_id is already in hitlist
    $query = mysql_query("SELECT * FROM hitlist WHERE player_id  = '$playerID'");
    $result = mysql_query($query);
    while ($result = mysql_fetch_assoc($result))
    foreach ($result as $hit_id => $value){
    if($result[$hit_id] == $value); 
    $str = "";
    }
    }
    else

  7. I dont know what im looking for is the honest truth, i just want to look it to see if $addIDs_ary is already set as hit_id in the table hitlist where the players_id = $playersID,, i get how to do it normally buy doing it for multiple results just baffles my mind

  8. Getting the following error Parse error: syntax error, unexpected T_AS in C:\Program Files\EasyPHP-5.3.3\www\public_html\PlayerRanks.php on line 22, really unsure as to why any insight please? Thanks

    $sql = "SELECT * FROM hitlist WHERE player_id = '$playerID'";
    $que = mysql_query($sql) or die(mysql_error()); 
    if (is_array($que['hit_id'] as $hits) {
    
      foreach ($que['hit_id'] as $hits) {
       //do somthing
      }
    }
    else

  9. Went with the following and still got an error,

    Warning: Invalid argument supplied for foreach() in C:\Program Files\EasyPHP-5.3.3\www\public_html\PlayerRanks.php on line 23, sorry not meaning to be a pain this is just blowing my mind.

     

    $sql = "SELECT * FROM hitlist WHERE player_id = '$playerID'";
    $que = mysql_query($sql) or die(mysql_error()); 
    $hitid = $que['hit_id'];
    foreach($hitid as $hits)
    if ($addIDs_ary == '$hits'){
    }
    else

  10. Sorry really bad with this type of stuff, tried the following and got Parse error: syntax error, unexpected T_FOREACH in C:\Program Files\EasyPHP-5.3.3\www\public_html\PlayerRanks.php on line 20, exactly how am i going about that wrong, Thanks

     

    $sql = foreach"SELECT * FROM hitlist WHERE player_id = '$playerID' AND hit_id = '$addIDs_ary'";
    $que = mysql_query($sql) or die(mysql_error()); 
    if ($que['hit_id'] == '$addIDs_ary'){
    $str = "";
    }
    else

  11. Yea i moved it up one and it worked, maybe a silly question but do you have any clue how you can see if $addIDs_ary is already in the table hitlists under the column hit_id? Unsure as of how to check this in a loop, Thanks.

     

     

    if (isset($_POST["submit"]) && $_POST["submit"] == "Investigate Players")
    {
    //Force POST values to be INTs
    $addIDs_ary = array_map('intval', $_POST['chkInv']);
    //Remove any 'false' value
    $addIDs_ary = array_filter($addIDs_ary);
    //Check that there was at least one valid value
    if ($playerdata['Informants'] <= count($addIDs_ary)){
    $attempt = count($addIDs_ary);
    echo "You are trying to investigate $attempt player(s) and only have $playerdata[informants] Informants available";
    }
    else
    if(count($addIDs_ary) > 0)
    {
    $str = "";
    foreach($addIDs_ary as $val)
    if(end($addIDs_ary) == $val)
    {
    $str .= "({$val},{$playerID})";
    }
    else
    {
    $str .= "({$val},{$playerID}),";
    if(end($addIDs_ary) == $val)
    {
    $str .= "({$val},{$playerID})";
    }
    }
    echo $str; // (val,val), (val,val), (val,val) etc..
    $query = "INSERT INTO hitlist
    (hit_id,player_id) values $str";

  12. Basically the following code works fine, exepct when it comes to the last result it inserts it twice, example:

     

    (3,17),(4,17),(5,17),(5,17)

     

    Any clues as to why? Thanks

     

    if(count($addIDs_ary) > 0)
    {
    $str = "";
    foreach($addIDs_ary as $val)
    {
    $str .= "({$val},{$playerID}),";
    if(end($addIDs_ary) == $val)
    {
    $str .= "({$val},{$playerID})";
    }
    }
    echo $str; // (val,val), (val,val), (val,val) etc..
    $query = "INSERT INTO hitlist
    (hit_id,player_id) values $str";

  13. Ahh sorry i guess i'm unsure as to how to go about an insert the code bwlow this deletes multiple results, id just like to add them instead:

     

    $query = "DELETE FROM hitlist
    WHERE hit_id IN ($deleteIDs_str) AND player_id = '$playerID'";
    if(mysql_query($query))

     

    Any clue how i could make that an insert? as when ive tried something along the lines of:

     

    $query = "INSERT INTO hitlist
    SET hit_id = IN ($deleteIDs_str) AND player_id = '$playerID'";
    if(mysql_query($query))

     

    I've error'd out any help would be great thanks

  14. Hey, Basically the script runs fine except for the fact its just inserting one user instead of multiple users, anyone have a clue as to why? would be a huge hand, Cheers

     

    <?php
    if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants")
    {
    //Force POST values to be INTs
    $addIDs_ary = array_map('intval', $_POST['chkInv']);
    //Remove any 'false' value
    $addIDs_ary = array_filter($addIDs_ary);
    //Check that there was at least one valid value
    if(count($addIDs_ary))
    {
    //Create comma separated string of the IDs
    $addIDs_str = implode(',', $addIDs_ary);
    //Create and run one query to perform all the adds (of the user) 
    $query = "INSERT INTO hitlist SET hit_id = '($addIDs_str)' AND player_id = '$playerID'";
    $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'";
    mysql_query($sql) or die(mysql_error());
    if(mysql_query($query))
    {
    $selectedCount = count($addIDs_ary);
    $adddCount  = mysql_affected_rows();
    echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully added.";
    }else{
    echo "There was a problem running the query.<br>" . mysql_error();
    }
    }else{
    echo "Invalid ID data passed.";
    }
    }

  15. I did try this, but it only works for one user and not the rest, sorry i probably am missing something easy here but i just cannot get my head around it

    $query = "INSERT INTO hitlist(hit_id,player_id) VALUES ('$addIDs_str','$playerID')";
    $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'";
    mysql_query($sql) or die(mysql_error());
    if(mysql_query($query))
    {
    

  16. Sorry completely over looked that

     

    There was a problem running the query.

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hit_id = (2,3), player_id = '17'' at line 2

     

    is the error msg im getting really unsure as to why

  17. Its the

     

    $query = "INSERT INTO hitlist
    hit_id = ($addIDs_str), player_id = '$playerID'";

     

    Thats the issue, my codes below i cannot figure out how to insert the results, any help would be appreciated Thanks

     

    if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants")
    {
    //Force POST values to be INTs
    $addIDs_ary = array_map('intval', $_POST['chkInv']);
    //Remove any 'false' value
    $addIDs_ary = array_filter($addIDs_ary);
    //Check that there was at least one valid value
    if(count($addIDs_ary))
    {
    //Create comma separated string of the IDs
    $addIDs_str = implode(',', $addIDs_ary);
    //Create and run one query to perform all the adds (of the user)
    $query = "INSERT INTO hitlist
    hit_id = ($addIDs_str), player_id = '$playerID'";
    $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'";
    mysql_query($sql) or die(mysql_error());
    if(mysql_query($query))
    {
    $selectedCount = count($addIDs_ary);
    $adddCount  = mysql_affected_rows();
    echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully Removed.";
    if($adddCount != $selectedCount)
    {
    echo " You do not have rights to the others.";
    }
    }else{
    echo "There was a problem running the query.<br>" . mysql_error();
    }
    }else{
    echo "Invalid ID data passed.";
    }
    }

  18. Sorry maybe a stupid question but Ive made a cron and its not updating the players cash as it should, can anyone spot why? I've looked but just cannot see it, Thanks appreciate your time for looking.

     

    <?php
    include("server.php");
    $sql = "SELECT * FROM players";
    $que = mysql_query($sql);
    while($res=mysql_fetch_array($que)) {
        $sql2 = "SELECT * FROM players WHERE id = '$res[id]'";
        $que2 = mysql_query($sql2) or die(mysql_error());
        $res2 = mysql_fetch_array($que2);
        $hoes = $res2['Hoes'];
        $hobedding = $res2['MaxHoes'];
        $incomemod = $res2['HoIncome'];
        $morale = $res2['HoesMorale'];
    if ($hoes < $hobedding) {
    $income = (250 * $hoes * $incomemod * $morale);
    } else {
    if ($hoes > $hobedding) {
    $income = (250 * $hobedding * $incomemod * $morale) + (125 * ($hoes - $hobedding) * $incomemod * $morale); 
    }
    $sql5 = "UPDATE players SET cash = cash + '$income' WHERE id = '$res[id]'";
    mysql_query($sql5) or die(mysql_error()); 	
    }
    }
    ?>					

  19. $sql = "SELECT DATE_FORMAT(timestamp, '%b %e, %H:%s') AS formatted_time FROM ledger";

    $que = mysql_query($sql) or die(mysql_error());

     

    echo "<tr><td class='lil1'>$que[formatted_time]</td>";

     

    would that be correct? sorry thinking i maybe read it wrong

  20. I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried;

     

    $time = date("j/n H:i", $Events['timestamp']);

     

    But no success can anyone point me in the correct direction? Thanks

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