![]() |
# 1 |
חבר מתקדם
|
בעיה עם מחלקה בPHP
יש לי מחלקה שמנהלת מסד נתונים, עכשיו יש פעולה פנימית כזו:
קוד:
public function select($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM '.$table; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; $query = @mysql_query($q); if($query) { $this->numResults = mysql_num_rows($query); for($i = 0; $i < $this->numResults; $i++) { $r = mysql_fetch_array($query); $key = array_keys($r); for($x = 0; $x < count($key); $x++) { // Sanitizes keys so only alphavalues are allowed if(!is_int($key[$x])) { if(mysql_num_rows($query) > 1) $this->result[$i][$key[$x]] = $r[$key[$x]]; else if(mysql_num_rows($query) < 1) $this->result = null; else $this->result[$key[$x]] = $r[$key[$x]]; } } } return true; } else { return false; } } ואז קראתי למחלקה בדף אחר, ואם אני כותב: קוד:
$res = $msgs->getResult(); print_r ($res); וזה מציג לי את התכנים של המערך. אבל אם אני עושה echo $res הוא מדפיס "Array". מה שאני רוצה בעצם זה ש echo $res ידפיס את כל התכנים של המערך. |
![]() |
![]() |
# 2 |
חבר מתקדם
|
אתה לא יכול להדפיס תוכן של מערך בעזרת ECHO או PRINT. מערך מכיל מספר אלמנטים. תבצע לולאה שבכל שלב בלולאה תדפיס את התוכן של האלמנט הנוכחי.
|
![]() |
![]() |
# 3 | |
חבר מתקדם
|
ציטוט:
קוד:
foreach($res as $value) { echo $value; } ArrayArray אני פשוט רגיל לC#, וכן אני יודע שהתחביר דומה בסה"כ, אבל יש הבדלים וכל מיני פונקציות שאני עדיין לא רגיל אליהם, ככה שאם יש לך הצעה תודה. עריכה: אם זה עוזר, הנה הדף המלא: קוד:
<?php /* Adding Messages */ $msgs = new Messages(); $msgs->connect(); $msgs->select('messages','*'); //$msgs->insert('messages',array(0,1,0,"","Shmuel","Today","","Shillo","sshilo@gmail.com")); $res = $msgs->getResult(); //print_r ($res); foreach($res as $key=>$value) { echo $value . $key; } ?> Last edited by Shillo; 06-05-09 at 13:58.. |
|
![]() |
![]() |
# 4 |
חבר מתקדם
|
print_r ($res);
מה זה מחזיר? |
![]() |
![]() |
# 5 |
חבר מתקדם
|
Array ( [0] => Array ( [msg_id] => 14 [isParent] => 1 [msg_level] => 0 [smiley_path] => [msg_content] => Shmuel [msg_pdate] => Today [attachment_path] => [author_name] => Shillo [author_email] => sshilo@gmail.com ) [1] => Array ( [msg_id] => 13 [isParent] => 1 [msg_level] => 0 [smiley_path] => [msg_content] => Hello [msg_pdate] => Today [attachment_path] => [author_name] => Shillo [author_email] => sshilo@gmail.com ) )
|
![]() |
![]() |
# 6 |
חבר מתקדם
|
אז הייתי מציע שתקרא אודות ARRAYS
PHP קוד:
|
![]() |
![]() |
# 7 | |
חבר מתקדם
|
ציטוט:
![]() |
|
![]() |
![]() |
חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים) | |
כלים לאשכול | |
תצורת הצגה | |
|
|