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
Please I need help reading a mySQL table
Old 08-28-2007, 03:49 AM Please I need help reading a mySQL table
Average Talker

Posts: 18
Name: Richard Thomas
Trades: 0
I have inherited a Joomla website that has used a guestbook component to record a petition. Whilst visitors have left their address, it is not readable from the component and I need to recover it from the mySQL database.

I only have a rudimentary understanding of php, and urgently need help with a bit of code that will read the tables back to an excel spreadsheet, or at least to a readable document of some sort.

This is the table and field headings:

`jos_easygb` (`id`, `date`, `content`, `name`, `email`, `homepage`, `rating`, `ip`, `browser`, `published`, `address`)

It would be easy to import it directly into excel because the fields are all nicely comma delimited. But the 'address' field is not. It is one field, and here are two records, 34 and 35, suitably anonymised with personal details changed:

(34, '2007-08-16 04:17:16', 'Worcestershire', 'Joe Bloggs', 'joebloggs@hotmail.com', '', 0, '81.77.182.131', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.12) Gecko/20000578 Firefox/1.5.0.12', 1, '22 Bosley Common\r\nBosley Kings\r\nStourport-on-Severn\r\nWorcestershire\r\nBG24 !RT'),
(35, '2007-08-16 05:15:58', 'Street North Somerset', 'Sally Barton', 'bartonsb@tiscali.co.uk', '', 0, '188.06.14.188', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; FREESERVE_IE5; .NET CLR 1.1.4322)', 1, 'The Old Poorhouse\r\nLittle Pudding Road\r\nBarton\r\nBristol\r\nBR32 7GR'),

The address lines are separated by \r\n

I know its a big ask, but would someone be willing to write a bit of code that will read these back to an excel spreadsheet, or even a simple document, so that the address is readable?

Richard
rpthomas is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-28-2007, 05:26 AM Re: Please I need help reading a mySQL table
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I don't have time right now, but you can simply replace those characters.

\r means "carriage return"
\n means "new line"

It's the code that windows send when you hit the enter key.
If you are more comfortable in excel, you could do a macro that will remove them and replace them by a space.
Or in php you can use str_replace
PHP Code:

$q
="SELECT * FROM jos_easygb";
$r=mysql_query($q);
while(
$o=mysql_fetch_object($r)){
  
$adr=str_replace('\r',' ',$o->address);
  
$adr=str_replace('\n','',$adr);
  
//And now, $adr contains the address only, without the \r\n junk
  //You can do whatever you want with it...

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-28-2007, 08:06 AM Re: Please I need help reading a mySQL table
Experienced Talker

Posts: 33
Trades: 0
Do a google on "php csv" and you'll find lots of scriptlets for generating csv files from php. You might also just do a search on "csv mysql" and do the dump outside of php if you have direct access to the data.

In case I missed a step in the explanation: csv files are readable by Excel.
__________________

Please login or register to view this content. Registration is FREE
- FREE Directory of Freelance Consultants - Are You In It?
FreelanceMan is offline
Reply With Quote
View Public Profile
 
Old 08-29-2007, 09:20 AM Re: Please I need help reading a mySQL table
Experienced Talker

Posts: 44
Name: Kuldeep Sahi
Trades: 0
You can remove these while exporting the data itself. In your phpmyadmin, when you select a table for export, select CSV, and on the right you will see an Option " Lines terminated by". Remove the "\r\n" against it and replace it with a Space. This should achieve the effect of replacing all newlines with Space in stead of "\r\n".
Kuldeep2195 is offline
Reply With Quote
View Public Profile Visit Kuldeep2195's homepage!
 
Reply     « Reply to Please I need help reading a mySQL table
 

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.60153 seconds with 12 queries