scottrohe
07-29-2006, 01:59 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);
while($rows=mysql_fetch_array($result))
{
$this->display_favorites = $rows['favorites'].", ";
}
and anything else i could think of.. lol. help please!
welcome here!
if i understand it correctly, then you want to turn a comma-seperated string into links?
something like
$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...
scottrohe
07-31-2006, 03:12 AM
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?
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 | ...
scottrohe
08-01-2006, 09:01 AM
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.
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.