Jump to content

Adding Values to variables


bullbreed

Recommended Posts

HI Guys

 

I have some serialised data in my database related to the colour of a product. The data is actually a link to an image of a coloured square 22px x 22px representing a colour. In order to unserialise it and I used the following code;

 

<?php

$sql = "SELECT * FROM `products` WHERE `prod_name` = '".$_GET['nid']."' limit 1 ";
$query = mysql_query($sql) or die(mysql_error());
        
                if (mysql_num_rows($query) > 0) {
        
                        while ($row = mysql_fetch_assoc($query)){
                        $colours = $row['prod_colours'];
                        $colours = stripslashes($colours); 
                        $colours = unserialize($colours);
                        $itemcount = count($colours);
                                for ($i=0;$i<$itemcount;$i++) {
        
?>      
        <div class="colours"><a href="productdesign.php?nid=<?php echo $row['prod_name']; ?>&colid="<?php echo $row['prod_colours']; ?> >
	<?php echo '<img src="' .$colours[$i]. '">'; ?></a></div>
        
<?php 
                                }
                        }
                }
?>

 

But when the colour is selected I need a nedw image to appear on screen which will be the product in the required colour.

 

How do I add a value to the coloured square so when it is clicked I can call it as 'colid', meaning the page will be;

prodtype.php?nid=value&colid=value associated with square image

 

I hope I have explained ok.

Link to comment
https://forums.phpfreaks.com/topic/195336-adding-values-to-variables/
Share on other sites

The following code is correct for your link.

<div class="colours"><a href="productdesign.php?nid=<?php echo $row['prod_name']; ?>&colid="<?php echo $row['prod_colours']; ?> >

However the quote before this bit here <?php echo $row['prod_colours']; ? should be after it, eg

<div class="colours"><a href="productdesign.php?nid=<?php echo $row['prod_name']; ?>&colid=<?php echo $row['prod_colours']; ?>" >

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.