/    Sign up×
Community /Pin to ProfileBookmark

Pulling info from database, also getting extra spaces?!

When I get data from my database and display it in a formfield so they can update the record, I am getting the record info fine, but have tones of trailing spaces. Am I doing something wrong?

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriOct 27.2004 — dont know, unless i see your code :rolleyes:
Copy linkTweet thisAlerts:
@d_brandusaauthorOct 27.2004 — [code=php]
<?php

//Database Connection
include('../../includes/msql/sql_connection.php');

//Select From Database
$conn = odbc_connect($db, $user, $pass);

if(isset($_GET["id"]) && !empty($_GET["id"])) {

$id = $_GET["id"];

$query = "SELECT * FROM pcfd_roster WHERE ID = '" . $id . "'";

$result=odbc_do($conn, $query);
?>
[/code]


[code=php]
<?php

while($myrow=odbc_fetch_array($result)) {

echo('

<table border="0" width="499" height="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="499" height="15"></td>
</tr>
<tr>
<td width="499" height="20"><font size="2"><b>Company Name:</b></font> <input name="Company_Name" value="'.$myrow['Company_Name'].'"></td>
</tr>
</table>
');

}

}

?>
[/code]
Copy linkTweet thisAlerts:
@96turnerriOct 27.2004 — you get excess whitespace with that code? hmm thats odd change

[code=php]$myrow['Company_Name'][/code]
for
[code=php]preg_replace("/ /", "", $myrow['Company_Name'])[/code]
Copy linkTweet thisAlerts:
@pyroOct 27.2004 — [i]Originally posted by 96turnerri [/i]

[B]change

...

for

[code=php]preg_replace("/ /", "", $myrow['Company_Name'])[/code] [/B][/QUOTE]
You think that's a good idea? Replacing all spaces? I'd use [URL=http://www.php.net/manual/en/function.trim.php]trim[/URL], for multiple reasons...
Copy linkTweet thisAlerts:
@96turnerriOct 27.2004 — excuses excuses, and i got no excuse for not saying trim() i know, but i was posting that while i try to work out what is causing the problem (the whitespace), that would be a better fix

and o i just realised and i have slapped myself!, if

$myrow['Company_Name'] = " Infinity Web Design ";

after this

preg_replace("/ /", "", $myrow['Company_Name'])

would be

InfinityWebDesign

ooops, my bad
Copy linkTweet thisAlerts:
@d_brandusaauthorNov 06.2004 — I'm trying to pull data from a database like so:

[code=php]
//Organize Database Results
$ID = (''.$column['ID'].'');
$NT_Display_Name = (''.$column['NT_Display_Name'].'');
$Company_Payday = (''.$column['Company_Payday'].'');
$Company_Holiday = (''.$column['Company_Holiday'].'');
$Help_Desk = (''.$column['Help_Desk'].'');
}

//Display Organized Results
echo "ID: $ID<br>n";
echo "Username: $NT_Display_Name<br>n";
echo "View Company Payday: $Company_Payday<br>n";
echo "View Company Holiday: $Company_Holiday<br>n";
echo "View Live Helpdesk: $Help_Desk<p>n";
echo "Results Retrieved Successfully!n";
[/code]


How can I user "trim" when I'm organizing the results, or do I use trim when "echoing" the results, I've tried both but can't get it right, please help!
Copy linkTweet thisAlerts:
@d_brandusaauthorNov 06.2004 — Guess I spoke to soon, this worked perfect for me:

[code=php]
//Organize Database Results
$ID = trim(''.$column['ID'].'');
$NT_Display_Name = trim(''.$column['NT_Display_Name'].'');
$Company_Payday = trim(''.$column['Company_Payday'].'');
$Company_Holiday = trim(''.$column['Company_Holiday'].'');
$Help_Desk = trim(''.$column['Help_Desk'].'');
}
[/code]


The results echoed like this:

[code=php]
ID: 1<br>
Username: John Doe<br>
View Company Payday: Yes<br>
View Company Holiday: Yes<br>
View Live Helpdesk: Yes<p>
Results Retrieved Successfully!
[/code]
Copy linkTweet thisAlerts:
@96turnerriNov 07.2004 — congrats, but what are the <br> and <p> doing there? is that just forum formatting errors, or do your results display like that
Copy linkTweet thisAlerts:
@Paul_JrNov 07.2004 — [i]Originally posted by 96turnerri [/i]

[B]congrats, but what are the <br> and <p> doing there? is that just forum formatting errors, or do your results display like that [/B][/QUOTE]


[i]Originally posted by d.brandusa [/i]

[B][code=php]
//Display Organized Results
echo "ID: $ID<br>n";
echo "Username: $NT_Display_Name<br>n";
echo "View Company Payday: $Company_Payday<br>n";
echo "View Company Holiday: $Company_Holiday<br>n";
echo "View Live Helpdesk: $Help_Desk<p>n";
echo "Results Retrieved Successfully!n";
[/code]
[/B][/QUOTE]
×

Success!

Help @d_brandusa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...