PDA

View Full Version : Cant Get Data


antubob
05-09-2006, 09:20 AM
i have 1 mysql database name data1.. then in the database have 3 column .. named with id,name,item..this database is for keep list of item that customer have purchase..

what i want to do is to collect list of item which the person purchase..so it will display name and item of purchase when i enter id for request query..

any body can help me?

i try with this code but it doesn't working. when i run this command it will read the first row of the table and if the id didnt match with the id in first row of the table it will run the else command.

<?php
session_start();
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("data1") or die(mysql_error());
$id = $_SESSION['views'];

$result = mysql_query("SELECT * FROM purchase") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$point = $row['id'];
}

if ($id == $point) {
$URL="http://www.try.com/collection_details.php";
header ("Location: $URL");
}
if ($id != $point) {
$URL="http://www.try.com/nodb.php";
header ("Location: $URL");
}
?>

guelphdad
05-09-2006, 04:05 PM
This is really a PHP question and should have been posted there. Your problem is that you loop through all your results coming from mysql and only test the very last value. You need to change your code like this:


<?php
session_start();
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("data1") or die(mysql_error());
$id = $_SESSION['views'];

$result = mysql_query("SELECT * FROM purchase") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$point = $row['id'];


if ($id == $point) {
$URL="http://www.try.com/collection_details.php";
header ("Location: $URL");
}

if ($id != $point) {
$URL="http://www.try.com/nodb.php";
header ("Location: $URL");
}

}
?>