<div id="rightContent">
                    <div id="contentBox" class="right">
                        <div id="contentPadding" style="padding: 10px 10px 5px 10px;">
                            <div id="slickTitle" class="hotelStat">
                            <?php $userReg = mysql_num_rows(mysql_query("SELECT * FROM users")); ?>
                                <?php echo $userReg; ?> Registered Users
                            </div>
                            <div id="slickTitle" class="hotelStat">
                            <?php $totalFurni = mysql_num_rows(mysql_query("SELECT * FROM furniture")); ?>
                                <?php echo $totalFurni; ?> Total Furniture
                            </div>
                            <div id="slickTitle" class="hotelStat">
                            <?php $totalRooms = mysql_num_rows(mysql_query("SELECT * FROM rooms")); ?>
                                <?php echo $totalRooms; ?> Rooms Created
                            </div><br clear="all" />
                        </div>
                    </div>
                </div>

Was wondering is there a better way of doing the above to select the total amount id's per table to gather statistics ? Also wondering how can I make it display things like this?

35k instead of 35000 ?

Recommended Answers

All 3 Replies

SELECT COUNT(*) AS count FROM users

This query will get only one row, you can use mysql_fetch_assoc to get it. Performance will be better. You can even join the three queries into one for better performance (or use a VIEW).

<?php $userReg = mysql_num_rows(mysql_query("SELECT COUNT(*) AS count FROM users")); ?>

Only returns 1 user could you help me with the whole code? I suck personally at coding. That is why I'm asking for help :(

Ended up with the following any help with cleaning it up?

                    <div id="rightContent">
                    <div id="contentBox" class="right">
                        <div id="contentPadding" style="padding: 10px 10px 5px 10px;">
                            <div id="slickTitle" class="hotelStat">
                            <?php $result = mysql_query("select count(1) FROM users");
                                $row = mysql_fetch_array($result);
                                $totalUsers = $row[0];
                                echo " " . $totalUsers; ?> Registered Users
                            </div>

                            <div id="slickTitle" class="hotelStat">
                            <?php $result = mysql_query("select count(1) FROM furniture");
                                $row = mysql_fetch_array($result);
                                $totalFurniture = $row[0];
                                echo " " . $totalFurniture; ?> Total Furniture  
                            </div>

                            <div id="slickTitle" class="hotelStat">
                            <?php $result = mysql_query("select count(1) FROM rooms");
                                $row = mysql_fetch_array($result);
                                $totalRooms = $row[0];
                                echo " " . $totalRooms; ?> Rooms Created
                            </div><br clear="all" />
                            </div>
                        </div>
                    </div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.