pdo fetch with if command help?

Status
Not open for further replies.

griimnak

You're a slave to the money then you die
Jul 20, 2013
956
797
So I'm working on something right now, I've been looking for a solution for quite some time, kinda new to pdo.
So basicaly i have a table here:
GmenLcc.png

and I'm trying to make it so when i maint = 0 there will be a green check on the site (as in, maint = enabled)
Twclx7m.png

but my code is not working, not sure why?
Code:
<?php
                    $query = dbConnect()->prepare("SELECT maintenance FROM gweb_settings");
                    $query->execute();
                    $res = $query->fetchAll(PDO::FETCH_COLUMN);

                    if($res == 1){
                        echo "<li class='security off last'><span class='value on-off'>Low</span>maint";
                        echo "<div class='tooltip'>";
                        echo "Maintenance on";
                        echo "</div></li>";

                        }else{
                        echo "<li class='wifi on'><span class='value on-off'>On</span>maint";
                        echo "<div class='tooltip'>";
                        echo "Maintenance off";
                        echo "</div></li>";

                        }
                ?>
Thanks in the advance, i have no idea what the issue is, i've tried alot of methods *shrugs*
 
I know it must be something with the query, maybe i'm not supposed to use fetchall :confused:
 

griimnak

You're a slave to the money then you die
Jul 20, 2013
956
797
In this instance, since you're only fetching a single row, you should probably just use 'fetch'.
Thanks for the response, and ah i already fond out the issue, now i'm all set :)

disabled maintenance:
dQbLNPc.png


enabled maintenance:
bTEPniy.png


code:
Code:
<?php
                      $query = dbConnect()->prepare("SELECT * FROM gweb_settings");
                        $query->execute();
                     $status = $query->fetchAll();

                    foreach( $status as $row) {
                  
                        $onlinestat = $row['maintenance'];
        }
                    if($onlinestat == '1'){
                        echo "<li class='security off last'><span class='value on-off'>Low</span>Site: offline";
                        echo "<div class='tooltip'>";
                        echo "Maintenance: ENABLED";
                        echo "</div></li>";

                        }else{
                        echo "<li class='wifi on'><span class='value on-off'>On</span>Site: online";
                        echo "<div class='tooltip'>";
                        echo "Maintenance: DISABLED";
                        echo "</div></li>";

                        }
                ?>
 

Singlish

New Member
Apr 23, 2012
8
2
Glad you worked it out!

If it's simply for a single row, I wouldn't fetchall so there's no need to iterate just for one entry. When you use fetchall, you'll need to iterate through each result.

Have fun with your system!
 
Status
Not open for further replies.

Users who are viewing this thread

Top