טוב אז יש לי את הקוד הזה.
PHP קוד:
<?php
/**
* @author Mor Sela
* @copyright 2010
*/
class test{
private $text;
private $sqli;
private $result;
private $number;
private $result2;
private $num;
private $counter;
private $holder;
function coon(){
$this->sqli = new mysqli("localhost", "root", "", "test");
$this->number=2;
if(mysqli_connect_errno()){
echo 'Could not connect to data base , Error : '.mysqli_connect_error();
exit;
}
}
function getText(){
$this->result=$this->sqli->query("SELECT * FROM `tests`");
$this->num=$this->result->num_rows;
while ($this->result->fetch_object()) {
$this->result2=$this->result->fetch_assoc();
$this->echoText($this->result2['test1']);
}
}
function echoText($text){
echo '<div class="smalldiv">'.$text.'</div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Check Divs With PHP!</title>
<style>
.smalldiv{
text-align:center;
width: 99%;
border-style:solid;
border-color:blue;
border-width:1.5px;
}
</style>
</head>
<body>
<?php
$control = new test();
$control -> coon();
$control->getText();
?>
</body>
</html>
דבר ראשון , זה אפשרי שהוא מוציא לי 6 תוצאות ומדפיס רק 3?
והוא מדפיס רק את הזוגיים ולא את האי זוגיים , מה הבעיה פה?
דבר שני , האם זה אפשרי לקצר את הפעולה עם ה- while?
שזה קודם עושה fetch_object ואחרי זה עושים fetch_assoc , איך אפשר לקצר את זה אם אפשר והאם זה יעיל כמו שעשיתי? (אני בא מmysql רגיל וזה קצת שונה לי להריץ 2 פקודות על אותו מערך.)
תודה.