PDA

View Full Version : add to basket



sova
November 26th, 2006, 10:20 AM
the code is a bit messy!!
but what i'm trying to do is how to get each button that is being created for each image in the database to get the same value as the image has.. so that when i click on each button the 'artikelNr' is retrieved and then inserted into a database (I haven't come that far yet)
I can get the right number if i click on the image, but not on the button..
My php scills arent to impressive so I could really do with some help!

while($row = mysql_fetch_array($result))
{
$thumb = $row['thumbnail'];
$nr = $row['artikelNr'];
echo ('<a href="' . $_SERVER['PHP_SELF'] . '?image=' . $thumb . '&artikelNr=' . $nr . '"><img src="'. $thumb. '" border="0"></a><br>');
//echo "<input type='hidden' value='$nr' name='myhidden'>";
echo "<input type='submit' value='add' name='mybutton'><br>";

}

if (isset($_POST['mybutton']))
{
$productid= $_POST['myhidden'];
echo $productid;
//echo $new_id ;
//echo $nr;
}



greatful for any help :-)

CriTiCeRz
November 26th, 2006, 01:35 PM
Ok your code is very confusing and I don't seem to get what you are trying to do... please explain a bit more clear.

sova
November 26th, 2006, 03:16 PM
I'm basically displaying all the images i have in a database on a page, with each seperate images i need a button that has the same productId as the image so that i know which one the user has selected. then all the selected items goes in a mail and is beeing sent off. but i dont know how to get a seperate value for each button..
is this clearer?

so looping through the database and adding a button to each pic.
while($row = mysql_fetch_array($result))
{
$thumb = $row['thumbnail'];
$nr = $row['artikelNr'];
echo ('<a href="' . $_SERVER['PHP_SELF'].'?image='.$thumb.'&artikelNr='.$nr.'"><img src="'. $thumb.'" border="0"></a><br>');
echo "<input type='submit' value='add' name='mybutton'><br>";
}

if submit is klicked

if (isset($_POST['mybutton']))
{
echo something???
}

CriTiCeRz
November 26th, 2006, 04:19 PM
while($row = mysql_fetch_array($result))
{
$thumb = $row['thumbnail'];
$nr = $row['artikelNr'];

echo ('<a href="' . $_SERVER['PHP_SELF'].'?image='.$thumb.'&artikelNr='.$nr.'"><img src="'. $thumb.'" border="0"></a><br>');
echo "<input type='hidden' value='{$nr}' name='myhidden'>";
echo "<input type='submit' value='add' name='mybutton'><br>";
}

if (isset($_POST['mybutton'])) {
echo "You have selected {$_POST['myhidden']}."
}


I'm not sure what you want to do with $nr though.... Is that it?

sova
November 27th, 2006, 02:45 AM
Thank you.. I'm gonna try it out. I need $nr to store that value in a database. if i klick on one of the images, this value 'artikelNr' shows, i need the same for each button... how else do i know which button goes with what image?





while($row = mysql_fetch_array($result))
{
$thumb = $row['thumbnail'];
$nr = $row['artikelNr'];

echo ('<a href="' . $_SERVER['PHP_SELF'].'?image='.$thumb.'&artikelNr='.$nr.'"><img src="'. $thumb.'" border="0"></a><br>');
echo "<input type='hidden' value='{$nr}' name='myhidden'>";
echo "<input type='submit' value='add' name='mybutton'><br>";
}

if (isset($_POST['mybutton'])) {
echo "You have selected {$_POST['myhidden']}."
}


I'm not sure what you want to do with $nr though.... Is that it?