0
for ($q = 1 ; $q < 7 ; $q++ )
{
echo $q ; echo $row;
}

now this code works fine but i want to echo 2 rows like in the image below:

the $row is a string value from sql I don't want use other for loop, Can i do it with table html tags ?

1 Answer 1

2

You can achieve this using variables that you will echo later just like this:

$tableHeader = "";
$tableRow = "";

for ($q = 1 ; $q < 7 ; $q++ )
{
    $tableHeader .= "<th>" . $q . "</th>";
    $tableRow .= "<td>". $row ."</td>";
}

echo "<table> <tr>$tableHeader</tr> <tr>$tableRow</tr> </table>";
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks,, can I use table tag to echo inside it because i have other for loops every loop start from different values ?
@Aiman Yes of course just remove it from my echo and append to your final 'html table string'. Don't forget to validate the answer and upvote it if it was helpfull :)
Thanks it's working, and i upvoted your answer, but get logic error when I add -1 after $q $q-1 to echo 1 , 2 , 3, etc.
In SO you can use the V icon under the 2 arrows to downote or upvote. This icon mark the answer has the correct answer of your question. It's help other user to directly see what the answer is.
your code is perfect but how can I echo the result of $q-1without get the logic error ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.