Tangled Posted September 25, 2014 Posted September 25, 2014 Can someone tell me how to add images to my items in the shops? Quote
Script47 Posted September 25, 2014 Posted September 25, 2014 I'm sure [MENTION=65371]sniko[/MENTION] can help? :p Joking. Assuming you've already inserted the image in to the database you'd output the image using a while(); loop like normal and put it all in a table and the images is put next to the item. Back when I was making a game I used the following code. Use it and adapt it to work in your situation. while($res = $selectHangerInfo->fetch(PDO::FETCH_OBJ)) { $b64Src = "data:image/jpeg;base64," . base64_encode($res->Display_Image); echo '<tr><td style="float: left; text-align: left;"><img src="'.$b64Src.'" /></td>'; echo '<td><strong>Hanger Type: </strong>'.$res->Name.'<br/><strong>Cost: </strong>'.$selectCurrencyRes->Currency_Symbol.$functions->formatNumber($res->Cost).'<br/><strong>Construction Time: </strong>'.$res->Construction_Time_Minutes.' Minutes<br/><strong>Holding Capacity (Planes):</strong> '.$res->Plane_Holding.'</strong></td>'; echo '<td><a href="index.php?module=hangerShop&hangerID='.$res->ID.'&buy=true">Buy '.$res->Name.'</a></td>'; echo '</tr>'; } Quote
Tangled Posted September 25, 2014 Author Posted September 25, 2014 I'm sure [MENTION=65371]sniko[/MENTION] can help? :p Joking. Assuming you've already inserted the image in to the database you'd output the image using a while(); loop like normal and put it all in a table and the images is put next to the item. Back when I was making a game I used the following code. Use it and adapt it to work in your situation. while($res = $selectHangerInfo->fetch(PDO::FETCH_OBJ)) { $b64Src = "data:image/jpeg;base64," . base64_encode($res->Display_Image); echo '<tr><td style="float: left; text-align: left;"><img src="'.$b64Src.'" /></td>'; echo '<td><strong>Hanger Type: </strong>'.$res->Name.'<br/><strong>Cost: </strong>'.$selectCurrencyRes->Currency_Symbol.$functions->formatNumber($res->Cost).'<br/><strong>Construction Time: </strong>'.$res->Construction_Time_Minutes.' Minutes<br/><strong>Holding Capacity (Planes):</strong> '.$res->Plane_Holding.'</strong></td>'; echo '<td><a href="index.php?module=hangerShop&hangerID='.$res->ID.'&buy=true">Buy '.$res->Name.'</a></td>'; echo '</tr>'; } lol there's no slot in the database for an image... I need help getting that in. that's where I started. sigh I know go study some more .... Quote
Script47 Posted September 25, 2014 Posted September 25, 2014 lol there's no slot in the database for an image... I need help getting that in. that's where I started. sigh I know go study some more .... Read this, it might help. Quote
G7470 Posted September 25, 2014 Posted September 25, 2014 (edited) Depends on how you would want to do it and structure it, but usually images are placed under a special images directory you have in your file structure. Then, in the database, you add a column to place the image file itself for your items (whatever it may happen to be called). After that is done, the coding part is not too bad. Again, all depends on how you would want to do it. You can either create a function like I did to accomplish this: show_image($image_file_name, $item_id); and build a function in a classes file like so: function show_image($image, $id) { return "<a href='javascript:;' onclick=\"javascript:window.open( 'description.php?id=".$id."', '60', 'left = 20, top = 20, width = 400, height = 440, toolbar = 0, resizable = 0, scrollbars=0, location=0, menubar=0' );\"><img src='".$image."' width='100' height='100' style='border: 1px solid #000000'></a>"; } or you can do something like Script did. They all basically do something similar. ~G7470 Edited September 25, 2014 by G7470 Quote
Tangled Posted September 25, 2014 Author Posted September 25, 2014 Depends on how you would want to do it and structure it, but usually images are placed under a special images directory you have in your file structure. Then, in the database, you add a column to place the image file itself for your items (whatever it may happen to be called).\ After that is done, the coding part is not too bad. Again, all depends on how you would want to do it. You can either create a function like I did to accomplish this: show_image($image_file_name, $item_id); and build a function in a classes file like so: function show_image($image, $id) { return "<a href='javascript:;' onclick=\"javascript:window.open( 'description.php?id=".$id."', '60', 'left = 20, top = 20, width = 400, height = 440, toolbar = 0, resizable = 0, scrollbars=0, location=0, menubar=0' );\"><img src='".$image."' width='100' height='100' style='border: 1px solid #000000'></a>"; } or you can do something like Script did. They all basically do something similar. ~G7470 Thank you both for your imput and advice...I am such a noob I'm reading what script suggested. I am doing my best to learn how to do this haha dictionary time! Quote
Script47 Posted September 25, 2014 Posted September 25, 2014 Personally I would suggest [MENTION=70485]G7470[/MENTION] method although a little bit more confusing it will be worth it in the long run as the method I suggested is a quick method but it makes the DB huge depending on the amount of images you have. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.