Burti adlı üyeden alıntı: mesajı görüntüle
E-Ticaret sistemi yazdım onun için mysql'den çekmek lazım..
E-ticaret sistemi yazmış bir insan için böylesi basit bir hata çok şaşırtıcı. Yanlış anlamayın ama bir sistem yazmadan önce bu işin inciğini cinciğini öğrenmeniz daha sağlıklı olur.

Veritabanınızın id - name - price şeklinde olduğunu varsaydım. Aşağıdaki kodlar iş görür. switch ile nasıl yapacağınızı gösterdim ama gereksizdir. Hemen altında yorum satırı ile birlikte if ile kullanımını gösterdim. O şekil kullanın.


<?php

include('../configuration.php'); 
if(!isset($_POST['productId']))exit;    /* No product id sent as input to this file */ 
$get_product = mysql_query("SELECT * FROM products ORDER BY id ASC");
$product = null;
while($list_product = mysql_fetch_array($get_product)){
	$product[$list_product['id']] = array('id'=>$list_product['id'], 'name'=>$list_product['name'], 'price'=>$list_product['price']);
}

switch($_POST['productId']){
	default: 
		echo $product[$_POST['productId']]['id'].'|||'.$product[$_POST['productId']]['name'].'|||'.$product[$_POST['productId']]['price'];
		break;
}

/* Switch kullanacağına aşağıdaki gibi bir if yapısı kullan daha güzel olacaktır. */

if(isset($product[$_POST['productId']])){
	echo $product[$_POST['productId']]['id'].'|||'.$product[$_POST['productId']]['name'].'|||'.$product[$_POST['productId']]['price'];
}

?>