Hey Stack Overflowians,
I have a beginners problem for PHP which I’ve not had too much luck searching for so I thought I’d ask.
The problem is a slight alteration of my past post which you can find via my profile (since it’s my only one) where I’m trying to print data out of a database in a loop but also trying to wrap HTML around it.
In my example here, I’m trying to print the test line in my database which happens to be a style code of KO278 so that as well as printing the style code, it also prints it inside of an img src so the img of that item is printed as well but I’m not having much luck so far.
I thought perhaps some concatenation might work since I haven’t used it much but my attempt at it didn’t give me much of a result but perhaps my formatting could be off?
Anyway, I’m hoping you could aim me in the right direction.
Thanks!
Also, on a sidenote, I was thinking about if it would be possible for a small image of each colour (jpgs as they are more like patterns) to appear in place of the word of the colour but I don’t see how I could link that up.
Some products have both mixed colours (so different jpgs of them crossing over) or up to 8 colours so I wouldn’t know how to account for that much variability short of having a heap of fields in my database which doesn’t seem very efficient. It’s not that important but it’d be nice if anyone has any suggestions on how I might go about this?
<?php
$sql = "SELECT * FROM mc16koruproducts where collection = 'womens' order by ref";
$result = pg_exec($sql);
$nrows = pg_numrows($result);
#print $nrows;
$items = pg_fetch_all($result);
#print_r($items);
$type = '';
for ($i=0; $i<$nrows; $i++) {
if($items[$i]['type']!=$type)
{
print "<h2>";
print $items[$i]['type'];
print "</h2>";
$city = $items[$i]['city'];
}
print "<div id='info-holder'>";
print "<div id='img'>";
print "<img src='products/";
print $items[$i]['style'];
print ".jpg />";
print "</div>";
print "<div id='style'>";
print "Style ";
print $items[$i]['style'];
print "</div>";
print "<div id='desc'>";
print $items[$i]['desc'];
print "</div>";
print "<div id='size'>";
print "Sizes: ";
print $items[$i]['size'];
print "</div>";
print "<div id='colour'>";
print "Colours Available: ";
print $items[$i]['colour'];
print "</div>";
print "<br />";
print "<br />";
print "</div>";
?>
I think the problem might be that you’re missing a closing single quote after .jpg
Should be
I hope that helps. If not just let me know and I’ll dig deeper.