Posted by Stephen Preston on 12/05/05 19:47
I can't get an $array[key] to be used as a select query on a mySQL database.
I have a 'parts list' which displays on a page (works fine) and is a form.
At the end of each row is a input type='text' (quantity) cell with a default
0
The quantity can be altered.
At the bottom of the table (form) is a submit to basket Button
echo "<form action='basket.php' method='POST'>\n";
while ($row = mysql_fetch_array($result))
extract($row);
echo "<tr>\n
<td WIDTH=10% align='middle'><FONT SIZE=-1 face=Arial>$item</td>\n
<td WIDTH=25%><FONT SIZE=-1 face=Arial> $partNo</td>\n
<td WIDTH=50%><FONT SIZE=-1 face=Arial> $description</td>\n";
echo "<td WIDTH=5% align='center'>\n";
echo "<td WIDTH=10%> <input type='text' name='basket[$id]' value='0'
size='2'></td>\n";
echo "</tr>\n";
<tr>
<input type='submit' value='Add to basket'></form></td>\n";
</tr>
The table z350 contains columns headed
id (unique identifier numerical)
item
partNo
description
When some values have been entered in the quantity I submit.
*******************************************
The 'basket' page displays. I have used the
echo "<pre>";
print_r ($_POST['basket']);
echo "</pre>";
To display the contents of the posted array.
It is shown below how it prints out. The Key refers to a line entry (id) in
the database.
The right hand entry is a quantity input by the user on the previous page.
Array
(
[63] => 5
[64] => 0
[65] => 6
[66] => 25
[67] => 0
)
The basket page needs to pull these requsted rows (id) from the database.
I have tried various combinations of MySQL queries but can't seem to get the
data into a $query.
$query = "SELECT * FROM z350 WHERE id=\"{$basket[id]}\"";
$result = mysql_query($query)
or die ("Couldn't execute query.");
I beleive the state of play with the above is that the key is not being
looked at, its the value.
So how do I make the key into the values that will be used in the SQL query.
Ultimately my desire is to keep the Array in a session which will keep the
keys and as the users adds the 'id' and
the value (quantity ordered), but on request to view the basket the Key will
be used to get the partNo and description to display.
in a table (I feel confident I can do that part).
Thanks in antcipation
Stephen
Navigation:
[Reply to this message]
|