stig1 Posted May 5, 2009 Share Posted May 5, 2009 I have set up a table that using a varchar field. In phpmyadmin, i add data, however, when i retrieve the data, it puts extra spaces at the end for some reason? It never use to. I am using mysql 5. So for example i would have a varchar(10) field and i would have the following inserted via phpmyadmin SHOPBAGS but when i extract it via php I get SHOPBAGS 2 Spaces at the end.. so my url looks like the following: browse.php?st=SHOPBAGS " It happens on all the data in my database, and i do have varchar(10) field as a primary key, would that matter? Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/ Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Did you type a space when you entered it into the DB? Sometimes people type a space without knowing it because they are used to pressing the space bar so much. Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/#findComment-826512 Share on other sites More sharing options...
stig1 Posted May 5, 2009 Author Share Posted May 5, 2009 No I didn't type a space, as when i go to look at the data in phpMyAdmin, it looks exactly how i typed it, no spaces. Another one of my varchar field holding item information, which is a primary key also has extra spaces to make 15 characters all the time, even if i only type in 5. i didnt use to have this issue.. Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/#findComment-826514 Share on other sites More sharing options...
Daniel0 Posted May 5, 2009 Share Posted May 5, 2009 Show us some code... Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/#findComment-826524 Share on other sites More sharing options...
stig1 Posted May 5, 2009 Author Share Posted May 5, 2009 <?php $x = "select subtype from subtypsec where prodtype = '$ptID' and division = '$divnID' order by sequence asc, subtype asc"; $xresult = $mysql->query($x); while ($subtypelist = mysql_fetch_array($xresult)){ $stID = $subtypelist['subtype']; $st = "select descript from prdchgsub where subtype = '$stID'"; $st_result = $mysql->query($st); $st_row = mysql_fetch_row($st_result); $subtype = $st_row[0]; ?> <li> <a href="browse.php?pt=<?=$ptID;?>&st=<?=$stID;?>" title="<?= $subtype; ?>"><?= $subtype; ?></a> </li> <?php } ?> I can put in rtrim() and it will fix it up.. however, I didn't have to do that before on the old database, the new database is exact same fields. Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/#findComment-826532 Share on other sites More sharing options...
stig1 Posted May 5, 2009 Author Share Posted May 5, 2009 SOLVED... I was working / looking at the wrong table, its the data i imported from another database system put spaces in automatically. Link to comment https://forums.phpfreaks.com/topic/156892-extra-spaces-at-end-of-data-retrivial-using-varchar/#findComment-826533 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.