i have been trying to make a shopping cart, i have three files the first searches a database
the second (below) displays the result of the search and the third shows the shopping cart (below) on the shopping cart i am having trouble displaying the result in a table
i want each column to display a different piece of information
e.g column one title, column two artist, column 3 price
and i want each item in the shopping cart to be displayed in a different row
at present i am only able to display the title, price and artist in a single row of a single column can anyone help me
first file trolly.php
<?php
session_start(); // Initialise session
error_reporting(1); // suppress warning messages
if ($HTTP_POST_VARS["choice"]) {
$trolleyContents[count($trolleyContents)] = $HTTP_POST_VARS["choice"];
session_register("trolleyContents"); // Register our variables
} elseif ($HTTP_POST_VARS["clear"]) {
session_unregister("trolleyContents"); // Un-register our variables
} else {
session_register("trolleyContents");
}
?>
<html><head><title>PHP session example</title>
</head><body>
<h2 align="center">Shopping trolley (php session version)</h2>
<form method="post" action="trolly.php">
Choose an item: </p>
<input type="submit" name="clear" value="Empty the trolley" /><br />
<table border="1" cellpadding="3" cellspacing="1">
<tr>
<td>
<?php
if ((!$SESSION['trolleyContents'] && !$POST['choice']) || $clear) {
$SESSION['trolleyContents'] = "";
echo "<p>Trolley currently empty</p>";
} else {
if ( $POST['choice']) $SESSION['trolleyContents'] = $SESSION['trolleyContents'] . "<li>{$POST['choice']}</li>";
echo "<p>Trolley Contains</p>";
echo "<ul>{$SESSION['trolleyContents']}</ul>";
}
?></u>
</td>
</tr>
</body></html>
second file
results.php
<?php
session_start(); // Initialise session
error_reporting(1); // suppress warning messages
if ($HTTP_POST_VARS["choice"]) {
$trolleyContents[count($trolleyContents)] = $HTTP_POST_VARS["choice"];
session_register("trolleyContents"); // Register our variables
} elseif ($HTTP_POST_VARS["clear"]) {
session_unregister("trolleyContents"); // Un-register our variables
} else {
session_register("trolleyContents");
}
?>
<html>
<head>
<title>Online CD Shop - Results</title>
</head>
<body bgcolor="#ffffff" text="000000">
<h2>Online CD Shop - Results</h2>
<table border="1" cellpadding="3" cellspacing="1">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Price</th>
<th>Genre</th>
<th>Add to Trolley</th>
</tr>
<?php
//connect to the MySQL server
$conn = @ mysql_connect("localhost") or die(mysql_error());
//select the database
mysql_select_db('CdShop', $conn) or die(mysql_error());
//attempt to fetch the form variables
$query = addslashes($HTTP_GET_VARS['query']);
$type = $HTTP_GET_VARS['type'];
//Query the database
if (empty($query)){
if($type == 'all')
$sql ="SELECT title,artist,genre, price, release, sleeve FROM cd, genre, artist WHERE cd.genreNo=genre.genreNo AND cd.artistNo=artist.artistNo";
}
if (!empty($query) && !empty($type)) {
if ($type == 'title') {
$sql = " SELECT price, title, artist, genre FROM cd, artist, genre WHERE cd.genreNo=genre.genreNo AND cd.artistNo = artist.artistNo AND title LIKE '%$query%'";
} elseif ($type == 'artist') {
$sql = " SELECT price, title, artist, genre FROM cd, artist, genre WHERE cd.genreNo=genre.genreNo AND cd.artistNo = artist.artistNo AND artist LIKE '%$query%'";
} elseif ($type == 'genre') {
$sql = " SELECT price, title, artist, genre FROM cd, artist, genre WHERE cd.genreNo=genre.genreNo AND cd.artistNo = artist.artistNo AND genre LIKE '%$query%'";
}
}
$result = mysql_query($sql, $conn);
//Print the <option> rows for the <select> widget
if ($result && (mysql_num_rows($result) >0 )) {
while ($row = mysql_fetch_assoc($result)) {
?>
<form method="POST" action="trolly.php">
<tr>
<td>
<input type ="text" name="choice" value=<?php echo
(htmlspecialchars($row['artist'])) .
(htmlspecialchars($row['price'])) .
(htmlspecialchars($row['title']))?>/>
</td>
<td>
<?php echo(htmlspecialchars($row['artist']));?>
</td>
<td>
<?php echo (htmlspecialchars($row['price']));?>
</td>
<td>
<?php echo(htmlspecialchars($row['genre']));?>
</td>
<td><input type="submit" name="submit" value="Add to the trolley" /></td>
</tr>
</form>
<?php
}
} else{
echo("<tr><td colspan=\"6\"> No matches were found.</td></tr>\n");
}
//close the database connection
mysql_close($conn);
?>
</table>
<a href="search.php">Search Again</a>
<form action="delete.php" method="GET">
Delete: <input name="query" type="text" /><br />
<input type="submit" value="Delete"/>
</form>
<body>
</html>