Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-12-2008, 12:43 PM mysql problem
Junior Talker

Posts: 3
Trades: 0
Please solve my mysql problem

I have field on mysql

ID | Title
------------
1 | Xxxx Yyyyy
2 | Www ZZZ

I need to change to

ID | Title
------------
1 | xxxx_yyyy
2 | www_zzzz

How to do it ?
lilianchen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-12-2008, 01:11 PM Re: mysql problem
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Use the ALTER TABLE function in MySQL. Also check if your host provides PHPMyAdmin, it's a MySQL maintenance script which you should find useful.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-12-2008, 03:34 PM Re: mysql problem
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Im assuming you want to replace all the spaces in the values with underscores..?

try...


PHP Code:

$res 
mysql_query("SELECT * FROM myTable");

while( 
$arr mysql_fetch_array($res) )
{
$ID $arr['ID'];
$Title str_replace(" ""_"$arr['Title']);

$res2 mysql_query("UPDATE myTable SET `Title` = '$Title' WHERE `ID`='$ID'");


Along those lines anyway - thats not tested or anything...
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 09-12-2008, 04:06 PM Re: mysql problem
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Actually, I think stoot98 has understood your question much better then me. Go for his answer
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-13-2008, 06:15 AM Re: mysql problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You don't need to go into PHP to do that

A very simple query in MySQL is all that is needed and would be a LOT quicker than fetching all the records in a loop then sending them back again.

UPDATE table SET title = lower(replace(title," ","_"))

Let the database do the the work. It's far more efficient at it.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-13-2008, 10:53 PM Re: mysql problem
Novice Talker

Posts: 7
Name: César
Location: MAYCHU.NET
Trades: 0
I think this problem has been solved nicely. The second is quite shortly complete.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
lovelycesar is offline
Reply With Quote
View Public Profile Visit lovelycesar's homepage!
 
Reply     « Reply to mysql problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48020 seconds with 12 queries