473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

2 New Member
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
1 1533
johny10151981
1,059 Top Contributor
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

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

Similar topics

1
by: Will Handley | last post by:
How do you use a LABEL tag within a two dimensional table? In the examples I've seen for this element, only extremely simple situations are shown, e.g., <LABEL FOR="wgt">Weight:</LABEL><INPUT...
3
by: Sandy Bremmer | last post by:
I was curious how one goes about properly creates a table row with multiple TD cells as a single hyperlink because I have seen examples of what I think is invalid and poorly conceived HTML. It...
1
by: Henry Stockbridge | last post by:
Hi, I am doing database documentation and run the procedure below to list the record count for each table in the database. The results in the immediate window only a partial listing of tables. ...
4
by: phil2phil | last post by:
Hi, Right now I have a datalist, that renders the following html: <tr> <td class="daycss" align="Left" valign="Top" style="background-color:#EEEEEE;height:20px;"> <div...
7
by: khunohm | last post by:
I would like to know how to select each item of data from text file transfer to each column in excel file. source 1..159662 /organism="Candidatus...
4
by: TS | last post by:
I am losing my colgroup html element of a table that i toggle back and forth of being visible=true/false. is there any workaround since the rendered html doesn't contain it even though it has not...
1
by: gah | last post by:
I am getting an array of records from an asp.net webservice and wanting to display them in a dynamically created html table in the php page. I am new to php and not sure how to get the values from...
3
by: bharathi228 | last post by:
hi, iam doing one asp.net application in gridview i have 3 columns. the first two column values are coming from database. the third column is template field.here i have one...
4
by: phpnewbie26 | last post by:
So my goal is actually to use the in_array function but I believe it searches for a string within an array. My problem is that I explode a line and my data is now in an array. I'm hoping to change...
2
by: ram712 | last post by:
hi, In sheet each cell is define with pre-defined formula. what i need is to change all the formulae in each cell when i create a copy of these existing worksheets.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.