samedi 28 septembre 2019

Turn this into an if / else statement

When an item is chosen on my site, it opens a details page. This is the top of the details page above the html tags:

<?php require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$recordID = $_GET['recordID'];
$query_Master_details = "SELECT * FROM Master_List WHERE Master_List.Master_Id = $recordID";
$Master_details = mysqli_query($conn, $query_Master_details) or die(mysqli_error());
$row_Master_details = mysqli_fetch_assoc($Master_details);
$totalRows_Master_details = mysqli_num_rows($Master_details);
?>

This is the code that makes the body of the page:

<div class="container2">
    <div class="category"><h2><?php echo $row_Master_details['Name']; ?></h2></div>
    <p><?php echo $row_Master_details['Name']; ?></p>
    <p><img src="img/<?php echo $row_Master_details['Img']; ?>" /></p>
    <p><?php echo $row_Master_details['Code']; ?></p>
    <p><?php echo $row_Master_details['Length']; ?> Characters</p>
    <?php
    mysqli_free_result($Master_details);
    ?>
<!-- end .container2 --></div>

What I would like to do is create an if/else statement that will look at the Style_ID of the selected item and determine if the number is > 3. If it is, I want it to choose an item that has a Style_Id of 1, 2, or 3 and the same Length as the item chosen and return a random row in the layout above, skip a few lines and then display the information for the selected item in the layout above. Else if it is < or = 3, then I need it to just display as above.

I have tried using:

    <?php
    If (Style_ID > 3) {
        echo 'Test';
    }Else {
    <div class="category"><h2><?php echo $row_Master_details['Name']; ?></h2></div>
    <p><?php echo $row_Master_details['Name']; ?></p>
    <p><img src="img/<?php echo $row_Master_details['Img']; ?>" /></p>
    <p><?php echo $row_Master_details['Code']; ?></p>
    <p><?php echo $row_Master_details['Length']; ?> Characters</p>
    }
    ?>
    <?php
    mysqli_free_result($Master_details);
    ?>

But it doesn't work and has syntax errors. How can I create this if/else statement?

Note: I would appreciate being able to get one setup for all of it, but if not just fixing this part would be a big help right now.

Aucun commentaire:

Enregistrer un commentaire