Jump to content

Marcel1993

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Posts posted by Marcel1993

  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 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 ;-)

     

  4. 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]);
    

  5. 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  ;D

     

     

  6. 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];
    

  7. 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 :-)

  8. 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 :-)

  9. 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?

  10. Hey,

     

    I've got a query in which a variable is interpreted as a column and I don't why this is caused.

     

    $upgrade_time_sql = "SELECT * FROM todo_upgrades WHERE profile_id = ".$profile_id." AND level = ".$profile_data['level2_'.$show.'']." AND type = ".$show."";
    $upgrade_time_res = mysql_query($upgrade_time_sql) or die (mysql_error());
    

     

    $show is filled with the content "storage"

     

    The mysql_error is

     

    "Unknown column 'storage' in 'where clause'"

     

    Thanks for helping.

  11. Hey,

     

    $todo_upgrades_sql = "SELECT * FROM todo_upgrades WHERE time_completion >= $time";
    $todo_upgrades_res = mysql_query($todo_upgrades_sql) or die (mysql_error());

    results:

     

    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 '' at line 1

  12. Hey guys,

     

    I dont know whether this is the right place for my question. I've just installed XAMPP on a computer. Now I want to reach XAMPP on another one in my network. So I've just used the IP-adress from the computer where XAMPP is installed. This has been working very fine.

     

    Now I want to open "htdocs" using FTP. When I used the same IP-adress as stated above my computer didn't show htdocs to me as supposed. There is a directory "outgoing" and the file "onefile.html".

     

    Thank you for answering  :shy:

  13. Hey guys,

     

    I am looking for a possibily to create a multilingual application. The languages I want to provide are English, German, and Spainish. At first I thougth it is going to be very easy. I just create a extra table for the language-contents.

     

    ENGLISH GERMAN SPANISH

    TABLE    TISCH    MESA

     

    So far so good - but what will be if there is a phrase with included variables? I think in English it is quiet easy to form correct sentences. In German and Spanish there are some specifications what lead to garbled sentences.

     

    So LANGUAGE_PART_1 VARIABLE_1 LANGUAGE_PART_2 LANGUAGE_PART_2 wouldn't work as desired.

     

    Can I make PHP just set in a place any variable? So when I've got the sentence "At the moment there are #NUMBER_OF_TABLES# tables available", "Momentan sind #NUMBER_OF_TABLES# Tische verfügbar" or "Actualmente hay #NUMBER_OF_TABLES# mesas disponibles".

     

    In this case PHP is supposed to set in #NUMBER_OF_TABLES# the variable $number_of_tables.

     

    Perhaps there are some other ways for developing a multilingual app.

    Thanks a lot for helping  ::)

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