/    Sign up×
Community /Pin to ProfileBookmark

Table Autofill

Hey I’m having problems with my code. I want the first row to have multiple columns based on input.

Min to Max height in steps of five for the row
Min to Max weight in steps of five for the columns

So far I’ve been able to get the length to work but the weight just piles up on one row instead of spreading out on a column.

Help will be greatly appreciated.

[code=php]
<table border= “1” align= “center” style=”width:600px”>’;
for($j=$min_height; $j<=$max_height; $j=$j+5){
echo ‘<tr>
<td> Height &#8674; </br> Weight &#8675;</td>
<td>’ . $j . ‘</td>
</tr>
‘;
}
for ($i=$min_weight; $i<=$max_weight; $i= $i+5) {
echo ‘
<tr>
<td>’ . $i . ‘</td>
<td>’ . $i/($j*$j) . ‘</td>
<td>’ . $i/($j*$j) . ‘</td>
<td>’ . $i/($j*$j) . ‘</td>
<td>’ . $i/($j*$j) . ‘</td>
<td>’ . $i/($j*$j) . ‘</td>
</tr>
‘;
}

echo ‘
<tr>

</tr>
</table>
[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@OmegaJuniorMay 01.2015 — Your code is making 2 sets of rows: a set of height rows, and then a set of weight rows. Each set has a different amount of columns. I can imagine that many a browser will choke on that.

If it is your intention to have 2 sets of rows, then maybe you should show them in 2 tables, rather than 1.

If that is not your intention, but you would rather show 1 weight row per height row, you need to rethink your loops.

Since I refuse to read your mind, it may help to draw a picture of your desired end result.
Copy linkTweet thisAlerts:
@CodeGuruauthorMay 01.2015 — Haha that was funny. This is what i have in mind/what i'm trying to do. [ATTACH]16681[/ATTACH]

[canned-message]attachments-removed-during-migration[/canned-message]
Copy linkTweet thisAlerts:
@CodeGuruauthorMay 02.2015 — Help anyone? Am i not explaining it well? ?
Copy linkTweet thisAlerts:
@CodeGuruauthorMay 03.2015 — Hey, I was able to get the table rows and columns in order but i only have one major problem left. I would really appreciate it if someone could look at it.

The table is meant to produce this formula [code=php]number_format(($j/pow(($i/100),2)),3)[/code] However, it displays the result on one row instead of across the whole table.

This is my full code:
[code=php]
<?php

$min_weight = 60;
$max_weight = 90;
$min_height = 140;
$max_height = 170;

echo '<!DOCTYPE html>
<head>
<title>Task 1</title>
<style>
body {
background-color: blue;
}
</style>
</head>
<body>
<table border= "1" align= "center" style="width:600px;">
<tr>
<th>Height &#8674; </br> Weight &#8675;</th>';
for($i=$min_height; $i<=$max_height; $i=$i+5){

echo '<th>' . $i . '</th>
';
}
echo'</tr>';
for ($j=$min_weight; $j<=$max_weight; $j= $j+5) {
echo '<tr>
<th>' . $j . '</th>
';
}
for($i=$min_height; $i<=$max_height; $i=$i+5){
for ($j=$min_weight; $j<=$max_weight; $j= $j+5) {
echo '<td>' . number_format(($j/pow(($i/100),2)),3) . '</td>
';
}
}
echo '
</tr>
</tr>
</table>
</body>
';
?>
[/code]
Copy linkTweet thisAlerts:
@rootMay 05.2015 — IMHO one of the problems you have is that you are writing large code blocks by making them in to strings.

Suggest that you look at HEREDOC methods of producing large HTML code blocks, as well as dropping in and out of PHP with page flow, it will also help you in regards to layout.

What you need is to look at the end user and if the server glitches and the page doesn't compile, if you have the bones of an HTML framework that loads, at the very least the clients not staring at page with only a server error 500 or similar displaying.
Copy linkTweet thisAlerts:
@CodeGuruauthorMay 06.2015 — Thanks. I'll look into that!
×

Success!

Help @CodeGuru spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...