2016-06-07 8 views
0

Wie kann ich auf den Wert overall_score zugreifen, ohne eine foreach jede Schleife zu tun?Wie greife ich auf diese Objekteigenschaft ohne foreach-Schleife zu

Ich versuche, den Wert Gesamtnote erhalten, habe ich versucht $links->overall_score aber ich bekomme:

Notice: Undefined property: mysqli_native_moodle_recordset::$overall_score in /Users/richard/Sites/moodle/moodle/report/link_critic/link_detail.php on line 90

So bin ich

tun
$links = $DB->get_recordset_sql($query_links); 

hier ist das Objekt, das ich zurück von meiner Anfrage erhalten

mysqli_native_moodle_recordset Object 
(
[result:protected] => mysqli_result Object 
    (
     [current_field] => 0 
     [field_count] => 17 
     [lengths] => Array 
      (
       [0] => 4 
       [1] => 4 
       [2] => 2 
       [3] => 1 
       [4] => 10 
       [5] => 24 
       [6] => 18 
       [7] => 1 
       [8] => 0 
       [9] => 29 
       [10] => 5 
       [11] => 4 
       [12] => 1 
       [13] => 1 
       [14] => 0 
       [15] => 10 
       [16] => 1 
      ) 

     [num_rows] => 21 
     [type] => 0 
    ) 

[current:protected] => Array 
    (
     [id] => 17397 
     [resource_id] => 2512 
     [page_id] => 15 
     [user_id] => 1 
     [link_submitted] => 1462649904 
     [link_title] => Cold Spring Harbour page 
     [link_description] => A useful brain map 
     [link_status] => 1 
     [link_broken] => 
     [link_url] => http://www.g2conline.org/2022 
     [link_id] => 1583 
     [vote_score] => 1 
     [vote_comment] => 
     [vote_timestamp] => 1464795526 
     [overall_score] => 1 
    ) 

) 

A Var Dump von $ Links-> current()

object(stdClass)#4476 (15) { ["id"]=> string(5) "17397" ["resource_id"]=> string(4) "2512" ["page_id"]=> string(2) "15" ["user_id"]=> string(1) "1" ["link_submitted"]=> string(10) "1462649904" ["link_title"]=> string(24) "Cold Spring Harbour page" ["link_description"]=> string(18) "A useful brain map" ["link_status"]=> string(1) "1" ["link_broken"]=> NULL ["link_url"]=> string(29) "http://www.g2conline.org/2022" ["link_id"]=> string(4) "1583" ["vote_score"]=> string(1) "1" ["vote_comment"]=> NULL ["vote_timestamp"]=> string(10) "1464795526" ["overall_score"]=> string(1) "1" } 
+0

Eine Vermutung nach einer schnellen Google-Suche, $ links-> current() ['overall_score'] '? (Abhängig von der PHP-Version). –

+0

Es sieht so aus, als hätte es ein paar Arrays. Probieren Sie $ links-> current ["overall_score"] ' –

+0

@JeffPuckettII $ links ist ein Objekt nach dem Aussehen, und die' current' Eigenschaft ist geschützt. –

Antwort

0

Recordset gibt mehrere Datensätze zurück.

https://docs.moodle.org/dev/Data_manipulation_API#Using_Recordsets

So overall_score unter der Annahme ist eine Spalte in der SQL, die Sie verwenden sollten:

$links = $DB->get_recordset_sql($query_links); 
foreach ($links as $link) { 
    echo $link->overall_score; 
} 
$links->close(); // This bit is very important!!! 

Wenn Sie nur dann einen einzelnen Datensatz erwartet get_record_sql()

$link = $DB->get_record_sql($query_links); 
echo $link->overall_score; 

verwenden Wenn Sie sind neu in Moodle, dann behalten Sie dies in Ihrem Browser als Referenz:

https://docs.moodle.org/dev/Data_manipulation_API

Verwandte Themen