0

Hello the valuies are not echoing when I am out side the loop

<?php 
            if(isset($_GET["catid"])) {
                $catid = $_GET["catid"];
                $query_cat = mysqli_query($connection, "SELECT * FROM category WHERE cat_name='$catid'");
                while($row = mysqli_fetch_assoc($query_cat)) {
                    $h1       = $row["h1"];
                    $h2       = $row["h2"];
                    $span     = $row["span"];
                    $catslide = $row["cat_slider"];
                    $ct_name  = $row["cat_name"];
                }
        ?>
            <div class="col-sm-6">
                <h1><?php echo $h1; ?><span class="banner-head"><br><?php echo $h2; ?></span></h1>
                <p><?php echo $span; ?></p>
                <!--<button class="btn btn-default purple-btn" type="submit">downloads</button>-->
            </div>
            <div class="col-sm-6 banner-img">
                <img src="admin/img/postslider/<?php echo $catslide; ?>" alt="">
            </div>
        <?php } else { ?>
            <div class="col-sm-6">
                <h1>Download<span class="banner-head"><br><FREE IPHONE AND <br />ANDROID RINGTONES</span></h1>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry</p>
                <!--<button class="btn btn-default purple-btn" type="submit">downloads</button>-->
            </div>
            <div class="col-sm-6 banner-img">
                <img src="images/mario-game.png" alt="">
            </div>
        <?php } ?>
4
Contributors
6
Replies
21
Views
2 Years
Discussion Span
Last Post by diafol
0

you close ur while loop too early, try this

<?php 

                while($row = mysqli_fetch_assoc($query_cat)) {
                    $h1       = $row["h1"];
                    $h2       = $row["h2"];
                    $span     = $row["span"];
                    $catslide = $row["cat_slider"];
                    $ct_name  = $row["cat_name"];
             //}   dont close here
        ?>
        ...
        <?php }} else { ?>//close here
0

when I am doing this the divs are looping thought which I dotn want it to be done

0

First of all, had you check your database if last data that matching the condition is having values?
As from what I can see from your code, for every rows of data the mysqli_fetch_assoc fetch, you will replace your $h1,$h2 etc with the newly fetched data. So, if the last row of data is having empty data, then all the variable will be set to empty.

0

This makes v. little sense to me.

How many rows are you retrieving? If only one, then you don't need a loop - and I'd add 'LIMIT 1' to the SQL.
If more, then you're overwriting your vars on every iteration of the loop.

Either way, it looks wrong.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.