Cycle does not show all the results as it shows in the SQL
my code is not showing all the results that my query shows in the SQL, and i«m not sure why I would like someone to help me find the problem, I have the following code below:
My query in php (it shows 2 results in SQL of 2 different cards from the same person, but in php it just shows one result)
$sql='SELECT Card.*
FROM Card
WHERE ValidUntil <= Cast(DateAdd( DD ,7 , GetDate() ) as Date)
ORDER BY ValidUntil ASC';
$stm = $conn->query($sql);
My cycle in php after my query:
OLD CODE
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
echo
'
';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead>';
echo '<tbody><tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr></br>';
echo '</tbody></table></body>';
After reading the comments I started changing my code, and at some point it shows all the results that it should, but it was showing for each row one tableheader
and I only want a single one, and the results below it, I have made the following changes, but now it still appears only one result again
if (!$stm)
echo "";
else
$rowsCabecalho = $stm->fetch();
$CType = isset($rowsCabecalho['CardType']) ? $rowsCabecalho['CardType'] : NULL;
$CNr = isset($rowsCabecalho['CardNr']) ? $rowsCabecalho['CardNr'] : NULL;
$CValFrom = isset($rowsCabecalho['ValidFrom']) ? $rowsCabecalho['ValidFrom'] : NULL;
$CValUntil = isset($rowsCabecalho['ValidUntil']) ? $rowsCabecalho['ValidUntil'] : NULL;
$CLTCCTime = isset($rowsCabecalho['LastTccTime']) ? $rowsCabecalho['LastTccTime'] : NULL;
$CCodingDate = isset($rowsCabecalho['CodingDate']) ? $rowsCabecalho['CodingDate'] : NULL;
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
php sql-server
add a comment |
my code is not showing all the results that my query shows in the SQL, and i«m not sure why I would like someone to help me find the problem, I have the following code below:
My query in php (it shows 2 results in SQL of 2 different cards from the same person, but in php it just shows one result)
$sql='SELECT Card.*
FROM Card
WHERE ValidUntil <= Cast(DateAdd( DD ,7 , GetDate() ) as Date)
ORDER BY ValidUntil ASC';
$stm = $conn->query($sql);
My cycle in php after my query:
OLD CODE
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
echo
'
';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead>';
echo '<tbody><tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr></br>';
echo '</tbody></table></body>';
After reading the comments I started changing my code, and at some point it shows all the results that it should, but it was showing for each row one tableheader
and I only want a single one, and the results below it, I have made the following changes, but now it still appears only one result again
if (!$stm)
echo "";
else
$rowsCabecalho = $stm->fetch();
$CType = isset($rowsCabecalho['CardType']) ? $rowsCabecalho['CardType'] : NULL;
$CNr = isset($rowsCabecalho['CardNr']) ? $rowsCabecalho['CardNr'] : NULL;
$CValFrom = isset($rowsCabecalho['ValidFrom']) ? $rowsCabecalho['ValidFrom'] : NULL;
$CValUntil = isset($rowsCabecalho['ValidUntil']) ? $rowsCabecalho['ValidUntil'] : NULL;
$CLTCCTime = isset($rowsCabecalho['LastTccTime']) ? $rowsCabecalho['LastTccTime'] : NULL;
$CCodingDate = isset($rowsCabecalho['CodingDate']) ? $rowsCabecalho['CodingDate'] : NULL;
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
php sql-server
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46
add a comment |
my code is not showing all the results that my query shows in the SQL, and i«m not sure why I would like someone to help me find the problem, I have the following code below:
My query in php (it shows 2 results in SQL of 2 different cards from the same person, but in php it just shows one result)
$sql='SELECT Card.*
FROM Card
WHERE ValidUntil <= Cast(DateAdd( DD ,7 , GetDate() ) as Date)
ORDER BY ValidUntil ASC';
$stm = $conn->query($sql);
My cycle in php after my query:
OLD CODE
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
echo
'
';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead>';
echo '<tbody><tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr></br>';
echo '</tbody></table></body>';
After reading the comments I started changing my code, and at some point it shows all the results that it should, but it was showing for each row one tableheader
and I only want a single one, and the results below it, I have made the following changes, but now it still appears only one result again
if (!$stm)
echo "";
else
$rowsCabecalho = $stm->fetch();
$CType = isset($rowsCabecalho['CardType']) ? $rowsCabecalho['CardType'] : NULL;
$CNr = isset($rowsCabecalho['CardNr']) ? $rowsCabecalho['CardNr'] : NULL;
$CValFrom = isset($rowsCabecalho['ValidFrom']) ? $rowsCabecalho['ValidFrom'] : NULL;
$CValUntil = isset($rowsCabecalho['ValidUntil']) ? $rowsCabecalho['ValidUntil'] : NULL;
$CLTCCTime = isset($rowsCabecalho['LastTccTime']) ? $rowsCabecalho['LastTccTime'] : NULL;
$CCodingDate = isset($rowsCabecalho['CodingDate']) ? $rowsCabecalho['CodingDate'] : NULL;
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
php sql-server
my code is not showing all the results that my query shows in the SQL, and i«m not sure why I would like someone to help me find the problem, I have the following code below:
My query in php (it shows 2 results in SQL of 2 different cards from the same person, but in php it just shows one result)
$sql='SELECT Card.*
FROM Card
WHERE ValidUntil <= Cast(DateAdd( DD ,7 , GetDate() ) as Date)
ORDER BY ValidUntil ASC';
$stm = $conn->query($sql);
My cycle in php after my query:
OLD CODE
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
echo
'
';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead>';
echo '<tbody><tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr></br>';
echo '</tbody></table></body>';
After reading the comments I started changing my code, and at some point it shows all the results that it should, but it was showing for each row one tableheader
and I only want a single one, and the results below it, I have made the following changes, but now it still appears only one result again
if (!$stm)
echo "";
else
$rowsCabecalho = $stm->fetch();
$CType = isset($rowsCabecalho['CardType']) ? $rowsCabecalho['CardType'] : NULL;
$CNr = isset($rowsCabecalho['CardNr']) ? $rowsCabecalho['CardNr'] : NULL;
$CValFrom = isset($rowsCabecalho['ValidFrom']) ? $rowsCabecalho['ValidFrom'] : NULL;
$CValUntil = isset($rowsCabecalho['ValidUntil']) ? $rowsCabecalho['ValidUntil'] : NULL;
$CLTCCTime = isset($rowsCabecalho['LastTccTime']) ? $rowsCabecalho['LastTccTime'] : NULL;
$CCodingDate = isset($rowsCabecalho['CodingDate']) ? $rowsCabecalho['CodingDate'] : NULL;
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
if (isset($$variable) AND !is_null($$variable) AND !empty(trim($$variable))):
echo '<th>' . $tableHeader['title'] . '</th>';
endif;
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
php sql-server
php sql-server
edited Nov 14 '18 at 10:38
Anoushka Iola
asked Nov 14 '18 at 10:08
Anoushka IolaAnoushka Iola
74
74
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46
add a comment |
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46
add a comment |
1 Answer
1
active
oldest
votes
Solution:
Remove $rowsCabecalho = $stm->fetch();
from your code. First, you never use $rowsCabecalho
and second, don't call $stm->fetch()
twice.
Use PDOStatement::fetch like this:
<?php
...
while ($row = $stmt->fetch())
foreach($row => $value)
echo $value;
// your code ...
...
?>
Update:
If you want to print the header, and then the rows, you may try with this:
<?php
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
echo '<th>' . $tableHeader['title'] . '</th>';
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
?>
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297624%2fcycle-does-not-show-all-the-results-as-it-shows-in-the-sql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solution:
Remove $rowsCabecalho = $stm->fetch();
from your code. First, you never use $rowsCabecalho
and second, don't call $stm->fetch()
twice.
Use PDOStatement::fetch like this:
<?php
...
while ($row = $stmt->fetch())
foreach($row => $value)
echo $value;
// your code ...
...
?>
Update:
If you want to print the header, and then the rows, you may try with this:
<?php
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
echo '<th>' . $tableHeader['title'] . '</th>';
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
?>
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
add a comment |
Solution:
Remove $rowsCabecalho = $stm->fetch();
from your code. First, you never use $rowsCabecalho
and second, don't call $stm->fetch()
twice.
Use PDOStatement::fetch like this:
<?php
...
while ($row = $stmt->fetch())
foreach($row => $value)
echo $value;
// your code ...
...
?>
Update:
If you want to print the header, and then the rows, you may try with this:
<?php
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
echo '<th>' . $tableHeader['title'] . '</th>';
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
?>
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
add a comment |
Solution:
Remove $rowsCabecalho = $stm->fetch();
from your code. First, you never use $rowsCabecalho
and second, don't call $stm->fetch()
twice.
Use PDOStatement::fetch like this:
<?php
...
while ($row = $stmt->fetch())
foreach($row => $value)
echo $value;
// your code ...
...
?>
Update:
If you want to print the header, and then the rows, you may try with this:
<?php
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
echo '<th>' . $tableHeader['title'] . '</th>';
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
?>
Solution:
Remove $rowsCabecalho = $stm->fetch();
from your code. First, you never use $rowsCabecalho
and second, don't call $stm->fetch()
twice.
Use PDOStatement::fetch like this:
<?php
...
while ($row = $stmt->fetch())
foreach($row => $value)
echo $value;
// your code ...
...
?>
Update:
If you want to print the header, and then the rows, you may try with this:
<?php
echo '<div class="informaltable"><p></p><table cellspacing="2" border="0"><thead><tr>';
$tableHeaders = [
['variable' => 'CType', 'title' => 'Tipo'],
['variable' => 'CNr', 'title' => 'Nr.'],
['variable' => 'CValFrom', 'title' => 'Válido Desde'],
['variable' => 'CValUntil', 'title' => 'Válido Até'],
['variable' => 'CLTCCTime', 'title' => 'Dia/Hora no Último Terminal'],
];
foreach($tableHeaders as $tableHeader):
$variable = $tableHeader['variable'];
echo '<th>' . $tableHeader['title'] . '</th>';
endforeach;
echo '</tr></thead><tbody>';
if (!$stm)
echo "";
else
while ($rows2 = $stm->fetch())
$CType = isset($rows2['CardType']) ? $rows2['CardType'] : NULL;
$CNr = isset($rows2['CardNr']) ? $rows2['CardNr'] : NULL;
$CValFrom = isset($rows2['ValidFrom']) ? $rows2['ValidFrom'] : NULL;
$CValUntil = isset($rows2['ValidUntil']) ? $rows2['ValidUntil'] : NULL;
$CLTCCTime = isset($rows2['LastTccTime']) ? $rows2['LastTccTime'] : NULL;
$CCodingDate = isset($rows2['CodingDate']) ? $rows2['CodingDate'] : NULL;
echo '<tr>';
$tableDatas1 = [
['variable1' => 'CType', 'data1' => $CType],
['variable1' => 'CNr', 'data1' => $CNr],
['variable1' => 'CValFrom', 'data1' => $mytime1],
['variable1' => 'CValUntil', 'data1' => $mytime2],
['variable1' => 'CLTCCTime', 'data1' => $mytime3],
];
foreach($tableDatas1 as $tableData1):
$variable1 = $tableData1['variable1'];
if (isset($$variable1) AND !is_null($$variable1) AND !empty(trim($$variable1))):
echo '<td class="text_body">' . $tableData1['data1'] . '</td>';
endif;
endforeach;
echo '</tr>';
echo '</tbody></table></body>';
?>
edited Nov 14 '18 at 10:46
answered Nov 14 '18 at 10:17
ZhorovZhorov
3,7442518
3,7442518
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
add a comment |
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
It's working and the code is smaller than it was! I really thought I would have to use all those fetch and ifs. THanks!
– Anoushka Iola
Nov 14 '18 at 10:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297624%2fcycle-does-not-show-all-the-results-as-it-shows-in-the-sql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think the fetch statement is fault. You need to fetch_assoc(). Try $row = fetch_assoc($stm).
– Bijay Regmi
Nov 14 '18 at 10:15
You've made a change in your code. Is this last version of you code? Thanks.
– Zhorov
Nov 14 '18 at 10:35
@Zhorov I've made some changes now, with your answer below it was working, showing all the results, but it was not the way I wanted because I had one header for each row, I«ve made some changes as you can see in the updated, but now I still only get one row
– Anoushka Iola
Nov 14 '18 at 10:40
@AnoushkaIola OK, see updated answer.
– Zhorov
Nov 14 '18 at 10:46