Jump to content


Howto extract rows from a text type?

  • Please log in to reply
2 replies to this topic

#1 scottrohe

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 29 July 2006 - 12:49 PM

Ok so ive been tryin to figure it out all night and i cant. Im trying to extract from a "Text" value box in mysql, but when it comes out it comes like.. blah, blah2, blah3.. or however i enter it into the box. i want it to come out so i can make each blah have an href.. is it possible or what would i do to do something like it? the purpose for it is for a "favorites" system, where the user clicks add to favorites, it simply adds the products ID to the text box "favorites" in mysql..hopefuly i explained clearly enough. ive tried stuff like;
   function displayFavorites(){
      $q = "SELECT * FROM ".TBL_USERS." ORDER BY favorites";
      $result = mysql_query($q);
      $this->display_favorites = $rows['favorites'].", ";
and anything else i could think of.. lol. help please!

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 July 2006 - 02:34 PM

.. and where would each blah get it's href from???

It might be much better database design to have each blah AND its href as a single row in the database, rather than having to retrieve and post-process the field contents. 

If instead (and it's a weaker solution) you want to have a single database record with multiple pieces of data like blah, blah1, blah2 then you can separate lines by splitting the parts into array elements.

$blahs = explode("," $blah_from_database); // produces array of all blah elements

Legend has it that reading the manual never killed anyone.
My site

#3 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 29 July 2006 - 03:08 PM

Yeah, definitely stay away from storing lists in single database columns, unless you never need to edit them.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users