Ben odaklı nesne yazarken alışmaya çalışıyorum, ama çoğu zaman ben biraz takılıyorum. Bu ben diziler oluşturmak için kullanmak istediğiniz sorgular var.
$user1 = mysql_fetch_object(mysql_query("SELECT * FROM tbl WHERE username='$oc->user1'"));
$user2 = mysql_fetch_object(mysql_query("SELECT * FROM tbl WHERE username='$oc->user2'"));
$user3 = mysql_fetch_object(mysql_query("SELECT * FROM tbl WHERE username='$oc->user3'"));
Ben böyle yaparak user1 konumunu alabilirsiniz: $location = $user1->location, ama kullanıcılara tüm yerleri ile bir dizi oluşturmak istiyorum ve ben bu denedim:
for ($x = 0 ; $x < $users_total; $x++ ){
$user = "user".($x + 1);
$user_location[$x] = $user->location ; //array med stedet alle brukerne befinner seg
}
Bu $user1->location çağırmalıdır, $user2->location, $user3->location dizisine [0] [1] ve [3]. Ama onun yerine ben almak
Notice: Trying to get property of non-object
Sorun nedir? I "user".($x + 1); bu gibi dize numaralar eklemek ve konumunu arayamazsın $user->location. Gibi aynı değil midir $user1->location?