Split data line by line and add transverse lime between then

Dharmeshdhabu

New member
I have text data in php database. I want to separate it line by line and add transverse line between them while printing in a table. Please guide me.
 
Can you post any example?
You can split the text by the explode function and split the array again to the text with the implode function
 
Michalio said:
Can you post any example?
You can split the text by the explode function and split the array again to the text with the implode function

Yes, sure. Below is my cose. Here $treatment contains multiple lines/paragraphs. I want to draw horizontal line after each line of data.

Code:
<td align="left" colspan="3">
									<br>
									<h5 style="white-space: pre-wrap;"><?php echo $Treatment; ?></h5>
								
								</td>
Little more code for your refference.

Code:
<table style="width: 100%;" border="1" >
							<style>
								

								table5 {
								  border-collapse: collapse;
								  width: 100%;
								}

								th, td {
								  padding: 7px;
								  font-size:12px;
								}
							</style>
							
							
							
							<tr>
								<td align="center" colspan="3">
								<label>Treatment: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								
								
							</tr>
							
							<tr>
								<td align="left" colspan="3">
									<br>
									<h5 style="white-space: pre-wrap;"><?php echo $Treatment; ?></h5>
								
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								
								<td align="center" colspan="1">
								<label></label>
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								
								
							</tr>
							
							
							<tr>
								<td colspan="7">
								<label>Advise: </label>
									<br>
									<h5 style="white-space: pre-wrap;"><?php echo $Advise; ?></h5>
								</td>
							
							</tr>
							
							</table>
 
Michalio said:
Try to use
Code:
str_replace("\n", '<hr>', $Treatment);

Wonderful. It worked nice. I want to extend same line in "Time" column but here there is no data. If you see the code, I have placed blank label in this place. Is it possible to extend that line across table end to end? May be some other idea. Please suggest. Also line leaves some space at start and end which I wants to avoid. Below is my code.
Code:
<td align="left" colspan="3">
									<br>
									<h5 style="white-space: pre-wrap;"><?php echo str_replace("\n", '<hr style="border-top: 1px solid #000;>', $Treatment); ?></h5>
								
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
 
Michalio said:
Why cannot you use the if statement to check thet the Time can be formatted?

You misunderstood. Actually I want to keep blank space where time can be written manually. Actually this is for printing. Only thing is that in medicine column I have list of 8-10 lines. Opposite to that time column is blank. I wish to draw horizontal line across table after each line of medicine.
 
Can you paste here an example of the value that you have and what it should be after formatting? It will be easier to imagine how it exactly should works
 
Michalio said:
Can you paste here an example of the value that you have and what it should be after formatting? It will be easier to imagine how it exactly should works

Actually there is no data. I wish to just draw a transverse line. That's all. Below is my complete code of page for your reference.

Code:
<?php
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
	header('Location: index.php');
	exit;
}
?>
<?php 
include('ipd_data.php');
include('menu.php');
include "db_conn.php";
	

	if (isset($_GET['view'])) {
		$ID = $_GET['view'];
		$update = true;
		$result = mysqli_query($conn, "SELECT * FROM treatment WHERE ID=$ID");

		//if (count($record) == 1 ) {
			$n = mysqli_fetch_array($result);
			$ID = $n['ID'];
			$RegNo = $n['RegNo'];
			$Date = $n['Date'];
			$Name = $n['Name'];
			$Sex = $n['Sex'];
			$Age = $n['Age'];
			$IPNo = $n['IPNo'];
			$Advise = $n['Advise'];
			$Ward = $n['Ward'];
			$Treatment = $n['Treatment'];

		//}

	}
		
?>






<!DOCTYPE html>

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>OPD Bill</title>

    
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	
	    
    <link href="vendor/datatables-plugins/dataTables.bootstrap.css" rel="styletabel">

    
    <link href="vendor/datatables-responsive/dataTables.responsive.css" rel="styletabel">

	
	<style>
	@media print {
  #printPageButton {
    display: none;
  }
}
	</style>

</head>


<body>

    <div id="wrapper">

       
	 <center>   
	<button class="btn btn-danger" onClick="window.print();"  id="printPageButton" >Print This Page</button>      
	<button class="btn btn-warning" onclick="window.location='ipd.php'"  id="printPageButton" >Go Back IPD</button>
     </center>
      
        <div id="page-wrapper">
        
            
            <div class="row">
			
			<div class="col-lg-12" style="padding-top:30px;">
                    <div class="row" style="padding-left:50px; padding-right:50px;">
                     
						
                      	<div class="form-group">
                            
							<table style="width: 100%;" border="1" >
							<style>
								

								table2 {
								  border-collapse: collapse;
								  width: 100%;
								}

								th, td {
								  padding: 7px;
								  font-size:12px;
								}
							</style>
							
							<tr>
								<td align="center"  colspan="3">
									<h2>Ratanba Multispeciality Hospital</h2>
									
								</td>
							</tr>
							<tr>
								<td align="center"  colspan="3">
										Near Dev ICU, Behind Doctor House, Palanpur-385001,ph.02742-250108 
								</td>
							</tr>
							
							<tr>
								<td align="center"  colspan="3">
										<h4>IPD Treatment Sheet</h4>
								</td>
							</tr>
							
							
							<tr>
								<td>
									
								</td>
								<td align="right" size='4pt'>
										<label>Date: </label>
										<label name="Date" size='4pt'> <?php echo $Date = date("d/m/Y",strtotime($Date)); ?></label>
								</td>
							</tr>
							<tr>
								<td>
									<label>Reg No.: </label>
									<label name="RegNo" > <?php echo $RegNo; ?></label>
								</td>
								<td align="right">
										<label name="IPNo">IPNo: <?php echo $IPNo; ?> </label>
							
										
									
								</td>
							</tr>
							
							<tr>
								<td>
									
									<label>Patient Name: </label>
									<label name="Name" > <?php echo $Name; ?></label>
								</td>
								<td align="right">
								<label name="Age"><label>Age / Sex: </label> <?php echo $Age; ?> / <?php echo $Sex; ?></label>
								
							</tr>
							
							<tr>
								<td>
									<label>Consultant: Dr Dharmesh Prajapati </label>
									
								</td>
								<td align="right">
								
								<label name="Ward"><label>Ward: </label> <?php echo $Ward; ?></label>
												
									
								</td>
								
							</tr>
							
							</table>
							<table style="width: 100%;" border="1" >
							<style>
								

								table5 {
								  border-collapse: collapse;
								  width: 100%;
								}

								th, td {
								  padding: 7px;
								  font-size:12px;
								}
							</style>
							
							
							
							<tr>
								<td align="center" colspan="3">
								<label>Treatment: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								
								<td align="center" colspan="1">
								<label>Time: </label>
								</td>
								
								
							</tr>
							
							<tr>
								<td align="left" colspan="3">
									
									<h6 style="white-space: pre-wrap;"><?php echo str_replace("\n", '<hr style="border-top: 1px solid #000;>', $Treatment); ?></h6>
								
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								
								<td align="center" colspan="1">
								<label></label>
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								<td align="center" colspan="1">
								<label></label>
								</td>
								
								
							</tr>
							
							
							<tr>
								<td colspan="7">
								<label>Advise: </label>
									<br>
									<h6 style="white-space: pre-wrap;"><?php echo $Advise; ?></>
								</td>
							
							</tr>
							
							</table>
							<table style="width: 100%;" border="1" >
							<style>
								

								table6 {
								  border-collapse: collapse;
								  width: 100%;
								}

								th, td {
								  padding: 7px;
								  font-size:12px;
								}
							</style>
							
							<tr>
								<td align="left" colspan="1">
								<label>Input: </label>
								</td>
								<td align="left" colspan="1">
								<label>Day: </label>
								</td>
								<td align="left" colspan="1">
								<label>Night: </label>
								</td>
								
								<td align="left" colspan="1">
								<label>Output: </label>
								</td>
								<td align="left" colspan="1">
								<label>Day: </label>
								</td>
								<td align="left" colspan="1">
								<label>Night: </label>
								</td>
								
								
							</tr>
							
							<tr>
								<td align="left" colspan="1">
								<label>Oral/RT/FJ: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								<td align="left" colspan="1">
								<label>Urine: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
							</tr>
							<tr>
								<td align="left" colspan="1">
								<label>IV Fluid: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								<td align="left" colspan="1">
								<label>RT Aspiration: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
							</tr>
							<tr>
								<td align="left" colspan="1">
								<label>Other: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								<td align="left" colspan="1">
								<label>Drain: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								
							</tr>
							<tr>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								<td align="left" colspan="1">
								<label>Other: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								
							</tr>
							<tr>
								<td align="left" colspan="1">
								<label>Total: </label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								
							</tr>
							
							<tr>
								<td align="left" colspan="1">
								<label>Fluid Balance: Input-Output </label>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
								</td>
								<td align="left" colspan="1">
								<label></label>
								</td>
								
							</tr>
							
							
							
							
							
							<tr>
								<td colspan="6" align="right">
									<label>Dr Dharmesh Prajapati</label></br>
									<label>Ratanba MultiSpeciality Hospital</label>
								</td>
							
							</tr>
							
							
							
							
							
							
							</table>
							
									
							
							
										
							
                    </div>

                    </div>
                    
                </div>
                
		</div>
                    
    </div>
          
    

    
    <script src="../vendor/jquery/jquery.min.js"></script>

    
    <script src="../vendor/bootstrap/js/bootstrap.min.js"></script>

    
    <script src="../vendor/metisMenu/metisMenu.min.js"></script>

    
    <script src="../dist/js/sb-admin-2.js"></script>
	
	 <script>
    // tooltip demo
    $('.tooltip-demo').tooltip({
        selector: "[data-toggle=tooltip]",
        container: "body"
    })
    // popover demo
    $("[data-toggle=popover]")
        .popover()
    </script>
	
	 
    <script src="../vendor/datatables/js/jquery.dataTables.min.js"></script>
    <script src="../vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="../vendor/datatables-responsive/dataTables.responsive.js"></script>

    
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
    </script>


</body>

</html>
 
I don't get it, if there is no data then just add something like <td>-</td> (or add empty cell and add some css for td:empty), but if the value should depends on the value from database then add some mock data for testing.
Should the line be displayed when there is no value? You can do it with simple if statement.
 
Michalio said:
I don't get it, if there is no data then just add something like <td>-</td> (or add empty cell and add some css for td:empty), but if the value should depends on the value from database then add some mock data for testing.
Should the line be displayed when there is no value? You can do it with simple if statement.

Well, what I want is a transverse line across table after each line of $treatment data. in treatment column I want treatment tobe displayed which you helped me with string replace replacing new line with br. In the next column I wish the same thing. Here I wish to replace new line with br as well all text tobe replaced with blank space. So you may consider that here also data is same $treatment and we need to use string replace. But only difference is that I want to replace all text with blank space as well new line with br. Please guide if there is a way to replace text with blank space.
 
I used following code to replace all character with blank space and the replaced new line with hr.

Code:
<h6 style="white-space: pre-wrap;"><?php $search = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '&', '?','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); 
								$replace = array( '');  $newTreatment =  str_replace($search, $replace, $Treatment); echo str_replace("\n", '<hr style="border-top: 1px solid #000;>', $newTreatment);?></h6>

This is a workable solution. What remains is a space between table border and hr. Please give me suggestion how can I add line from border to border.
 
Can you provide any example of any fake data how it will be before formatting and how it should like after that, I can imagine what are you trying to do.
Do you just want to add 5 <hr> elements if the Treatment contains 5 new line characters?
 
Michalio said:
Can you provide any example of any fake data how it will be before formatting and how it should like after that, I can imagine what are you trying to do.
Do you just want to add 5 <hr> elements if the Treatment contains 5 new line characters?

Sure, Below is a sample data for your reference. I wants fixed number of hr say 15 as usually there are less than 15 lines in data and so I want fix height of <tr> say 800px.

Inj RL 500ml with MVI 1amp IV BD

Inj DNS 500ml IV BD

Inj Ceftriaxone with Sulbactom 1.5gm with 100ml NS IV BD

Inj Netmicin 300mg IV OD

Inj Pantoprazole 40mg IV OD

Inj Ondensetraone 4mg IV BD

Inj Tramadole 100mg with 100ml NS IV BD

Inj Dexona 4mg IV OD

Tab Feliz S Plus HS

Tab Desvelnafexine 100mg OD

Tab Amitryptyline 10mg HS
 
Try to use
Code:
<div style="max-height: 800px;overflow: auto">the text</div>
These styles will works with the div element, but not with tr or td
 
Michalio said:
Try to use
Code:
<div style="max-height: 800px;overflow: auto">the text</div>
These styles will works with the div element, but not with tr or td

I used following code and fixed height is achieved.
Code:
	<tr style="height:700px">
								<td style="vertical-align:top" align="left" colspan="3">

What remains is to draw fixed no of lines. Please guide me how to achieve it. Thanks
 
So you can still use the code that I posted with small changes:
Code:
<div style="line-height: 1rem;max-height:8rem;overflow:hidden;">
In this div you can see up to 8 lines and all after that will be hidden
 
Michalio said:
So you can still use the code that I posted with small changes:
Code:
<div style="line-height: 1rem;max-height:8rem;overflow:hidden;">
In this div you can see up to 8 lines and all after that will be hidden

I tried your code various ways but it is not working. Perhaps I don't know where exactly to place <div> within table, tr, td. Also one more thing I needs 15 lines at minimum and not maximum. I want to allow more data but don't want to keep blank space at the end of page if data is small.
 
Back
Top