Jump to content

php code needed in displaying the datas frm db in a new line


bindiya

Recommended Posts

I hav a php page which takes data from the db.But the problem i am facing is for a particular fild in database ,i have long data,which i need to b displayed in a wordwrap way

 

eg my data is " Description      need a site for school    gave order on 12-10-2010    work started on 12-10-2010  "

this shuld  be displayed as

"Description      need a site for school

                        gave order on 12-10-2010

                        work started on 12-10-2010"

 

Description is the field in the database and rest of them are the datas in it

 

Link to comment
Share on other sites

$sql = "select * from product where reference_no = '".$reference_no."'";

    $sqlquery = mysql_query($sql);

    $sql_project_fetch_array =mysql_fetch_array($sqlquery);

echo "<table><tr>

  <td class="tableCellOne"> </td>

<td class="tableCellOne">Description</td>

<td class="tableCellOne">

<?php echo str_replace("<p>"," ",$sql_project_fetch_array['description']); ?></td>

</tr>

Link to comment
Share on other sites

You need to print more table rows.

 

echo "<table><tr>
  <td class="tableCellOne"> </td></tr>
<tr><td class="tableCellOne">Description</td></tr>
<tr><td class="tableCellOne">
<?php echo str_replace("<p>"," ",$sql_project_fetch_array['description']); ?></td>
</tr>

 

Denno

Link to comment
Share on other sites

Well you are printing one row(<tr> </tr>), and then 3 cells (<td> </td>). This means they're all aligned horizontally on the same line.

You want to print your data in a new cell, that's on a new row. I added <tr> </tr> tags to fix this.

 

You will get the format of

"Description      need a site for school

                        gave order on 12-10-2010

                        work started on 12-10-2010"

Using this code.

 

Denno

Link to comment
Share on other sites

understood ur code.but some doubt ,suppose there are more lines of description for some id(another field,a primary key).Then how will i use this code?

eg

 

id                          description (no of rows)

1                        4 rows are there

2                        1  row only

3                        8 rows

 

Link to comment
Share on other sites

echo "<table>
<tr><td>id</td> <td class="tableCellOne">Description</td></tr>
<tr><td>1</td> <td class="tableCellOne">4 rows are there</td></tr>
<tr><td>2</td> <td class="tableCellOne">1 row only</td></tr>
<tr><td>3</td> <td class="tableCellOne">8 rows</td></tr>
</table>"

 

You'll notice that now there is two sets of <td> </td> between each <tr> </tr> tag. This means 2 cells on one row.

 

I just did a google search for online HTML table generator. Look at this link and it will generate the code you need for a X column by Y rows.

http://www.quackit.com/html/html_table_generator.cfm

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.