PHP Table Data Show Results Vertically not Horizontally - php
I'm really frustrated.. I really need to show this table right. How can I set this code to show table vertically like this:
1 - 4 - 7
2 - 5 - 8
3 - 6 - 9
And not like this:
1 - 2 - 3 - 4
5 - 6 - 7 - 8
9 - ... ect
<?php
$PNG_WEB_DIR = plugin_dir_path( __FILE__ ).'temp/';
wp_mkdir_p($PNG_WEB_DIR);
$cols = $this->settings['cols'];
$rows = $this->settings['rows'];
$label_number = 0;
// die($_GET['order_ids']);
$order_ids = explode(',',$_GET['ids']);
$order_count = count($order_ids);
$labels_per_page = $cols*$rows;
$page_count = ceil(($order_count)/$labels_per_page);
for ($page=0; $page < $page_count; $page++) {
echo '<table class="address-labels" width="100%" height="100%" border="0" cellpadding="0">';
$last_height = 0;
$current_height = $current_width = 0;
$current_row = 0;
for ($label=0; $label < $labels_per_page; $label++) {
$label_number++;
$current_col = (($label_number-1) % $cols)+1;
if ($current_col == 1) {
$last_height = $current_height;
$last_width = 0;
$current_row++;
echo '<tr class="label-row">';
}
if ( $label_number > $this->offset && isset($order_ids[$label_number - $this->offset - 1]) ) {
$order_id = $order_ids[$label_number - $this->offset - 1];
} else {
$order_id = '';
}
$current_width = round( $current_col * (100/$cols) );
$width = $current_width - $last_width;
$last_width = $current_width;
$current_height = round( $current_row * (100/$rows) );
$height = $current_height - $last_height;
printf('<td width="%s%%" height="%s%%" class="label"><div class="label-wrapper">', $width, $height);
// because we are also looping through the empty labels,
// we need to check if there's an order for this label
if (!empty($order_id)) {
// get label data from order
$order = new WC_Order( $order_id );
// replace placeholders
$label_data = isset($this->settings['address_data'])? nl2br( $this->settings['address_data'] ): '[shipping_address]';
$label_data = $this->make_replacements( $label_data, $order );
echo '<div class="address-block">';
echo '<div class="addrress_show">';
// process label template to display content
echo $label_data;
echo '</div>';
echo '<div class="clearb"></div>';
echo '</div>';
} else {
echo ' ';
}
echo '</div></td>';
if ($current_col == $cols) {
echo '</tr>';
}
}
echo '</table>';
}
// shpt_after_page hook
do_action( 'shpt_after_page' );
?>
Since I can't know your raw data structure which you use to loop through it and produce the table, I presumed it as one-dimensional array and you want to print the table as 3 columns as you said, to see in action here's a PHP Fiddle - hit run to execute it - this will work for any array length as long as columns is 3, the rows is dynamic
PHP: Updated for naming purpose
<?php
$table = '<table class="address-labels" width="30%" border="0" cellpadding="0">';
$dataArr = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, 17);
$colNum = 3;
$rowNum = ceil(count($dataArr)/$colNum);
for($i=0; $i < $rowNum; $i++){
$x1 = isset( $dataArr[$i] ) ? $dataArr[$i] : '-';
$x2 = isset( $dataArr[$i + $rowNum] ) ? $dataArr[$i + $rowNum] : '-';
$x3 = isset( $dataArr[$i + 2 * $rowNum] ) ? $dataArr[$i + 2 * $rowNum] : '-';
$table .= '<tr><td>' . $x1 . '</td><td>' . $x2 . '</td><td>' . $x3 . '</td></tr>';
}
$table .= '</table>';
echo $table;
?>
EDIT:
Now if you want to change the column number, like set it to 5 for example, you need to do the following:
1st - set $colNum = 5;
2nd - add more variables to hold the values like, *considering it is 5 columns:
$x4 = isset( $dataArr[$i + 3 * $rowNum] ) ? $dataArr[$i + 3 * $rowNum] : '-';
$x5 = isset( $dataArr[$i + 4 * $rowNum] ) ? $dataArr[$i + 4 * $rowNum] : '-';
and don't forget to increase the multiplier * $rowNum
then for each extra column you add you need to add <td></td> like:
'<td>' . $x4 . '</td><td>' . '</td><td>' . $x5 . '</td><td>' . '</td>'
Here's another PHP Fiddle showing the above for 5 columns.
Try this. It's in pure php
<?php
$cols = 3;
$data = range(1,29);
// classic
$index = 1;
foreach($data as $el)
{
echo $el.' '; if ($index % $cols ==0) echo '<br/>';
$index++;
}
echo '<br/><br/>';
// special
$rows = $cols ;
$cols = floor(count($data)/$cols);
for($row = 0 ; $row < $rows; $row++){
for ($index = $row; $index < count($data); $index += $rows)
echo $data[$index].' ';
echo '<br/>';
}
Related
How to use PHP pagination in array's
Since I am trying to learn more about PHP I would like to add Pagination to array's I have a JSON output that I can read and echo via a foreach. But I am not able to show 10 or 20 records. I have used the code from this page: But I miss the place where I can store the echo for the array. $persons = '[ {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"}, {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"}, {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"}, {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"}, {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"}, {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"}, {"FrstName":"Avery","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Peter","Middlename":"","LastName":"Kap","Online":true,"DeptId":"2"}, {"FrstName":"Denzo","Middlename":"","LastName":"Falc","Online":false,"DeptId":"4"}, {"FrstName":"Eveline","Middlename":"","LastName":"Benzel","Online":false,"DeptId":"3"}, {"FrstName":"Bill","Middlename":"","LastName":"Libuz","Online":false,"DeptId":"3"}, {"FrstName":"April","Middlename":"","LastName":"Gonzo","Online":false,"DeptId":"2"}, {"FrstName":"Harry","Middlename":"","LastName":"Geraldson","Online":true,"DeptId":"3"}, {"FrstName":"Heraldson","Middlename":"","LastName":"McGree","Online":false,"DeptId":"3"} {"FrstName":"Abraham","Middlename":"","LastName":"Retz","Online":true,"DeptId":"4"}, {"FrstName":"June","Middlename":"","LastName":"Pharee","Online":true,"DeptId":"2"}, {"FrstName":"Anthony","Middlename":"","LastName":"Gonzales","Online":false,"DeptId":"4"}, {"FrstName":"Billy","Middlename":"","LastName":"Scott","Online":false,"DeptId":"3"}, {"FrstName":"Anika","Middlename":"","LastName":"Rose","Online":false,"DeptId":"3"}, {"FrstName":"Kristen","Middlename":"","LastName":"Fontana","Online":false,"DeptId":"2"}, {"FrstName":"Olivia","Middlename":"","LastName":"Menzel","Online":true,"DeptId":"3"}, {"FrstName":"Mark","Middlename":"van","LastName":"Gad","Online":false,"DeptId":"3"} {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"} ]'; $page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1; $total = count( $persons ); //total items in array $limit = 10; //per page $totalPages = ceil( $total/ $limit ); //calculate total pages $page = max($page, 1); //get 1 page when $_GET['page'] <= 0 $page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages $offset = ($page - 1) * $limit; if( $offset < 0 ) $offset = 0; $yourDataArray = array_slice( $persons, $offset, $limit ); $link = 'index.php?page=%d'; $pagerContainer = '<div style="width: 300px;">'; if( $totalPages != 0 ) { if( $page == 1 ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( ' « prev page', $page - 1 ); } $pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>'; if( $page == $totalPages ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( ' next page » ', $page + 1 ); } } $pagerContainer .= '</div>'; echo $pagerContainer; I would like to know how I can fix this to use pagination for my array.
You need to json_decode() your JSON first to access array methods (count(), array_slice()). Also, your JSON data was invalid, missing some commas, fixed that. <?php $persons = '[ {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"}, {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"}, {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"}, {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"}, {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"}, {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"}, {"FrstName":"Avery","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Peter","Middlename":"","LastName":"Kap","Online":true,"DeptId":"2"}, {"FrstName":"Denzo","Middlename":"","LastName":"Falc","Online":false,"DeptId":"4"}, {"FrstName":"Eveline","Middlename":"","LastName":"Benzel","Online":false,"DeptId":"3"}, {"FrstName":"Bill","Middlename":"","LastName":"Libuz","Online":false,"DeptId":"3"}, {"FrstName":"April","Middlename":"","LastName":"Gonzo","Online":false,"DeptId":"2"}, {"FrstName":"Harry","Middlename":"","LastName":"Geraldson","Online":true,"DeptId":"3"}, {"FrstName":"Heraldson","Middlename":"","LastName":"McGree","Online":false,"DeptId":"3"}, {"FrstName":"Abraham","Middlename":"","LastName":"Retz","Online":true,"DeptId":"4"}, {"FrstName":"June","Middlename":"","LastName":"Pharee","Online":true,"DeptId":"2"}, {"FrstName":"Anthony","Middlename":"","LastName":"Gonzales","Online":false,"DeptId":"4"}, {"FrstName":"Billy","Middlename":"","LastName":"Scott","Online":false,"DeptId":"3"}, {"FrstName":"Anika","Middlename":"","LastName":"Rose","Online":false,"DeptId":"3"}, {"FrstName":"Kristen","Middlename":"","LastName":"Fontana","Online":false,"DeptId":"2"}, {"FrstName":"Olivia","Middlename":"","LastName":"Menzel","Online":true,"DeptId":"3"}, {"FrstName":"Mark","Middlename":"van","LastName":"Gad","Online":false,"DeptId":"3"}, {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"} ]'; // Make the JSON an array, so count() and array_slice() work $persons = json_decode($persons, true); $page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1; $total = count( $persons ); //total items in array // $limit = 10; //per page // Set limit to 3 for testing: $limit = 3; $totalPages = ceil( $total/ $limit ); //calculate total pages $page = max($page, 1); //get 1 page when $_GET['page'] <= 0 $page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages // Uncomment this for testing // $page = 2; $offset = ($page - 1) * $limit; if( $offset < 0 ) $offset = 0; $yourDataArray = array_slice( $persons, $offset, $limit ); $link = 'index.php?page=%d'; $pagerContainer = '<div style="width: 300px;">'; if( $totalPages != 0 ) { if( $page == 1 ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( ' « prev page', $page - 1 ); } $pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>'; if( $page == $totalPages ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( ' next page » ', $page + 1 ); } } $pagerContainer .= '</div>'; echo $pagerContainer; foreach($yourDataArray as $person) { echo "\n"; echo "First name: " . $person['FrstName']; echo " - Middle name: " . $person['Middlename']; echo " - Last name: " . $person['LastName']; echo " - Online: " . $person['Online']; echo " - Dept: " . $person['DeptId']; } https://3v4l.org/8hR84
PHP sum each loop value
I wanted to make a simple calculations to summarized what I purchased. Using $_GET every time the value is updated it should save in an array then when 'start' is executed, it gives the sum. Sorry the codes here are just googled and I'm not really a programmer. I don't know how to combine the two sets of code (array + sum). $number = $_GET ['input']; $arr = array ($number); $data = array($arr); foreach ($tareas as $tarea) { $data[] = $tarea; } var_dump($data); $sum = 0; foreach($group as $key=>$arr) { $sum+= $arr; } echo $sum;
So I got this code from withinweb.com and modified to make it simpler. <?php session_start(); $products = array($_GET["prod"]); $amounts = array($_GET ["cost"]); if ( !isset($_SESSION["total"]) ) { $_SESSION["total"] = 0; for ($i=0; $i< count($products); $i++) { // $_SESSION["qty"][$i] = 0; $_SESSION["amounts"][$i] = 0; } } //--------------------------- //Reset if ( isset($_GET['reset']) ) { if ($_GET["reset"] == 'true') { unset($_SESSION["qty"]); //The quantity for each product unset($_SESSION["amounts"]); //The amount from each product unset($_SESSION["total"]); //The total cost unset($_SESSION["cart"]); //Which item has been chosen } } //--------------------------- //Add if ( isset($_GET["add"]) ) { $i = $_GET["add"]; $qty = $_SESSION["qty"][$i] + 1; $_SESSION["amounts"][$i] = $amounts[$i] * $qty; $_SESSION["cart"][$i] = $i; $_SESSION["qty"][$i] = $qty; } //--------------------------- //Delete if ( isset($_GET["delete"]) ) { $i = $_GET["delete"]; $qty = $_SESSION["qty"][$i]; $qty--; $_SESSION["qty"][$i] = $qty; //remove item if quantity is zero if ($qty == 0) { $_SESSION["amounts"][$i] = 0; unset($_SESSION["cart"][$i]); } else { $_SESSION["amounts"][$i] = $amounts[$i] * $qty; } } //cart if ( isset($_SESSION["cart"]) ) { $total = 0; foreach ( $_SESSION["cart"] as $i ) { echo '' . $products[$_SESSION["cart"][$i]] . ' - ' . $_SESSION["amounts"][$i] . '<br>'; $total = $total + $_SESSION["amounts"][$i]; } $_SESSION["total"] = $total; echo' <br> Total : ' . $total . ' '; } ?> When I input ?add=0&prod=apple&cost=100, it gives me: apple - 100 Total : 100 But when I add another session, ?add=1&prod=orange&cost=200 it doesn't give the right answer. orange - 100 - 0 Total : 100 It should return me this value, I'm puzzled where could be the error. apple - 100 orange - 200 Total : 300 Yes, I'm not a coder, but trying to solve a big problem.. :) Thanks for those who help.
Use PHP while loop to create advance filter
I have a problem and that is I want to create a link on a website like people can click the link to show certain products only depending on percentage. like for example, i have a column in my database with discount percentage and it will show min discount and max discount. assuming we have min and max discount. $min=12 and $max=94; and I want to put them in links to show only products with certain discounts only like filtering. below is the example of the link. <a href="#">12% to 20%</a 21% to 30% 31% to 40% and so on until it reaches 81% to 90% and the last will be 91% to 94% smallest and largest numbers will be coming from a column from database and they can change frequently. i came up with solution and its working fine but my code is too long and its like I took to many steps which could be done in few lines of code. I have pasted my working code below but I am sure this can be reduced to few lines of code. $catsql25 = "SELECT MAX(down_percentage) as largest FROM hot_deals"; $catquery25 = mysqli_query($conn, $catsql25); while ($row25 = mysqli_fetch_array($catquery25, MYSQLI_ASSOC)){ $largest_number = $row25['largest']; } $catsql26 = "SELECT MIN(down_percentage) as smallest FROM hot_deals"; $catquery26 = mysqli_query($conn, $catsql26); while ($row26 = mysqli_fetch_array($catquery26, MYSQLI_ASSOC)){ $smallest_number = $row26['smallest']; } $array_tens = array(10,20,30,40,50,60,70,80,90,100); foreach ($array_tens as $value){ if(($value - $smallest_number <= 10) && ($value - $smallest_number > 0)){ echo '<a href="/exp.php?fst='.$smallest_number.'&lst='.$value.'"><div class="lfmen2">'; echo $smallest_number." to ".$value."</div></a>"; $next_num = $value + 1; $next_ten = 9; $stop_num = floor($largest_number / 10); $stop_num2 = $stop_num * 10; //echo $stop_num2.'<br>'; $num_rounds = $stop_num2 - $value; $num_rounds2 = $num_rounds / 10; //echo $num_rounds2; for ($i = 1; $i <= $num_rounds2; $i++){ $end_num = $next_num + $next_ten; echo '<a href="/exp.php?fst='.$next_num.'&lst='.$end_num.'"><div class="lfmen2">'; echo $next_num; echo " to "; echo $end_num; echo "</div></a>"; $next_num += 10; $end_num += 10; } } } foreach ($array_tens as $value2){ if(($largest_number - $value2 < 10) && ($largest_number - $value2 > 0)){ $lsst = $value2 + 1; if($lsst != $largest_number){ echo '<div class="lfmen2">'.$lsst." to ".$largest_number."</div>"; } elseif($lsst == $largest_number){ echo '<div class="lfmen2">'.$largest_number.'</div>'; } } } I know its all mess but.. Thanks.
First thing you could do is only one SQL Query : $catsql = "SELECT MAX(down_percentage) as largest, MIN(down_percentage) as smallest FROM hot_deals"; And then you'll need only one loop : $catquery = mysqli_query($conn, $catsql); while ($row = mysqli_fetch_array($catquery, MYSQLI_ASSOC)){ $largest_number = $row['largest']; $smallest_number = $row['smalest']; } After that, you could make only one foreach loop. The two "if" conditions could be in the same loop : foreach ($array_tens as $value) { if (($value - $smallest_number <= 10) && ($value - $smallest_number > 0)) { echo '<a href="/exp.php?fst='.$smallest_number.'&lst='.$value.'"><div class="lfmen2">'; echo $smallest_number." to ".$value."</div></a>"; $next_num = $value + 1; $next_ten = 9; $stop_num = floor($largest_number / 10); $stop_num2 = $stop_num * 10; //echo $stop_num2.'<br>'; $num_rounds = $stop_num2 - $value; $num_rounds2 = $num_rounds / 10; //echo $num_rounds2; for ($i = 1; $i <= $num_rounds2; $i++) { $end_num = $next_num + $next_ten; echo '<a href="/exp.php?fst='.$next_num.'&lst='.$end_num.'"><div class="lfmen2">'; echo $next_num; echo " to "; echo $end_num; echo "</div></a>"; $next_num += 10; $end_num += 10; } } if (($largest_number - $value < 10) && ($largest_number - $value > 0)) { $lsst = $value + 1; if ($lsst != $largest_number) { echo '<div class="lfmen2">'.$lsst." to ".$largest_number."</div>"; } elseif ($lsst == $largest_number) { echo '<div class="lfmen2">'.$largest_number.'</div>'; } } } To make it more readable, you could also comment your code to know what do what. This and a good indentation and you're right. Hope it helps.
php pagination of an array with previous and next tab
I have this array which contain around 1000 records. I want to display 20 array records per page. $list=array( array([title]=>"sony", [description]=>"camera"), array([title]=>"sony", [description]=>"mobiles"), array([title]=>"lenovo", [description]=>"laptop"), array([title]=>"lenovo", [description]=>"mobiles") ); I have used the following code for pagination. It is giving me a long row for pagination. Can someone help me to include previous and next code to my existing code so that my pagination will look good. $page = isset($_REQUEST['page']) && $_REQUEST['page'] > 0 ? $_REQUEST['page'] : 1; function display($list, $page = 1) { $start = ($page - 1) * 2; $list = array_slice($list, $start, 15); foreach ($list as $key => $val) { echo $val['title'] . '<br/>'; echo $val['description'] . '<br/>'; echo "<br>"; }} $len = count($list); $pages = ceil($len / 2); if ($page > $pages or $page < 1) { echo 'page not found'; } else { display($list, $page); for ($i = 1 ; $i <= $pages ; $i++) { $current = ($i == $page) ? TRUE : FALSE; if ($current) { echo '<b>' . $i . '</b>'; } else { ?> <?php echo $i;?> <?php } } }
Here's an example with the data array from your question. The example The page size is assumed to be 2 (20 in your question). The size of the data array does not matter. The start parameter is provided (as in your example) thru a GET parameter http://localhost/flipkart-api/fkt_offer.php?…start=index_or_page. This parameter is available in the script as $_GET['start']. The previous and next start indices are to be calculated ($start +/- $maxpage, etc.). To keep this example simple, I took the start index, not the page number, as parameter. But you also could use a page number and calculate the index, of course. For the reason of brevity I omitted error checking ("what if no more items", etc.). Code: <?php // The data array $list=array( array('title'=>"sony", 'description'=>"camera"), array('title'=>"sony", 'description'=>"mobiles"), array('title'=>"lenovo", 'description'=>"laptop"), array('title'=>"lenovo", 'description'=>"mobiles") ); // Evaluate URL $proto = ((isset($_SERVER["HTTPS"])) && (strtoupper($_SERVER["HTTPS"]) == 'ON')) ? "https://" : "http://"; $hname = getenv("SERVER_NAME"); $port = getenv("SERVER_PORT"); if ( (($port==80)&&($proto=='http://')) || (($port==443)&&($proto=='https://')) ) { $port = ''; } $params = ''; foreach ($_GET as $key=>$value) { if (strtolower($key)=='start') continue; $params .= (empty($params)) ? "$key=$value" : "&$key=$value"; } $url = $proto . $hname . $port. $_SERVER['SCRIPT_NAME'] . '?' . $params; // Page contents $last = count($list)-1; $start = (isset($_GET['start'])) ? intval($_GET['start']) : 0; if ($start<0) $start = 0; if ($start > $last) $start = $last; $maxpage = 2; echo "<p>Start index = $start</p>" . PHP_EOL; $curpage = 0; for($xi=$start; $xi<=$last; $xi++) { if ($curpage >= $maxpage) break; $curpage++; echo 'Entry ' . $curpage . ': ' . $list[$xi]['title'] . ' - ' . $list[$xi]['description'] . '<br />' . PHP_EOL; } // Navigation $prev = $start - $maxpage; if ($prev<0) $prev = 0; $next = ( ($start+$maxpage) > $last) ? $start : $start + $maxpage; $prev = ( ($start-$maxpage) < 0) ? 0 : $start - $maxpage; echo '<p>Previous '; echo 'Next</p>'; ?> Result (e.g) Start index = 2 Entry 1: lenovo - laptop Entry 2: lenovo - mobiles Previous Next
PHP I want to create a html table using php
hi heres my attempted code, the first while statement works for the rows(works for the weights0, but i cant get it to work with the columns(heights). it works so if min_height input value is 20 and max_height is 50 the columns would look like this 20 25 30 35 40 45 50. my code currently works for the rows but not columns, can anyone help? <?php $rowiStep = 5; $coliStep = 5; // Get these $iweightMin = $_GET["min_weight"]; $iweightMax = $_GET["max_weight"]; $iheightMin = $_GET["max_height"]; $iheightmax = $_GET["min_height"]; $iCur = $iweightMin; $iCol = $iheightMin; print('<table class="table">'); print('<tr ><td>Height/</br>Weight</td>'); while ($iCur <= $iweightMax) { printf('<tr><td>%d</td></tr>', $iCur); $iCur += $rowiStep; } $rowiCol = $iheightMin; while ($iCol <= $iheightmax) { printf('<tr><td></td>', $iCol); $iCol += $rowiCol; } print ('</tr>'); print('</table>'); ?>
If you're looking to print a height/weight matrix; try this: $rowiStep = 5; $coliStep = 5; $output = array( '<table>' ); for( $row_val = $_GET['min_weight'], $row_max <= $_GET['max_weight']; $row_val < $row_max; $row_val += $rowistep ) { $output[] = '<tr><td>' . $row_val . '</td>'; for( $col_val = $_GET['min_height'], $col_val <= $_GET['max_height']; $col_val < $col_max; $col_val += $colistep ) { $output[] = '<td>' . $col_val . '</td>'; } $output[] = '</tr>'; } $output[] = '</table>'; echo implode( "\n", $output ); This will produce output like this: |min_weight |min_height|min_height+colIStep|min_height+2colIstep|...| |min_weight + rowIstep |min_height|min_height+colIStep|min_height+2colIstep|...| |min_weight + 2rowIstep|min_height|min_height+colIStep|min_height+2colIstep|...| |...| What output are you looking for?