Page 1 of 1

select part of a word (rookie)

Posted: Thu Jun 12, 2008 5:46 pm
by tdavid
Howdy!

Warning! Totally rookie here. :)

I have a field in our member database, called 'latta'. it's values are usually
|||31--jan 21, 2008|||33--jan 22, 2008|||31--jan 24, 2008|||

I can grab this and explode it like this (I think, so far it worked):

Code: Select all

 
$sql = mysql_query("SELECT * FROM wsnlinks_members WHERE latta LIKE '|||31%'");  
$rowdetail = mysql_fetch_array($sql);
$data  = $rowdetail['latta'];
$pieces = explode("|||", $data);
print $pieces[1];
print $pieces[2];
 
My problem is that I need to print only the pieces that match '31%'. So using the above example, I would like to print only:
31--jan 21, 2008
31--jan 24, 2008

How can this be done?

On another note, is there a way to strip the '31--' parts before actually printing the results?

Thanks for any help, or pointers to samples dealing with something similar. Since I am not an actual php programmer (yet), I don't even know what to search for exactly for this problem. :)

Thanks again
David T.

Re: select part of a word (rookie)

Posted: Thu Jun 12, 2008 6:38 pm
by Christopher
You could use the MySQL SUBSTR() function or the PHP substr() function. Check the manuals for each.

Re: select part of a word (rookie)

Posted: Thu Jun 12, 2008 6:39 pm
by nincha
use the function strstr to check

Re: select part of a word (rookie)

Posted: Thu Jun 12, 2008 6:46 pm
by tdavid
Hi guys!

Thanks for the help. I will do my research on those, and will let you know. :)

Thanks
David