PHP results from mysql array

Discussion in 'Web Design and Development' started by Stocktrader, Jun 10, 2013.

  1. Stocktrader macrumors member

    Oct 28, 2007
    The code below shows results from two queries with the output as:

    count of hotel1
    count of hotel2
    count of hotel3

    How can I get the results to read:
    hotel1 count of hotel1
    hotel2 count of hotel2
    hotel3 count of hotel3


    while($row = mysql_fetch_array($resultsum)){
    echo "Total ". $row['hotel']. " = $". $row['SUM(rate)'];
    echo "<br />";

    while($row = mysql_fetch_array($resultcount)){
    echo "There are ". $row['COUNT(rate)'] ." ". $row['rate'] ." items.";
    echo "<br />";
  2. SrWebDeveloper macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA
    Please always use PHP BB code tags to wrap source, it's easier for us to follow and assist you. Thanks.

    Maybe nobody else has responded because your code does NOT produce the output you posted here. What you want to do is merge some query results into output, which we can gladly help you with. However, this more than likely would be done with the query itself, not just the result set processing. Please post the queries and someone here will be able to assist you better, I think.

    On a side note you can assign aliases in your query to fields which then can be used as keys in those associative arrays. This makes for easier debugging and also formats key names properly avoiding potential errors:

    // $row['SUM(rate)'] could be $row['ratesum'] if the query was: 
    $query="select sum(rate) as ratesum from table";
  3. johnmacd macrumors newbie

    Jun 13, 2013

Share This Page