Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Successfully retrieved data from MySQL but how do I control how it displays.

Discussion in 'Scripting' started by AbsoluteZero, Nov 23, 2013.

  1. AbsoluteZero

    AbsoluteZero

    Joined:
    Sep 2, 2013
    Posts:
    19
    Hello everyone,

    I am able to retrieve data from an SQL Database however I still need to control how it looks.

    I retrieve the data using the following PHP code:
    Code (csharp):
    1.          
    2. $query = "SELECT * FROM `highscores` ORDER by `score` DESC LIMIT 5";
    3. $result = mysqli_query($connection, $query) or die('Query failed: ' . mysql_error());
    4.      
    5.          $num_results = mysqli_num_rows($result);  
    6.      
    7.          for($i = 0; $i < $num_results; $i++)
    8.          {     
    9.              $row = mysqli_fetch_array($result);
    10.              echo $row['name'] . "\t" . $row['score'] . "\n";
    11.                  }
    And display it in unity using the following C# code:

    Code (csharp):
    1.         G1.guiText.text = "Loading Scores";
    2.         WWW hs_get = new WWW(highscoreURL);
    3.         yield return hs_get;
    4.  
    5.         if (hs_get.error != null)
    6.         {
    7.             print("There was an error getting the high score: " + hs_get.error);
    8.         }
    9.         else
    10.         {
    11.            G1.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
    12.         }
    and it display as so:
    $score.PNG

    Your kind advice is appreciated,

    Thanks,
     
  2. AbsoluteZero

    AbsoluteZero

    Joined:
    Sep 2, 2013
    Posts:
    19
    No one fiddled with gui before ? :(