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 /
  • Help Room /
avatar image
0
Question by master1122334455 · Oct 09, 2016 at 11:02 AM · mysqlphp

Mysql/PHP Grab specific data

I am trying to get a text field and a button for a player to enter in his/her username and then unity sends a get request to a .php and then sends unity the specific player data. In this case I am trying to get player's coordinates. So the player enters their username and it sends back a vector3 data.

Here is my PHP script. Name is the username, age is X, age2 is Y, age3 is Z.

     <?php
         $con = new mysqli("localhost","root","","game");
 
         if(isset($_POST['name']) && isset($_POST['age']) && isset($_POST['age2']) && isset($_POST['age3'])){
         $name = $_POST['name'];
         $age = $_POST['age'];
         $age2 = $_POST['age2'];
         $age3 = $_POST['age3'];
         
         
         
         $query = $con->query("SELECT * FROM items WHERE name='$name'");
         if($query->num_rows > 0){
         $con->query("UPDATE items SET age='$age' , age2='$age2', age3='$age3' WHERE name='$name'");
         }
         else{
             $con->query("INSERT INTO items (name,age,age2,age3) VALUES ('$name', '$age', '$age2', '$age3')");
         }
         }
         $result = $con->query("SELECT * FROM items");
         if($result->num_rows > 0){
             echo(";");
             while($row = $result->fetch_assoc()){
                 echo("Name:".$row["name"] . "|X:" . $row["age"] . "|Y:" . $row["age2"] . "|Z:" . $row["age3"] . ";");
             }
         }
         else{
             echo("Database is empty");
         }
     ?>
 

I don't have anything great for a working C# script but I have this which separates the data but that doesn't help me if I need only a specific player's data. using UnityEngine; using System.Collections;

 public class Location : MonoBehaviour {
 
     private string textFieldString = "Username";
 
     void OnGUI ()
     {
         textFieldString = GUI.TextField(new Rect(500, 25, 100, 30), textFieldString, 25);
 
 
         GUI.Label(new Rect(505, 75, 100, 100), textFieldString);
     }
 
     public string[] items;
 
     // Use this for initialization
     IEnumerator Start () {
         WWW itemsData = new WWW("localhost/game/plrdata.php");
         yield return itemsData;
         string itemsDataString = itemsData.text;
         print(itemsDataString);
         items = itemsDataString.Split(';');
     }
     
 
 }
Comment
Add comment · Show 10
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 doublemax · Oct 09, 2016 at 11:41 AM 0
Share

What exactly is your question/problem? It seems you already receive the correct string with the items data. So you just don't know how to parse the string?

avatar image master1122334455 doublemax · Oct 09, 2016 at 11:47 AM 0
Share

I did not receive the one player's data that I wanted, I received all of my data from the mysql server. I have multiple player's vector3 data in a mysql server but I want to have a text box where it will search for that one player's vector3 data and only that player's data.

avatar image doublemax master1122334455 · Oct 09, 2016 at 12:02 PM 1
Share

(Answering here because of stupid forum bug)

What line would I put " $result = $con->query("SELECT * FRO$$anonymous$$ items");" in?

I'm talking about line 20 in above PHP script. I think the filter "WHERE name='$name'" is missing and that's why it returns all items.

Compare line 20 and line 12 in the PHP script.

Show more comments
Show more comments
avatar image master1122334455 doublemax · Oct 09, 2016 at 12:08 PM 0
Share

I know, I want the php script to show all users. I just want unity to be able to pick out a single user from that list. Thus making it so multiple players can use this at once.

avatar image doublemax master1122334455 · Oct 09, 2016 at 12:27 PM 0
Share

So the string parsing is indeed the problem?

I would suggest to use JSON for the data transfer. It'll save you a lot of time in the long run.

http://www.kodingmadesimple.com/2015/01/convert-mysql-to-json-using-php.html

http://wiki.unity3d.com/index.php/SimpleJSON

Show more comments
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

76 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 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

Decoding JSON string 0 Answers

500 Internal server error in WWWForm 0 Answers

Can I add a table to a mySQL database using C#? 0 Answers

C# safe connect to MySQL database. Download and upload data via PHP script. 1 Answer

Certain parts of database not being retrieved in Webplayer/Android, other parts work fine. Everything works fine in Editor/Standalone. 0 Answers


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