[MYSQL] problem with spaces in rows


 
Thread Tools Search this Thread
Top Forums Web Development [MYSQL] problem with spaces in rows
# 8  
Old 02-21-2010
Hmm....

Hmm.. I wonder...could this have something to do with it all?
What I did change yesterday, was to make sure the spaces gets sent, BUT, these are changed %20

Could it by any chance be that the null results I am getting, is simply because when it is written to the database, it gets written as "Foxy%20Hollow".
If so, do you have any suggestions on how to get arount this?
Because as far as I know, it will either gets sent as "FoxyHollow" or "Foxy%20Hollow".
(I course make it so that it will be "Foxy<any char>Hollow" aswell, could I in the register.php change the <any char> before sending it to the database? And in that case, how?)

When I look in the phpMyAdmin interface, I see them as it should be, with blanks, not %20.. I havn't actually checked in the console yet.

---------- Post updated at 12:00 PM ---------- Previous update was at 11:40 AM ----------

I have to apologize again to anyone that have tried to helo me so far.. to see exactly what was going in to the database, I checked the logs of http-access....
All entries have (up untill now) gotten entered as "%20Venue%20Name" so all of them had a blank space in front of them.. no wonder I never found them when trying WHERE venue = 'Foxy Hollow".. it didn't exist.

Problem solved, thank you! Smilie

---------- Post updated at 12:35 PM ---------- Previous update was at 12:34 PM ----------

Ok, one more problem.. (hope you guys arn't fed up with me yet) Smilie

I have managed to strip it all diwn, as I said earlier, from "%20Venue%20Name" to "Venue%20Name". But, I just detected something else...

If the registered venue name is for example "Foxy Hollow" (Foxy%20%20%20Hollow) I get the same kind of error, it can't be found as I only get "Foxy%20Hollow" outputed in my dropdown menu.

Is there a way to already at the point of inserting the values in the database, reduce the blanks. So that if I get a value like "This%20Venue%20%20Name%20Is%20%20%20Long" in the $_POST[venue] variable in register.php, it can get reduced to "This%20Venue%20Name%20Is%20Long". I guess the answer is str_replace. If I knew how many blanks there were, I wouldn't have any problems with this. But I have no way of knowing the exact amount of blanks will be used in the name, so I have no clue of how to use str_replace for this.

I mean, str_replace(' ', ' '); would only convert two blanks into one, right?
# 9  
Old 02-21-2010
I recommend you use preg_replace() with a regular expression to remove any leading, trailing and "more than one space in the middle" of your string. This is really easy to do with one PHP preg_replace() statement. Or you could use more than one preg_replace() if easier for you at first, breaking the problem down into parts first.
# 10  
Old 02-21-2010
Thank you Neo. Smilie

A few minutes after I send the post, I got a friend online who suggested this:

PHP Code:
$venue $_GET[venue];
$venue trim(ereg_replace(' +'' '$venue)); 
which seems to work pretty good Smilie

Ofcourse, this doesn't remove leading and trailing spaces, but I managed to fix that in the code that is actually sending the http-request. Unfortunately that coding language is quite limited and won't remove the extra spaces in between words on an very efficient way. Smilie
# 11  
Old 02-21-2010
trim() will remove leading and trailing spaces.

PS: I suggest you do a bit of your own research before posting. For example, at a minimum look at the PHP man pages of the commands you are using!

Also, this:


PHP Code:
$venue $_GET[venue]; 
should be

PHP Code:
$venue $_GET['venue']; 
... for faster execution time.

I will leave it to you as an exercise to Google the net and find out why.

And please, do more of your own research before asking questions Smilie

If you get in the habit of looking at your log files when trouble shooting a problem, and also reading, at a minimum, the man pages of the PHP commands you are using, you will find that you actually will save more time v. less time.

Edit: I closed this thread because it is not related to MySQL; it is related to poor string formatting. If you wish to work on PHP string formatting, please start a new thread on a specific issue. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mysql: How to update value in 27000 rows?

Hello, some member created 27000 posts in wrong section (lol :D) so i need to edit all his entries to get new section ID. SELECT * FROM `phpbb_topics` WHERE `topic_first_poster_name` LIKE "%ozerway%"; this will select all his topics... the column with forum id is named "forum_id" and... (3 Replies)
Discussion started by: postcd
3 Replies

2. Shell Programming and Scripting

MySql split rows

Dear community, I have to split string in table and list all values. I'll skip the code and jump directly to mysql query. This is the table: category title ======= ======= 7,3 title 1 1,3 title 2 1,2,3 title 3 Now, what I need is split category into single... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

3. Shell Programming and Scripting

Retrieve multiple rows from mysql and automatically create a table

Hi, i want to create a table automatically based on another table (sms_key). For example; If user create a new row with sms_keyword field: IRC then a table created automatically (with some field on it, like: name, ph_number, messages). select * from sms_key; +-------------+ |... (1 Reply)
Discussion started by: jazzyzha
1 Replies

4. UNIX for Dummies Questions & Answers

[SOLVED] splitting a single column(with spaces) into multiple rows

Hi All, My requisite is to split a single column of phonemes seperated by spaces into multiple rows. my input file is: a dh u th a qn ch A v U r k my o/p should be like: adhu a dh u (3 Replies)
Discussion started by: girlofgenuine
3 Replies

5. Programming

Getting Rows from a MySQL Table with max values?

I feel stupid for asking this because it seems that MYSQL code isn't working the way that I think it should work. Basically I wrote code like this: select * from `Test_DC_Trailer` HAVING max(DR_RefKey); Where the DR_RefKey is a unique numeric field that is auto iterated (like a primary key)... (7 Replies)
Discussion started by: Astrocloud
7 Replies

6. UNIX and Linux Applications

Online insert MySQL rows by perl-script

Hello, Met a problem when I tried to insert rows to MySQL database from an old book that fits my learning level (MySQL and Perl for the Web, by Paul DuBois, 2001). First, under mysql console I created a database: webdb and the table: todo. Then I draft the perl-cgi script to have online page.... (0 Replies)
Discussion started by: yifangt
0 Replies

7. Shell Programming and Scripting

convert rows (with spaces) to columns

Hey all, I have a list in the format ; variable length with spaces more variable information some more variable information and I would like to transform that 'column' into rows ; variable length with spaces more variable information some more variable information Any... (8 Replies)
Discussion started by: TAPE
8 Replies

8. Web Development

Mysql question: Best way to update a column containing 8 million rows

Hi all, I was wondering if anyone knew a good/safe way to update a single column in a table that could contain upto 8 million rows... simple command like: UPDATE set blah=foo where bar=XXX; I will be running this on tables being written to and tables that have already been created. ... (3 Replies)
Discussion started by: muay_tb
3 Replies

9. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies

10. UNIX for Advanced & Expert Users

MySQL problem >> missing mysql.sock

MySQL on my server is down.... I figured out that the mysqld process isn't running. When I try to run it, it says it can't find mysql.sock Any suggestions? Here's what I can't do: can't be root don't have physical access (do stuff via SSH) reinstall MySQL (need to keep the current MySQL... (8 Replies)
Discussion started by: _hp_
8 Replies
Login or Register to Ask a Question