Hello, I would love to display the values of 65 columns which have been added and then display them on the screen, at the moment only 59 of the 65 columns added appear. here is my code.

$result = mysql_query("SELECT SUM(segment) AS segment, SUM(funct) AS funct,SUM(pronoun) AS pronoun.............. right up to column 65");

$row = mysql_fetch_assoc($result);

//display them onto the screen
echo '<br/>' . $row.'<br/>' . $row.'<br/>' . $row.........right up to column 65;

I think there might be columns which add up to zero and the code then reads it as an empty string, but I don't think that there are more than 2 which are zero. If there might be another explanation of this please assist.

Your help will be highly appreciated.

Dani AI

Generated

As already suggested, the first thing to check is alias collisions — if two SELECT items end up with the same column name the latter will overwrite the earlier value in the associative result. If you already ruled that out, try these practical checks and fixes to see what MySQL/PHP are actually returning.

First, inspect the raw result and column metadata so you can see which fields exist and which values are NULL/zero. Dump the fetched row and enumerate field names:

/* inspect what the DB returned */
var_dump($row);
echo 'fields returned: ' . mysql_num_fields($result) . "<br/>\n";

for ($i = 0; $i < mysql_num_fields($result); $i++) {
    $meta = mysql_fetch_field($result, $i);
    echo $meta->name . ': ' . var_export($row[$meta->name], true) . "<br/>\n";
}

If some SUM()s are NULL because the column contains only NULLs, they will look “missing” when printed. Convert NULLs to zeros in SQL with IFNULL or COALESCE so the result always shows a value:

SELECT IFNULL(SUM(colA), 0) AS colA_sum,
       IFNULL(SUM(colB), 0) AS colB_sum,
       ...
FROM your_table;

See the MySQL IFNULL docs for details: .

Other things to verify: check the real number of fields with mysql_num_fields() and watch for identifier truncation (MySQL truncates long aliases to the identifier limit — see identifier length), and call mysql_error() after mysql_query() to catch warnings. For readability and maintenance consider the view approach mentioned, and plan a move to mysqli or PDO since the old mysql extension is deprecated.

Recommended Answers

All 2 Replies

The only thing I can think of with such a long query is that you have used the same alias name twice. There is no logical reason that mysql does not return or show a single column.

Apart from this, I'd like to advise you to create a view with this query, so in code you can just do: SELECT * FROM my_sum_view

Hi priteas I just checked my query and there wasn't a single typing error or duplication of fields, I'll try viewing it then. Thank you very much!!!

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.