PHP question stuck

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

souled
New php-forum User
New php-forum User
Posts: 1
Joined: Fri May 03, 2013 4:52 pm

PHP question stuck

Postby souled » Fri May 03, 2013 4:57 pm

Good day fellow programmers.

I'm stuck in this question for days.
From my code below, I have to traverse the array and show the output, however, I have to break it to the next line everytime I hit the $multiple(which is the row&column limit according to the number of words i type)

My output is always the values in a straight line, or they will space out first then place my values at the bottom of the page.

<html>
<head>
<title>exploded</title>
</head>
<body>
<h1>Here are the exploded words</h1>
<table border="1">
<?php
$words = $_POST["words"];
$wordsArray = explode(",",$words);
$count=0;
for($i=0;$i<count($wordsArray);$i++)
{
$count++;
}
print"$count<br/>";

$r = $count;
$c = sqrt($r);
$multiple = ceil($c);

print("$multiple");



for($a=0;$a<count($wordsArray);$a++)
{
print"<td>$wordsArray[$a]</td>";
}
?>
</table>
</body>
</html>



Please help!

swarups
New php-forum User
New php-forum User
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm

Re: PHP question stuck

Postby swarups » Sun May 12, 2013 10:27 pm

Hi,

To have a break after each word, you have two option as described below:

1. Add a '<br />' after the word. like print"<td>$wordsArray[$a]<br /></td>";
2. Display each word in a single row. Like print"<tr><td>$wordsArray[$a]<br /></td></tr>";


Thanks
Swarup sahu
http://www.mindfiresolutions.com/


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests