By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

put each element of an explode string into each cell of table

P: 2
let say user key in a,b,c,d in the submit page, how to display the output as a in row 1 column 1, b in row 1 column 2, c in row 2 column 1 and d in row 2 column 2.


here is the code.
<?php
$input=$_POST['input'];
$inputexplode=explode(",",$input);
echo current($inputexplode);
echo next($inputexplode);




echo "Here are exploded words!"."<br/><br/>";

$result=count($inputexplode);
echo $result ."<br/>";


if ($result !=2 and $result>1){
ceil(sqrt($result));
$i=ceil(sqrt($result));

}
else{
floor(sqrt($result));
$i=floor(sqrt($result));
echo $i."<br/>";

}

echo "rownumber" ;
echo $i ."<br/>";

$k=0;
for($k=1; $k<=$i;$k++)
{
echo $inputexplode[$k];
}

$htmlStringForTable = '';
$htmlStringForTable = '<table border="1">' . "\n";

$rows=$i;
$cols =$i;






for($row = 1; $row <= $rows; $row++) {



$htmlStringForTable = $htmlStringForTable . '<tr>' . "\n";

for($col = 1; $col <= $cols; $col++) {

$htmlStringForTable = $htmlStringForTable . '<td>';
$htmlStringForTable = $htmlStringForTable . $inputexplode;

$htmlStringForTable = $htmlStringForTable . '</td>' . "\n";
}
}

$htmlStringForTable = $htmlStringForTable . '</table>';





//for ($k=0;$k<=$i;$k++)
// {



?>





<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
<?php echo $newTitle; ?>
</title>
<meta name="author" content="jinlu"><!-- Date: 2012-04-30 -->
</head>
<body>
<br/>
<a href="Ex2-3.php">Back to Explosion!</a><br />

<?php echo $htmlStringForTable; ?>
</body>
</html>


thanks
May 5 '12 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
i did not read your code. dumping all code will reduce the chance of getting a proper answer.

but here i will give you some advice.


with count function you can get the number of element available in your exploded variable.
its better if you avoid current and next function, just use plane for loop
May 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.