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 dbzfan254 · Aug 20, 2016 at 09:44 AM · c#mysqlsqlquizsqldatabase

C# How to select certain SQL data?

I have a c# script using a web request to connect to my mySQL database through php. Right now it displays the entire table on one GUIText component on a GameObject. My database has 3 columns, one for the identifying number, one for the Name, and one that contains image URLs. I want the game to use the level number and choose the SQL row with a identifying number corresponding to that number. It would select that row and put it’s Name in the GUIText component and use the Image URL to put in image on another component. When the level number changes to the next level the content would need to change to the corresponding row. My problem is I only know how to get Unity to show the whole table at once… How do I get it to use a level number (integer) to choose one row of the mysql table and show one column at a time?

The PHP:

 $query = "SELECT * FROM `CharacterGallery` ORDER by `charID` DESC LIMIT 5";
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $num_results = mysql_num_rows($result);
 for($i = 0; $i < $num_results; $i++)
 {
 $row = mysql_fetch_array($result);
 echo $row['charID'] . "\t" . $row['Name'] . "\n" . $row['ImageURL'] ."\t";
 }

The c#:

 using UnityEngine;
 using System.Collections;
 public class CharacterGallery : MonoBehaviour
 {
 public string displaychargalleryURL = "http://displaychargalleryurl.com";
 void Start()
 {
 StartCoroutine(GetCharacterGalleryQue());
 }
 // Get the questions from the MySQL DB to display in a GUIText.
 // remember to use StartCoroutine when calling this function!
 IEnumerator GetCharacterGalleryQue()
 {
 gameObject.GetComponent().text = "Loading Scores";
 WWW hs_get = new WWW(displaycharactergalleryURL);
 yield return hs_get;
 if (hs_get.error != null)
 {
 print("There was an error getting the Character Data: " + hs_get.error);
 }
 else
 {
 gameObject.GetComponent().text = hs_get.text;
 }
 }
 }


Comment
Add comment · Show 8
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 sourav13 · Aug 20, 2016 at 10:39 AM 0
Share

You can change your query to include the WHERE CLAUSE

$query = "SELECT * FRO$$anonymous$$ CharacterGallery WHERE 'charID = 1

And if you want to change that 1 , do it in php change it to some variable and similarly make a variable in C# and than send it in your URL .

avatar image dbzfan254 sourav13 · Aug 20, 2016 at 11:07 AM 0
Share

Okay, that's helpful, thanks. Now could you help with the part of displaying conent from columns according to the charID column? Like say the charID variable is 1, on my "Image" gameobject, I need it to show the image stored in the "image" column on the row charID 1 row. And on my "Title" gameobject, it needs to display the text stored in the "title" column of the same row as charID 1.

avatar image sourav13 dbzfan254 · Aug 20, 2016 at 11:43 AM 0
Share

Than the next step would be , to get the data in your hs_get as hs_get.text and than from what you retrieve you have to separate the values ,for that i would suggest first on php side using your result ,encode it into JSON and use some json parsing utility in unity you will easily get the name and the image url this way and than make another request with image url and you can then use the way unity documentation says public class ExampleClass : $$anonymous$$onoBehaviour { public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg"; IEnumerator Start() { WWW www = new WWW(url); yield return www; Renderer renderer = GetComponent(); renderer.material.mainTexture = www.texture; } }

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Access a MySQL database via C# ? 2 Answers

Building a dedicated server for multiplayer 0 Answers

When built for web player, my php doesn't return the datatable. Works just fine in standalone build and while editing. 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