[thelist] reworded MySQL query insert and back again

Andrew Maynes andrew at humanbehaviour.co.uk
Mon Feb 10 12:39:01 CST 2003


Hi All

I have a table that holds all the records for items.  Each item has a colour and
a size and could have more than one colour and size.  So tables have been
created to keep records for each items colour and size.  ref_colours ref_size
hold the names and item_colour item_size hold item - colour item -size
relationship.

When an item is displayed its respective colours and sizes are pulled using this
query:

function showSize($item_id)
{
 $query="select ref_size.* from item_size ,ref_size where
ref_size.size_id=item_size.size_id and item_size.item_id=$item_id";
$rs=mysql_query($query);
	if(!$rs)
	{
	echo "Error while exeuting the query";
	}
	else
	{
	while($row=mysql_fetch_array($rs))
		{
		$size_id=$row['size_id'];
		$size=$row['size'];
		echo "<option value=\"$size_id\">$size</option>";
		}
	}
}

when this item is selected by the visitor the item is held in a temporary table.
The colour and size are held in this table as size and colour but as the value
not as the name, so when called back from the temp file I am getting the value
not the name ie: 1 instead of blue.

I guess I can do one f two things: I create a query to convert the value back to
the name or the insert instread of being the value is the actual colour and
size, unfortunately my head is starting to spin and will explode at any minute
now !

oh this is the insert value if some can just spot an obvious error so that I can
inmsert the name instead of the value?

echo "<SELECT name=\"cName\" value=\"$cName\">";
showColor($II);
echo "</SELECT> ";

thank you

Andrew




More information about the thelist mailing list