Jump to content

Marcel1993

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Marcel1993's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey guys, I've got a table with the following contents: CID VALUE TIME 1 A 500 1 B 700 1 C 400 2 D 100 2 E 300 3 F 100 Now I want to output this table without having entries with the same CID. If a entry got a unique CID it is supposed to get displayed. If several entries got the same CID, only the entry with the highest time is supposed to get displayed: Example: 1 B 700 2 E 300 3 F 100 Is there a way to solve it in SQL? Thanks :-)
  2. Hey ;-) thank you for creating the query! I tried it but there is a malfunction in the script. It shows as many results as available profiles, in reference to the USED_ID. If the user got 3 profiles, the result contains 3 rows, independent whether the WORLD_ID matches the column "WORLDS" in "comp". The rows that are not matching with "comp" are empty, the right ones are filled with the correct content. Thanks ;-)
  3. Hey, thank you for answering. I read a lot of examples on the internet for join but I don't know how to start in my case :-( I will be very happy if you can help me
  4. Hey guys, I want to creat a SQL-Query and I don't know how to construct the part of "where". There are four tables 1: users - important column ID (USER_ID) 2: profiles (each user is able to create more than one profile) - important column WORLD_ID, USER_ID (3: comp_participants (each user is able to create more than one entry in the table, each comp_participant is connected to "comp")) 4: comp - important column WORLDS (e.g. "2, 4, 20") $user_id is set (e.g. 44) Now I want to show all entries of "comp" if the user got a profile on a world which is listed in WORLDS in the table "comp". I thing it is a very difficult kind of SQL-query and I look forward to a answer ;-) Best regards ;-)
  5. Hey guys, I've got a if-statement, which is supposed to be true by some kinds of combinations: $true = "1,2,3"; $value = 1 (TRUE) $value = 2 (TRUE) $value = 3 (TRUE) $value = 4 (FALSE) How can I put it in an if-statement? Best regards ;-)
  6. Hey guys, I want to create stats of visitors and some other values in the database depending on time. The stats are supposed to be created one time per hour. What can I use for it? Cronjob? What will be if it doesn't work?? Thanks for helping!
  7. Sorry, there were little mistakes in. I corrected these and now I think it is working :-) Thanks for helping! I try this script seriously and then I post again
  8. Okay, I tried, but that doesn't work: <?php include 'includes/settings/mysql.php'; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbbase); $time = time(); $update_weed_world_data_sql = "SELECT id, weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_id = $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; } function do_update_weed($profile_id,$world,$update,$level,$time,$ba,$fa){ $update_weed_period = $time - $update; $update_weed_add = ($update_weed_period / 3600 * $ba[$world] * pow($fa[$world],$level)) +1; echo $update_weed_world_basis[$world]*5; echo "<br>"; mysql_query("UPDATE profiles SET weed = weed +$update_weed_add, weed_update = $time WHERE id = $profile_id LIMIT 1"); } function todo_update_weed($time,$ba,$fa){ $todo_update_weed_sql = "SELECT * FROM profiles WHERE weed_update < $time"; $todo_update_weed_res = mysql_query($todo_update_weed_sql) or die (mysql_error()); while($todo_update_weed_while = mysql_fetch_assoc($todo_update_weed_res)){ do_update_weed( $todo_update_weed_while['id'], $todo_update_weed_while['world_id'], $todo_update_weed_while['weed_update'], $todo_update_weed_while['level_farm'], $time, $ba, $fa ); } } todo_update_weed($time, $update_weed_world_basis[$update_weed_world_id], $update_weed_world_factor[$update_weed_world_id]);
  9. Thanks, but $update_weed_add has to be set inside the function.
  10. Hey, I've been developing a browsergame. In this you are able to produce something ("weed"). Now I've got some kind of trouble with the function that is responsible for updating the "weed" on the user accounts. Im going to explain, how my script is working First step: Loading the datas from "worlds". In this case id, weed_factor, weed_basis. What this is required for you will see in the next steps <?php include 'includes/settings/mysql.php'; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbbase); $time = time(); $update_weed_world_data_sql = "SELECT id, weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_id = $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; global $update_weed_world_basis; } Second step: This is the function which is editing each account by the data given as parameters. function do_update_weed($profile_id,$world,$update,$level,$time){ $update_weed_period = $time - $update; $update_weed_add = ($update_weed_period / 3600 * $update_weed_world_basis[$world] * pow($update_weed_world_factor[$world],$level)) +1; echo $update_weed_world_basis[$world]; echo "<br>"; mysql_query("UPDATE profiles SET weed = weed +$update_weed_add, weed_update = $time WHERE id = $profile_id LIMIT 1"); } Note: echo $update_weed_world_basis[$world]; doesnt result an output. In step three, the accounts are loaded: function todo_update_weed($time){ $todo_update_weed_sql = "SELECT * FROM profiles WHERE weed_update < $time"; $todo_update_weed_res = mysql_query($todo_update_weed_sql) or die (mysql_error()); while($todo_update_weed_while = mysql_fetch_assoc($todo_update_weed_res)){ do_update_weed( $todo_update_weed_while['id'], $todo_update_weed_while['world_id'], $todo_update_weed_while['weed_update'], $todo_update_weed_while['level_farm'], $time ); } } And the last step is calling function "todo_update_weed" with the time. todo_update_weed($time); I script calculate the time between the last update and the current time. This make a difference in time. With this value I calculate something else. And then the update time has to be saved. The script has just working fine, when I set the variable "$update_weed_add" with a fix value. But by now the script doesn't work, because I don't know how to make the array available inside functions. I considered whether I put the database-function for the world_data inside the function that updates the profiles. But if I do this, the database will be called thousands of times... Hope anybody has a nice idea to fix the problem
  11. Hey, thanks for helping :-). I've just made an embarrassing mistake I didn't select "id" in the SQL-Query... Don't be cross with me
  12. Thank you but that didn't lead to any difference: $update_weed_world_data_sql = "SELECT weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_id = $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; } echo $update_weed_world_factor[1];
  13. Hey, my code doesnt work and I dont know why: $update_weed_world_data_sql = "SELECT weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_basis[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_factor']; } I want to save some rows in variables identifiable by the value in the array. As example. When I want to echo $update_weed_world_factor['1'] - I want to get the row with ID 1 and the column "world_factor". I've used this code long time ago - but know something was going wrong. Thanks for helping :-)
  14. Hey guys, I don't know what to do. I've got a script used for gamble: $gamble_rand = rand($number_of_tickets,$gamble_chance); if($gamble_chance == $gamble_rand){ If $number_of_tickets is set by 99 and $gamble_chance is set by 100 the chance is 1:100 that the If-Clause is not true. But it seems to me that PHP is making its on "random". Independent of the values PHP is interpreting that 20 times of 100 times the correct logic is false... If $number_of_tickets is set by 1 there's no big different. Its just a little bit less, but not the chance that it has to be. Thanks for helping and Merry Christmas :-)
  15. Hey, I've got a table with thousands of entries. No I want to select some of them. At first I want to get some of them with a more exact condition. The other ones I want to pick with using ORDER BY RAND() Its there a way to put this in one query?
×
×
  • 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.