Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:53:20+00:00 2026-05-27T07:53:20+00:00

I have some php querying and printing the info of a mysql table on

  • 0

I have some php querying and printing the info of a mysql table on a medical recruitment website.
Sometimes the users enter, causing line breaks where I would rather not have them, because
it affects the layout of the rendered HTML table in a way that it shouldn’t.

I can trim the strings when they fill in the forms and the data get written into the table, but there’s already a lot of data there, so i decided to remove the line breaks on the page
where php reads and prints the results.

i declared one of the strings where this causes trouble as such:

$specialtr = trim($special, "\n"); 

and then where the html table gets rendered:

echo '<td width="150">' . $specialtr . '</td>'; 

Here is the whole code:

All the code works, it’s only the parts above that I added that now causes the column with $specialtr variable not to print/print as empty.

    <form action="selected.php" method="POST">
<table border="1" cellpadding="2" cellspacing="2" style="width: 98%; margin-left: auto; margin-right: auto;">
<tr>
<td>
<?php
$dbhost = 'xxx';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbname = 'xxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error($conn));
mysql_select_db($dbname) or die(mysql_error($conn));

$specialtr = trim($special, "\n");

echo '<table border="1" cellpadding="2" cellspacing="2" style="margin-left: auto; margin-right: auto;">';

$query = 'SELECT userid FROM employee
      ORDER BY userid ASC';
$result = mysql_query($query, $conn) or die(mysql_error($conn));

$num_entries = mysql_num_rows($result); 

while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $value) {
echo '<tr>';
echo '<td><input type="radio" name="employee" value="' . $row['userid'] . '"/></td>';
echo '<td>Select</td>';
}
}

echo '</tr>';
echo '</table>';

?>

</td>
<td>

<?php
echo '<table border="1" cellpadding="2" cellspacing="2" style="width: 98%; margin-left: auto; margin-right: auto;">';
echo '<tr>';
$query = 'SELECT userid, name, surname, sex, age, nationality, email, telnr, special FROM employee
      ORDER BY userid ASC';
$result = mysql_query($query, $conn) or die(mysql_error($conn));
while ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<td>' . $userid . '</td>';
echo '<td>' . $name . '</td>';
echo '<td>' . $surname . '</td>';
echo '<td>' . $sex . '</td>';
echo '<td>' . $age . '</td>';
echo '<td>' . $nationality . '</td>';
echo '<td>' . $email . '</td>';               
echo '<td>' . $telnr . '</td>';                
echo '<td width="150">' . $specialtr . '</td>';  
echo '</tr>';
}
echo '</table>';
?>

</td>
</tr>
</table>

<br/>
<br/>
<input type="submit" name="go" value="Go!" />
</form>

The code worked well enough, but since I added the trim, that entire column (the $special column disappears).

I hope maybe someone can tell me why it disappears or if my syntax has a little mistake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:53:20+00:00Added an answer on May 27, 2026 at 7:53 am

    Using extract() like that is a horrible thing. The function should be avoided as a general rule.

    Also note that you’re doing your trim() call BEFORE $special is defined, so your $specialtr variable is going to be an empty string. Calling the function before you start fetching your database results and extracting a result row into $special will not magically apply trim() to reach row you’ve fetched. If you want the results to be trimmed as you fetch them, then you have to apply the trim AFTER you do the fetch:

    while ($row = mysql_fetch_assoc($result)) {
        echo '<td>' . $row['userid'] . '</td>';
        ...
        echo '<td width="150">' . trim($row['special']) . '</td>';  
                                  ^^^^^^^^^^^^^^^^^^^^^
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PHP script for export MYSQL table into Excel format, but I
I have some PHP script querying a mysql database and echoing out a piece
I have some PHP code which: connects to mysql table retrieves results formats results
I have some php code that generates multiple MySql queries and combines the results.
I have some PHP code that generates dynamic tables of data on the fly.
I have some PHP code that is designed to make a spreadsheet with formulas
I have some PHP code that generates a calendar and then outputs html to
I have some php files in a server which generate xml code in them.
I have some PHP code which allows me to sort a column into ascending
I have some PHP code which stores whatever is typed in a textbox in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.