instanciation impossible php
Bonjour,
voila apres mille essais je me tourne vers vous, je doit afficher les infos d'in produit et mon objet products reste vide, j ai utiliser netbeans et a remarqer que l'autolad appelle bien la class mais ne rentre pas dans la class donc elle n utilise pas le cosntructeur.
que faire?
morceaux INDEX.PHP:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <?php
...
while ($value = mysql_fetch_array($res))
{
$products[] = $value['products_id'];
}
//et nous affichons :
echo '<div name="products">';
foreach($products as $id)
{
$product = new product($id);
print_r($product);
echo '<div name="singleproduct"><a href="details.php?productid='.$product->id.'">'.$product->name.'</a><br>
Prix net : '.$product->price.' (+ '. $product->tax.') zl
<br>
Description : '.substr($product->description, 0,150).'<a href="details.php?productid='.$product->id.'"></a>
</div>';
}
echo '</div>';
}
}
$bdd ->deconnecter();
}
else
{
die('Erreur: '. $error);
}
?> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?PHP
class products:
class product
{
public $id;
public $name;
public $description;
public $price;
public $tax;
public $count;
public $categoryid;
private $error;
public function __constuct($id='')
{
if($id!='')
{
$this->load($id);
return ($id);
}
else
{
echo (-1);
}
}
public function load($id)
{
$bdd = new BDD();
if($bdd ->connect()!=false)
{
$value = mysql_query("SELECT * FROM products WHERE products_id = '".$id."'");
$res=mysql_fetch_assoc($value);
print_r($res);
if(mysql_num_rows($value) == 0)
{
$this->error = "Le produit avec l'id pr�cis� n'existe pas !";
return false;
}
$this->id = $value['products_id'];
$this->name = $value['products_name'];
$this->description = $value['products_description'];
$this->price = $value['products_price'];
$this->tax = $value['products_tax'];
$this->count = $value['products_count'];
$this->error='';
$bdd ->deconnecter();
return true;
}
else
{
return false;
echo (-1);
}
}
?> |
merci.