Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace text in loop

I can’t implement auto-replacement of text in the loop. The text is either not replaced, or is replaced randomly and not in the whole loop.
Help, please.

<?php  
 $connect = mysqli_connect("localhost", "111", "password", "222");  
 $query1 ="SELECT * FROM beta ORDER BY ID DESC"; 
 $result1 = mysqli_query($connect, $query1);
?> 
<script type="text/javascript">
$(document).ready(function() {
$("cost").html($("cost").html().replace('One', 'Two'));
});  
</script>
<cost>
<div class="table-responsive">
<table id="employee_data" class="row-border order-column cell-border hover">
<thead>
<tr>
<th>Name</th>  
<th width="10%">1</th>
<th width="10%">2</th>
<th width="10%">3</th>
<th width="10%">4</th>
<th width="10%">5</th>
<th width="10%">6</th>
</tr>
</thead>
<?php
while($row1 = mysqli_fetch_array($result1))
{
echo '
<tr>
<td><font face="Verdana">'.$row1["name"].'</font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["len"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["len"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["myt"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["myt"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["tr"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["tr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["kr"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["var"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["var"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["kor"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kor"].'" /></font></td>
</tr>
';  
}
?>
</table>
</div>
</cost>

The word "One" between <cost></cost> must be replaced by "Two".

Don’t judge me too harshly, I’m new at this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Big thnx!

>Solution :

You can use it from the php side using str_replace function

https://www.php.net/manual/en/function.str-replace.php

<?php
while($row1 = mysqli_fetch_array($result1))
{
echo '
<tr>
<td><font face="Verdana">'.$row1["name"].'</font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["len"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["len"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["myt"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["myt"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["tr"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["tr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["kr"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["var"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["var"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["kor"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kor"].'" /></font></td>
</tr>
';  
}
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading