Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2006, 01:59 PM   PM User | #1
scottrohe
New to the CF scene

 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
scottrohe is an unknown quantity at this point
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!
scottrohe is offline   Reply With Quote
Old 07-29-2006, 03:53 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
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
raf is offline   Reply With Quote
Old 07-31-2006, 03:12 AM   PM User | #3
scottrohe
New to the CF scene

 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
scottrohe is an unknown quantity at this point
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?
scottrohe is offline   Reply With Quote
Old 07-31-2006, 07:36 AM   PM User | #4
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
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
raf is offline   Reply With Quote
Old 08-01-2006, 09:01 AM   PM User | #5
scottrohe
New to the CF scene

 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
scottrohe is an unknown quantity at this point
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.
scottrohe is offline   Reply With Quote
Old 08-01-2006, 09:08 AM   PM User | #6
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
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
raf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 06:15 AM.


Advertisement
Log in to turn off these ads.