Jump to content

Archived

This topic is now archived and is closed to further replies.

scottrohe

Howto extract rows from a text type?

Recommended Posts

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;
[code]
  function displayFavorites(){
      $q = "SELECT * FROM ".TBL_USERS." ORDER BY favorites";
      $result = mysql_query($q);
      while($rows=mysql_fetch_array($result))
      {
      $this->display_favorites = $rows['favorites'].", ";
      }
[/code]
and anything else i could think of.. lol. help please!

Share this post


Link to post
Share on other sites
.. 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.

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

Share this post


Link to post
Share on other sites
Yeah, definitely stay away from storing lists in single database columns, unless you never need to edit them.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.