Jump to content

Recommended Posts

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433194
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433204
Share on other sites

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">

Link to comment
https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433211
Share on other sites

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/84806-out-of-stock-php-code/#findComment-433215
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.