Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Howto extract rows from "text" type? Help Pls!

    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'].", ";
          }
    and anything else i could think of.. lol. help please!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    welcome here!

    if i understand it correctly, then you want to turn a comma-seperated string into links?

    something like
    PHP Code:
    $arr_favorites explode (','$rows['favorites']);
    foreach(
    $arr_favorites as $favorite){
       echo 
    '<a href="'$favorite .'" title="link to favorite">blabla</a>';

    well, you don't say what should be the urls and message, but is suppose you get the idea...

    from a dba point of view, using composit values like your comma-separated sting for the favorites, is of course a verry bad practice.
    i personally would just create a nuw record for each favorite...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    by a new record, do you mean.. a new database, then add each user to that new database upon registration and have it create x amount of favorites for the amount they have?

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by scottrohe
    by a new record, do you mean.. a new database,
    no. a record is just a line (a row) in a database-table.
    you'd normally have a table with your users in (1 row for each user) and then you'd have a table with your favorites in (1 row for each favorite-user combination.) like

    usertable:
    userID | user_name | user_pwd | ...

    favorites:
    favoritID | userID | fav_url | ...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah yes, that would indeed be better. if users have a ton of favorites and they are all listed 1 favorite/row and there is a ton of rows, is it still effecient?
    thanks again.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by scottrohe
    ah yes, that would indeed be better. if users have a ton of favorites and they are all listed 1 favorite/row and there is a ton of rows, is it still effecient?
    thanks again.
    if you create indexes on the userID columns + if you keep your columntypes as small as possble, then you shouldn't notice any performance-issues until you have around 2°° records. i don' think you'll ever reach that number, and even then, id would just be a matter of a second to get the records from the table.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •