seeya Posted January 7, 2008 Share Posted January 7, 2008 can someone code a php code that is able to read from mysql database and then hide the shopping cart button and at the same time display 'out of stock' word. hope i explain it clearly. please let me know if i need to provide anything.. thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/ Share on other sites More sharing options...
redarrow Posted January 7, 2008 Share Posted January 7, 2008 <?php //database connection //select //while loop with $row if($row['stock']==1){ echo" In stock"; // with button... }else{ echo"Out of stock"; //no button } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432324 Share on other sites More sharing options...
seeya Posted January 7, 2008 Author Share Posted January 7, 2008 i am not sure where to put the code in, can u tell me where? thanks. config.php has mysql login (eg, $mysql_host etc) edit: wrong code Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432330 Share on other sites More sharing options...
redarrow Posted January 7, 2008 Share Posted January 7, 2008 MIGHT BE THIS LINE HAVE A LOOK M8 <td valign="top"bgcolor="#FFCCFF"><input type="text" name="iProductQty" size="2" maxlength="3" value="<?php echo $_SESSION['arrProductQty'][$key]; ?>" onBlur="chk_qty_wosp(this)"></td> Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432334 Share on other sites More sharing options...
seeya Posted January 7, 2008 Author Share Posted January 7, 2008 sorry. i have not any product display yet.. so sorry.. Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432348 Share on other sites More sharing options...
redarrow Posted January 7, 2008 Share Posted January 7, 2008 is it the line you want sorted or not mate....... Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432354 Share on other sites More sharing options...
seeya Posted January 7, 2008 Author Share Posted January 7, 2008 dont get wat u mean.. sorry mate Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-432550 Share on other sites More sharing options...
seeya Posted January 8, 2008 Author Share Posted January 8, 2008 i am so sorry mate.. i now then reliase that i have given the wrong code. <?php require_once("config.php"); require_once("header.php"); if (!isset($_POST['sCategory'])) { $_POST['sCategory'] = ""; } if (!isset($_POST['iStartRow'])) { $_POST['iStartRow'] = 0; } if (!isset($_POST['sProductSearch'])) { $_POST['sProductSearch'] = ""; } // Connecting, selecting database $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die('Could not connect: ' . mysql_error()); mysql_select_db($mysql_database) or die('Could not select database'); // Performing SQL query if (trim($_POST['sCategory']) <> "") { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product WHERE sCategory='" . trim($_POST['sCategory']) . "'"; } elseif (trim($_POST['sProductSearch']) <> "") { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product WHERE sPcode LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sName LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sProductDesc LIKE '%" . trim($_POST['sProductSearch']) . "%'"; } else { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product"; } $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $intProductCount = $row['iProductCount']; mysql_free_result($result); $query = "SELECT DISTINCT sCategory FROM tbl_product ORDER BY sCategory"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $strProductCatOptions = ""; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if (trim($_POST['sCategory']) == trim($row['sCategory'])) { $strProductCatOptions = $strProductCatOptions . "<option value=\"" . trim($row['sCategory']) . "\" selected>" . trim($row['sCategory']) . "</option>"; } else { $strProductCatOptions = $strProductCatOptions . "<option value=\"" . trim($row['sCategory']) . "\">" . trim($row['sCategory']) . "</option>"; } } mysql_free_result($result); if (trim($_POST['sCategory']) <> "") { $query = "SELECT * FROM tbl_product WHERE sCategory='" . trim($_POST['sCategory']) . "' ORDER BY sPcode LIMIT " . trim($_POST['iStartRow']) . ",3"; } elseif (trim($_POST['sProductSearch']) <> "") { $query = "SELECT * FROM tbl_product WHERE sPcode LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sName LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sProductDesc LIKE '%" . trim($_POST['sProductSearch']) . "%' ORDER BY sProductID LIMIT " . trim($_POST['iStartRow']) . ",3"; } else { $query = "SELECT * FROM tbl_product ORDER BY sPcode LIMIT " . trim($_POST['iStartRow']) . ",3"; } $result = mysql_query($query) or die('Query failed: ' . mysql_error()); ?> <style type="text/css"> <!-- body { background-image: url(background.jpg); } --> </style><tr> <td width="700" rowspan="2" valign="top" bgcolor="#FFCCFF"> <table width="699" border="1" cellpadding="3" cellspacing="3" bordercolor="#FFCCFF" bgcolor="#FFCCFF" id="About"> <td bgcolor="#FFCCFF"> <TABLE width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FFCCFF" bgcolor="#FFCCFF"> <TR> <TD> <form name="frmBrowseCategories" action="products.php" method="post"> <TABLE width="100%" border="0" cellpadding="2" cellspacing="0"> <TR> <TD align="center"> <font color="#000000"><font face="Trebuchet MS"><strong>Browse By Categories:</font></strong></fron> <select name="Category"> <option value="" selected><strong>Browse by all the categories</strong></option> <?php echo $strProductCatOptions ?> </select> <input type=image id="Go" src="go.jpg"> </TD> <TD align="left"> </TD> </TR> </TABLE> </form> <TR> <td> <?php if (trim($_POST['sProductSearch']) <> "") { echo "<br><b><font color=red>Search Results: " . $intProductCount . " products found with the word(s) '" . $_POST['sProductSearch'] . "'.</font></b>"; } ?> </td> </TR> </TD> </TR> </TABLE> <TABLE width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#FFCCFF" bgcolor="#FFCCFF"> <?php // Display 3 products at a time while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <form name=frmShoppingCart action=shoppingcart.php method=post> <input type=hidden name=sCartAction value="AddItem"> <input type=hidden name=sProductID value="<?php echo $row['sPcode']; ?>"> <input type=hidden name=sProductName value="<?php echo $row['sName']; ?>"> <input type=hidden name=dblUnitPrice value="<?php echo $row['sPrice']; ?>"> <tr> <td valign="middle"><div align="center"><img src="<?php echo $row['sPimage'];?>"></td></div> <td width="282" valign="top"><br /><font color="#3333ff"><strong><?php echo $row['sPcode']; ?></strong></font><br> <strong><font face="Jokerman"><font color="#FF00ff "><?php echo $row['sName']; ?></strong></font></font><br> <font color="#00000"><font face="Californian FB"><?php echo $row['sPdesc']; ?></font><br></font> <span class="style1"><strong><font color="#3333ff"><strong>Unit Price</strong>: <font color="#FF0000">SGD $<?php echo number_format($row['sPrice'],2); ?></font></span></td> <td width="127" valign="middle"><div align="center"> <input type=image id="Go" src="addtobasket.jpg" width="120" height="22"> </div></td> </tr> </form> <?php } ?> <tr> <td colspan="3"> <table width="100%" cellSpacing="2" cellPadding="0" align="center" border="0"> <tr> <?php // Next N-Interface - Previous/Next Links $iPrevious = $_POST['iStartRow'] - 3; if ($iPrevious >= 0) { echo "<form name=frmPrevLink action=products.php method=post><input type=hidden name=Category value=\"" . trim($_POST['sCategory']) . "\"><input type=hidden name=iStartRow value=" . trim($iPrevious) . "><td align=left><input type=image src=previous.gif border=0></td></form>"; } $iNext = $_POST['iStartRow'] + 3; if ($iNext < $intProductCount) { echo "<form name=frmNextLink action=products.php method=post><input type=hidden name=Category value=\"" . trim($_POST['sCategory']) . "\"><input type=hidden name=iStartRow value=" . trim($iNext) . "><td align=right><input type=image src=next.gif border=0></td></form>"; } ?> </tr> </table> </td> </tr> </TABLE> </td> </tr> </table> </td> <?php require_once("member_corners.php"); require_once("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433194 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 can someone code a php code that is able to read from mysql database and then hide the shopping cart button and at the same time display 'out of stock' word. hope i explain it clearly. please let me know if i need to provide anything.. thanks in advance! Uh which line is the shopping cart button? Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433204 Share on other sites More sharing options...
seeya Posted January 8, 2008 Author Share Posted January 8, 2008 can someone code a php code that is able to read from mysql database and then hide the shopping cart button and at the same time display 'out of stock' word. hope i explain it clearly. please let me know if i need to provide anything.. thanks in advance! Uh which line is the shopping cart button? here it is mate.. <input type=image id="Go" src="addtobasket.jpg" width="120" height="22"> Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433211 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 What about this? <?php require_once("config.php"); require_once("header.php"); if (!isset($_POST['sCategory'])) { $_POST['sCategory'] = ""; } if (!isset($_POST['iStartRow'])) { $_POST['iStartRow'] = 0; } if (!isset($_POST['sProductSearch'])) { $_POST['sProductSearch'] = ""; } // Connecting, selecting database $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die('Could not connect: ' . mysql_error()); mysql_select_db($mysql_database) or die('Could not select database'); // Performing SQL query if (trim($_POST['sCategory']) <> "") { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product WHERE sCategory='" . trim($_POST['sCategory']) . "'"; } elseif (trim($_POST['sProductSearch']) <> "") { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product WHERE sPcode LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sName LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sProductDesc LIKE '%" . trim($_POST['sProductSearch']) . "%'"; } else { $query = "SELECT COUNT(*) AS iProductCount FROM tbl_product"; } $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $intProductCount = $row['iProductCount']; mysql_free_result($result); $query = "SELECT DISTINCT sCategory FROM tbl_product ORDER BY sCategory"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $strProductCatOptions = ""; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if (trim($_POST['sCategory']) == trim($row['sCategory'])) { $strProductCatOptions = $strProductCatOptions . "<option value=\"" . trim($row['sCategory']) . "\" selected>" . trim($row['sCategory']) . "</option>"; } else { $strProductCatOptions = $strProductCatOptions . "<option value=\"" . trim($row['sCategory']) . "\">" . trim($row['sCategory']) . "</option>"; } } mysql_free_result($result); if (trim($_POST['sCategory']) <> "") { $query = "SELECT * FROM tbl_product WHERE sCategory='" . trim($_POST['sCategory']) . "' ORDER BY sPcode LIMIT " . trim($_POST['iStartRow']) . ",3"; } elseif (trim($_POST['sProductSearch']) <> "") { $query = "SELECT * FROM tbl_product WHERE sPcode LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sName LIKE '%" . trim($_POST['sProductSearch']) . "%' OR sProductDesc LIKE '%" . trim($_POST['sProductSearch']) . "%' ORDER BY sProductID LIMIT " . trim($_POST['iStartRow']) . ",3"; } else { $query = "SELECT * FROM tbl_product ORDER BY sPcode LIMIT " . trim($_POST['iStartRow']) . ",3"; } $result = mysql_query($query) or die('Query failed: ' . mysql_error()); ?> <style type="text/css"> <!-- body { background-image: url(background.jpg); } --> </style><tr> <td width="700" rowspan="2" valign="top" bgcolor="#FFCCFF"> <table width="699" border="1" cellpadding="3" cellspacing="3" bordercolor="#FFCCFF" bgcolor="#FFCCFF" id="About"> <td bgcolor="#FFCCFF"> <TABLE width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FFCCFF" bgcolor="#FFCCFF"> <TR> <TD> <form name="frmBrowseCategories" action="products.php" method="post"> <TABLE width="100%" border="0" cellpadding="2" cellspacing="0"> <TR> <TD align="center"> <font color="#000000"><font face="Trebuchet MS"><strong>Browse By Categories:</font></strong></fron> <select name="Category"> <option value="" selected><strong>Browse by all the categories</strong></option> <?php echo $strProductCatOptions ?> </select> <input type=image id="Go" src="go.jpg"> </TD> <TD align="left"> </TD> </TR> </TABLE> </form> <TR> <td> <?php if (trim($_POST['sProductSearch']) <> "") { echo "<br><b><font color=red>Search Results: " . $intProductCount . " products found with the word(s) '" . $_POST['sProductSearch'] . "'.</font></b>"; } ?> </td> </TR> </TD> </TR> </TABLE> <TABLE width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#FFCCFF" bgcolor="#FFCCFF"> <?php // Display 3 products at a time if (!$result||(mysql_num_rows($result)<1)) echo "<tr><td><span style='color:red;font-weight:bold;'>Out of stock</span></td></tr>"; else { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <form name=frmShoppingCart action=shoppingcart.php method=post> <input type=hidden name=sCartAction value="AddItem"> <input type=hidden name=sProductID value="<?php echo $row['sPcode']; ?>"> <input type=hidden name=sProductName value="<?php echo $row['sName']; ?>"> <input type=hidden name=dblUnitPrice value="<?php echo $row['sPrice']; ?>"> <tr> <td valign="middle"><div align="center"><img src="<?php echo $row['sPimage'];?>"></td></div> <td width="282" valign="top"><br /><font color="#3333ff"><strong><?php echo $row['sPcode']; ?></strong></font><br> <strong><font face="Jokerman"><font color="#FF00ff "><?php echo $row['sName']; ?></strong></font></font><br> <font color="#00000"><font face="Californian FB"><?php echo $row['sPdesc']; ?></font><br></font> <span class="style1"><strong><font color="#3333ff"><strong>Unit Price</strong>: <font color="#FF0000">SGD $<?php echo number_format($row['sPrice'],2); ?></font></span></td> <td width="127" valign="middle"><div align="center"> <input type=image id="Go" src="addtobasket.jpg" width="120" height="22"> </div></td> </tr> </form> <?php } ?> <tr> <td colspan="3"> <table width="100%" cellSpacing="2" cellPadding="0" align="center" border="0"> <tr> <?php // Next N-Interface - Previous/Next Links $iPrevious = $_POST['iStartRow'] - 3; if ($iPrevious >= 0) { echo "<form name=frmPrevLink action=products.php method=post><input type=hidden name=Category value=\"" . trim($_POST['sCategory']) . "\"><input type=hidden name=iStartRow value=" . trim($iPrevious) . "><td align=left><input type=image src=previous.gif border=0></td></form>"; } $iNext = $_POST['iStartRow'] + 3; if ($iNext < $intProductCount) { echo "<form name=frmNextLink action=products.php method=post><input type=hidden name=Category value=\"" . trim($_POST['sCategory']) . "\"><input type=hidden name=iStartRow value=" . trim($iNext) . "><td align=right><input type=image src=next.gif border=0></td></form>"; } ?> </tr> </table> </td> </tr> <?php } ?> </TABLE> </td> </tr> </table> </td> <?php require_once("member_corners.php"); require_once("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433215 Share on other sites More sharing options...
seeya Posted January 8, 2008 Author Share Posted January 8, 2008 is there any difference with product quantity being display? cause i have done some edit to code i posted. Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433224 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 Try it. It couldn't hurt. I just hide the part if the are no results. Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433232 Share on other sites More sharing options...
seeya Posted January 10, 2008 Author Share Posted January 10, 2008 tried it. doesnt work. this is a shopping cart page i am working for my sch project. i also need a php code that is able to minus the amount of product the customer has order. but that will come later.. Quote Link to comment https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-435140 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.