0

Hi,

I make two tables, one of them named operator, used to enter the mobile line operator name and the other one name directory, used to enter name, surname, mobile number and the id of the operator.

I make a page to display all data from directory table and call the name of the operator from the other table according the operatorid saved on directory table.

Apart from this I try to display the total amount of mobile numbers saved in directory table and I try to display the amount of mobile numbers with same operator id such as for example if 10 mobile numbers of abcmobile ltd from 84 mobile numbers I try ro show "10 of 84 mobile numbers are assigned to abcmobile"

anyone help me to correct my coding please shown below?

<?php 
    require("../headerloggedin.php"); 
?> 
    <div id="content">
            <?php
                $userid = $_SESSION["userid"];

                $allnumbers = 0;
                $gomobile = 0;
                $vodafone = 0;
                $melita = 0;
                $other = 0;

                $query = "SELECT * FROM directory, operator WHERE userid= $userid AND directory.operator1 = operator.id" ;
                $result = $db->query($query);

                $allnumbers++;
                    echo "Total numbers added is" .$allnumbers. "numbers";

                    if($row["operator1"] == "1")
                    {
                        $gomobile++;
                        echo "<p>".$gomobile."</p>";
                    }

                    else if($row["operator1"] == "Vodafone")
                    {
                        $vodafone++;
                    }

                    else if($row["operator1"] == "Melira")
                    {
                        $melita++;
                    }

                    else if($row["operator1"] == "Other Operator")
                    {
                        $others++;
                    }

                while ($row = mysql_fetch_array($result))
                {
            ?>
            <table>
                <tr>
                    <td>Name:</td>                        
                    <td><?php echo $row["name"];?></td>
                </tr>
                <tr>
                    <td>Surname:</td>
                    <td><?php echo $row["surname"]; ?></td>
                </tr>
                <tr>
                    <td>Mobile Number:</td>
                    <td><?php echo $row["mobnum1"]; ?></td>
                </tr>
                <tr>
                    <td>Operator:</td>
                    <td><?php echo $row["operator"]; ?></td>
                </tr>
            </table>
            <br />
            <?php 
                }
            ?>
        <br />   
        <a href="../indexloggedin.php">Go to main menu.</a>
    </div>
<?php require("../footerloggedin.php"); ?>
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0

The entire is probably not required, you just do an SQL count and group by and then place the data into an array.

SELECT operator, COUNT(operator) FROM table GROUP BY operator 

Edited by diafol

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.