Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by laharl219 · Mar 15, 2016 at 02:50 PM · dropdowndynamicallyfillsqldatabase

Can i fill a dropdown with data from a database or a Json file?

I need to dynamically fill a dropdown at unity, i can get the information from a database or a Json file(I just know how to fill a dropdown manually at the dropdown's component). Is there a way to do it?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by matthewseaward · Mar 15, 2016 at 08:49 PM

I'm assuming you are using the new UI elements and canvas?

This is simple:

 public Dropdown myDropdown; // Make sure to assign this
 private List<string> data;
 
 void Start()
 {
      data = LoadDataFromDBOrJSON(); // Or whatever way you will read your data in
 
      myDropdown.options.Clear();
      foreach(string str in data)
      {
         myDropdown.options.Add(new Dropdown.OptionData(str));
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tsondhi2006 · Dec 18, 2017 at 04:37 PM 0
Share

how to read the data from the mysql db??

avatar image
0

Answer by unity_eVEKXzm04KI-og · Jul 03, 2018 at 01:02 AM

The same question cómo leer los datos del mysql db ??,Lo mismo que pregunto tsondhi2006 cómo leer los datos del mysql db ??

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tsondhi2006 · Jul 12, 2018 at 09:03 PM

Did it:-

1) Create a c# file

 void Func1()
     {        
         WWW www = new WWW ("127.0.0.1/somefolder/somefile.php");// give location of Php file
         while (!www.isDone) {
         }
         string itemsDataString = www.text;
         string[] wwwItems = itemsDataString.Split (';'); //the values in mysql db is picked in a single string and should have some marker so as to split
         DD.options.Clear ();
         foreach (string str in wwwItems) {
             DD.options.Add (new Dropdown.OptionData (str));
         }
 }

2) Create a php file which will pass the values from mysql to unity [somefile.php]:-

 <?php
     $conn = new mysqli("127.0.0.1", "root", "", "somedb");
 
     if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
     }
     $sql = "SELECT * FROM sometable";
     $result = $conn->query($sql);
     if ($result->num_rows > 0) {
         // output data of each row
             while($row = $result->fetch_assoc()) {
             echo ";".$row["somefield"];
         }
     }
     $conn->close();
 ?>
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

40 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i make a dropdown via script(not using the new UI) 1 Answer

Create a Dropdown Menu with values from Database 0 Answers

load 3d model.. edit on runtime and export asset bundle + metadata on runtime 0 Answers

FullScreenMovieScalingMode 0 Answers

Alternative Slider Method 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges