Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP: Looping through mysql results and arrays

Options
  • 08-01-2008 7:52pm
    #1
    Registered Users Posts: 2,021 ✭✭✭


    Im running several count querys in mysql that provide the output shown below.


    +
    +
    +
    | to_number | callcount |
    +
    +
    +
    | 55555 | 123 |
    | 55556 | 10 |
    +
    +
    +
    2 rows in set (21.39 sec)

    This is the code I have written

    $sql = "select to_number, count(*) as callcount from entries where lcase(smsc) like '%vodafone%' and logdate >='2007-12-01' and logdate <='2007-12-31' and action='Receive' and to_number in (55555,55556) group by to_number;";

    $result = mysql_query($sql) or die('Error, query failed');
    $shortcodes_MO = array(55555, 55556);


    while ($row = mysql_fetch_row($result)) {
    foreach ($shortcodes_MO as $shortcode) {
    $row = $shortcode;


    }
    }

    What I'm trying to end up with is $55555 = 123 and $55556 = 10 but there is something incorrect and I dont know what it is. help!


Comments

  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    Assuming the query is returning a set, does a simple loop through the results not do?
    [PHP]$sql = "select to_number, count(*) as callcount from entries where lcase(smsc) like '%vodafone%' and logdate >='2007-12-01' and logdate <='2007-12-31' and action='Receive' and to_number in (55555,55556) group by to_number;";

    $result = mysql_query($sql) or die('Error, query failed');

    while ($row = mysql_fetch_row($result)) {
    echo "to_number=".$row.", count=".$row;
    }
    [/PHP]With table formatting around the output if appropriate.
    Or did you want to accumulate the query results in the $shortcodes_MO array for later processing?


Advertisement