Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP: Looping through mysql results and arrays

  • 08-01-2008 07:52PM
    #1
    Registered Users, Registered Users 2 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