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.
echo current($inputexplode);
echo next($inputexplode);

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

echo $result ."<br/>";

if ($result !=2 and $result>1){

echo $i."<br/>";


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

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

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

$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"
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php echo $newTitle; ?>
<meta name="author" content="jinlu"><!-- Date: 2012-04-30 -->
<a href="Ex2-3.php">Back to Explosion!</a><br />

<?php echo $htmlStringForTable; ?>

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

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.