twilitegxa Posted July 10, 2009 Share Posted July 10, 2009 Is there a way in the following script to set a size for the image that is to be displayed from the database so that all images displayed will be the same size? <?php session_start(); //connect to database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $display_block = "<h1>My Store - Item Detail</h1>"; //validate item $get_item = "select c.cat_title, si.item_title, si.item_price, si.item_desc, si.item_image from store_items as si left join store_categories as c on c.id = si.cat_id where si.id = $_GET[item_id]"; $get_item_res = mysql_query($get_item) or die(mysql_error()); $item_id = $_GET['item_id']; if (mysql_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info $cat_title = strtoupper(stripslashes( mysql_result($get_item_res,0,'cat_title'))); $item_title = stripslashes(mysql_result($get_item_res,0, 'item_title')); $item_price = mysql_result($get_item_res,0, 'item_price'); $item_desc = stripslashes(mysql_result($get_item_res,0, 'item_desc')); $item_image = mysql_result($get_item_res,0, 'item_image'); //make breadcrumb trail $display_block .= "<p><strong>You are viewing:</em><br> <a href=\"seestore.php?cat_id\">$cat_title</a> > $item_title</strong></p> <table cellpadding=3 cellspacing=3> <tr> <td valign=middle align=center><img src=\"$item_image\"></td> <td valign=middle><p><strong>Description:</strong><br>$item_desc</p> <p><strong>Price:</strong> \$$item_price</p> <form method=post action=\"addtocart.php\">"; //get colors $get_colors = "select item_color from store_item_color where item_id = $item_id order by item_color"; $get_colors_res = mysql_query($get_colors) or die(mysql_error()); if (mysql_num_rows($get_colors_res) > 0) { $display_block .= "<p><strong>Available Colors:</strong> <select name=\"sel_item_color\">"; while ($colors = mysql_fetch_array($get_colors_res)) { $item_color = $colors['item_color']; $display_block .= "<option value=\"$item_color\">$item_color</option>"; } $display_block .= "</select>"; } //get sizes $get_sizes = "select item_size from store_item_size where item_id = $item_id order by item_size"; $get_sizes_res = mysql_query($get_sizes) or die(mysql_error()); if (mysql_num_rows($get_sizes_res) > 0) { $display_block .= "<p><strong>Available Sizes:</strong> <select name=\"sel_item_size\">"; while ($sizes = mysql_fetch_array($get_sizes_res)) { $item_size = $sizes['item_size']; $display_block .= " <option value=\"$item_size\">$item_size</option>"; } $display_block .= "</select>"; } $display_block .= " <p><strong>Select Quantity:</strong> <select name=\"sel_item_qty\">"; for($i=1; $i<11; $i++) { $display_block .= "<option value=\"$i\">$i</option>"; } $display_block .= " </select> <input type=\"hidden\" name=\"sel_item_id\" value=\"$_GET[item_id]\"> <p><input type=\"submit\" name=\"submit\" value=\"Add To Cart\"></p> </form> </td> </tr> </table>"; } ?> <html> <head> <title>My Store</title> </head> <body> <?php print $display_block; ?> </body> </html> Here is the block of code that sets the variable for the items, so I'm assuming i can set it here, but I'm not sure exactly how: //valid item, get info $cat_title = strtoupper(stripslashes( mysql_result($get_item_res,0,'cat_title'))); $item_title = stripslashes(mysql_result($get_item_res,0, 'item_title')); $item_price = mysql_result($get_item_res,0, 'item_price'); $item_desc = stripslashes(mysql_result($get_item_res,0, 'item_desc')); $item_image = mysql_result($get_item_res,0, 'item_image'); Can anyone help me out here? I'd also like to set some spacing between the image and the text that runs alongside it, so I'm guessing this would be padding? Quote Link to comment https://forums.phpfreaks.com/topic/165538-solved-setting-image-size-and-padding/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 Is there a way in the following script to set a size for the image that is to be displayed from the database so that all images displayed will be the same size? 1) resize the image using a resizing script 2) use the width and height attributes of the img element Can anyone help me out here? I'd also like to set some spacing between the image and the text that runs alongside it, so I'm guessing this would be padding? Technically we can't help you on this one as this is html/css related and we are talking php here It's not padding but margin. Add a style attribute with the margin defined (like so: <img style="margin: .." ..>) If this doesn't work you may need to modify the display setting (<img style="margin: ..; display: block" ..>. Quote Link to comment https://forums.phpfreaks.com/topic/165538-solved-setting-image-size-and-padding/#findComment-873135 Share on other sites More sharing options...
twilitegxa Posted July 10, 2009 Author Share Posted July 10, 2009 Well, I posted it here because I need to apply these attributes to the php section of the code I'm assuming. Where would I add the style attribute? Quote Link to comment https://forums.phpfreaks.com/topic/165538-solved-setting-image-size-and-padding/#findComment-873163 Share on other sites More sharing options...
twilitegxa Posted July 10, 2009 Author Share Posted July 10, 2009 Wait, I figured it out. Thanks for the help! It was on this line: <td valign=middle align=center><img src=\"$item_image\" style=\"margin: 100; display: block;\"></td> Quote Link to comment https://forums.phpfreaks.com/topic/165538-solved-setting-image-size-and-padding/#findComment-873168 Share on other sites More sharing options...
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.