Sold out?

Discussion in 'Customization & add-ons' started by 123Marketing, Jan 14, 2015.

  1. 123Marketing

    123Marketing Member

    Joined:
    Jun 4, 2005
    Messages:
    138
    I want to have my own webpage (using PHP) display a conditional link - like this:

    If product id 3 is disabled, display:

    Sorry, this product is sold out - check back later.

    If product id 3 is enabled, display:

    Click here to order...

    Any ideas for this coding?

    Pretty simple, yes?
  2. 123Marketing

    123Marketing Member

    Joined:
    Jun 4, 2005
    Messages:
    138
  3. 123Marketing

    123Marketing Member

    Joined:
    Jun 4, 2005
    Messages:
    138
    I am surprised that this has not been replied to... is it too hard?
  4. edward_shephard

    edward_shephard aMember Pro Customer

    Joined:
    Aug 22, 2014
    Messages:
    41
    There may be a clever API way of doing it otherwise a manual thing could be:

    PHP:
    <?php

    $servername 
    "localhost";
    $username "db_username";
    $password "db_password";
    $dbname "database_name";

    // Create connection
    $conn = new mysqli($servername$username$password$dbname);
    // Check connection
    if ($conn->connect_error) {
        die(
    "Connection failed: " $conn->connect_error);
    }

    $sql "SELECT is_disabled FROM am_product WHERE product_id = '3'";
    $result $conn->query($sql);

    if (
    $result->num_rows == 1) {
        while(
    $row $result->fetch_assoc()) {
            if (
    $row["is_disabled"] == 0) {
                echo 
    "<a href='http://www.yoursite.org.uk/yourfile.php' >Click here to order...</a>";
            } else {
                echo 
    "Sorry, this product is sold out - check back later.";
            }
        }
    }
    $conn->close();
    ?>
    I haven't tried it so it may need a bit of debugging.
  5. 123Marketing

    123Marketing Member

    Joined:
    Jun 4, 2005
    Messages:
    138
    Excellent... works PERFECT.

    Thank you so much!

Share This Page