Hi,
I’m trying to create a ScrollViewList to show the users that have the same classroom code in mysql. So if three users have same classroom code, then they see eachother in the Classroom List.
For this purpose, I tried to get the data from mysql:
PHP:
siniflistesi.php
<? php
$con = mysqli_connect('IP','dbname','dbpass','dbuser');
if (mysqli_connect_errno())
{
echo "1: Bağlantı kurulamadı."; //error code 1=connection failed
exit();
}
$classroom = mysqli_real_escape_string($con, $_POST["classroom"]);
$query = "SELECT * FROM users WHERE classroom IN(SELECT classroom FROM users GROUP BY classroom having count(classroom ) > 1)"
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo "0\n";
echo $row["username"]."\t". $row["pp"]."\n".;
//echo ";".$row["username"]. ";".$row["pp"].; // pp is a point name.
}
}
else
{
echo "User info is wrong.";
}
?>
And then created a c# for listing.
SinifListesi.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SinifListesi : MonoBehaviour {
public Button button;
public Text ListNameLabel;
public Text ListPpLabel;
public Image ListAvatarImage;
public GameObject ListKingImage;
}
And using this to create the list:
SinifListesi_CreateScrollList.cs
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
[System.Serializable]
public class item
{
public string ListName;
public string ListPp;
public Sprite ListAvatar;
public bool ListKing;
public Button.ButtonClickedEvent thingToDo;
}
public class SinifListesi_CreateScrollList : MonoBehaviour
{
public GameObject sampleButton;
public Transform contentPanel;
public List<item> itemList;
void Start()
{
StartCoroutine(Listingclassroom());
}
IEnumerator Listingclassroom()
{
WWW snflst = new WWW("http://localhost/sqlconnect/siniflistesi.php");
yield return snflst;
if (snflst.text != null)
{
DBManager.SnfLst = snflst.text;
foreach (var item in itemList)
{
GameObject newButton = Instantiate(sampleButton) as GameObject;
SinifListesi buttonScript = newButton.GetComponent<SinifListesi>();
buttonScript.ListNameLabel.text = "Ö:" + snflst.text.ToString();
buttonScript.ListPpLabel.text = item.ListPp;
buttonScript.ListAvatarImage.sprite = item.ListAvatar;
buttonScript.ListKingImage.SetActive(item.ListKing);
buttonScript.button.onClick = item.thingToDo;
newButton.transform.SetParent(contentPanel, false);
}
}
}
public void DoSomething()
{
Debug.Log("Something");
}
}
Do you have any suggestions?
Thank you.