Lennart Ericson
asked on
Why do I get double values?
Trying to rewrite a script that worked well with php 5.6 to get it to work with php 7.1.
It gives me database column titles OK but it doubles all values. Please help.
medlem_excel.php
medlem-2017-10-22.xls
It gives me database column titles OK but it doubles all values. Please help.
medlem_excel.php
medlem-2017-10-22.xls
Good advice offered by fibo. You would do well to rewrite this script.
Your double values are likely coming from the fact that you have a while() loop based on "$row = $ret2->fetch_array()", but your custom function mysqli_result() is also seeking on the same object, $ret2. Your row-based loop will also tend to repeat the row closing tag.
Your double values are likely coming from the fact that you have a while() loop based on "$row = $ret2->fetch_array()", but your custom function mysqli_result() is also seeking on the same object, $ret2. Your row-based loop will also tend to repeat the row closing tag.
Try replacing the nested while for $ret2 with a foreach also (much like $ret3)
while ($row = $ret2->fetch_array()) {
foreach ($row as $k => $v) {
echo "<ss:Cell ss:StyleID=\"s24\"><ss:Data ss:Type=\"String\">".$v."</ss:Data></ss:Cell>";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
B-)
You're so right Julian!
You're so right Julian!
ASKER
Thanks Julian. Your insight made my day!
You are welcome.
Thanks Julian! This is something that should probably be added to php.net's notes
1 - You take the painful route to generate your Excel file. Some other paths you might consider:
a - If you use it as a raw excel file... generate a simple csv file instead, eg
Open in new window
(see https://dev.mysql.com/doc/refman/5.7/en/select-into.html) BUT in that case the file will be on the server, not the best solution in most cases(Note that I used ";" instead of "," as a separator, since I presume your working language in Excel is not English)
b - you can generatethe csv file yourself directly, using the same parameters.
2 - Your code mixes lots of "xml-like" tags with php text. This makes your program highly difficult to undertsand / check / debug.
I would consider placing most of the tags in php $variables, and place these definitions in a separate php file to be included. Your program would then bereduced to 2 dozens of lines .