PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > LIMIT and TEXT types.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
LIMIT and TEXT types.

Réponse
 
LinkBack Outils de la discussion
Vieux 13/10/2007, 05h12   #1
OutThisLife
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut LIMIT and TEXT types.

I've only been doing MySQL for a few weeks and I've run into a little
problem..

I have a column named tags and a column named name. I'm trying to find
the tags that are assigned to the name.

I've set the tag column to LONGTEXT as it will be used to store a
large list of words. I need to put the first 5 results into a
variable, then the next 5, and so on.

Code:

$first = mysql_query("SELECT tags,name FROM table WHERE
name='$username' LIMIT 5") or die(mysql_error());

while($row = mysql_fetch_array($first)) {
echo $row['tags'];
}



It doesn't get only the first 5 results, it prints everything out.

What's wrong w/ the code? And, am I going in the wrong direction with
this? Is there another way I should be using?

If there's any confusion it's set up like so (examples):

User
Natthew

Tags
word another word and another word

Thanks.

  Réponse avec citation
Vieux 13/10/2007, 05h33   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: LIMIT and TEXT types.

OutThisLife wrote:
> I've only been doing MySQL for a few weeks and I've run into a little
> problem..
>
> I have a column named tags and a column named name. I'm trying to find
> the tags that are assigned to the name.
>
> I've set the tag column to LONGTEXT as it will be used to store a
> large list of words. I need to put the first 5 results into a
> variable, then the next 5, and so on.
>
> Code:
>
> $first = mysql_query("SELECT tags,name FROM table WHERE
> name='$username' LIMIT 5") or die(mysql_error());
>
> while($row = mysql_fetch_array($first)) {
> echo $row['tags'];
> }
>
>
>
> It doesn't get only the first 5 results, it prints everything out.
>
> What's wrong w/ the code? And, am I going in the wrong direction with
> this? Is there another way I should be using?
>
> If there's any confusion it's set up like so (examples):
>
> User
> Natthew
>
> Tags
> word another word and another word
>
> Thanks.
>
>


This will give the first 5 rows. If you have multiple values in the a
column, MySQL doesn't know or care - it's all one row.

Google on "database normalization". This is contrary to first normal
form (each value in a column must be atomic).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 13/10/2007, 06h36   #3
Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: LIMIT and TEXT types.

On Oct 12, 11:33 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> OutThisLife wrote:
> > I've only been doing MySQL for a few weeks and I've run into a little
> > problem..

>
> > I have a column named tags and a column named name. I'm trying to find
> > the tags that are assigned to the name.

>
> > I've set the tag column to LONGTEXT as it will be used to store a
> > large list of words. I need to put the first 5 results into a
> > variable, then the next 5, and so on.

>
> > Code:

>
> > $first = mysql_query("SELECT tags,name FROM table WHERE
> > name='$username' LIMIT 5") or die(mysql_error());

>
> > while($row = mysql_fetch_array($first)) {
> > echo $row['tags'];
> > }

>
> > It doesn't get only the first 5 results, it prints everything out.

>
> > What's wrong w/ the code? And, am I going in the wrong direction with
> > this? Is there another way I should be using?

>
> > If there's any confusion it's set up like so (examples):

>
> > User
> > Natthew

>
> > Tags
> > word another word and another word

>
> > Thanks.

>
> This will give the first 5 rows. If you have multiple values in the a
> column, MySQL doesn't know or care - it's all one row.
>
> Google on "database normalization". This is contrary to first normal
> form (each value in a column must be atomic).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================



Hey Jerry, wouldn't it be easier to put the first 5 tags he's wanting
to print out in a SUBSTRING()?

  Réponse avec citation
Vieux 13/10/2007, 06h52   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: LIMIT and TEXT types.

Austin wrote:
> On Oct 12, 11:33 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> OutThisLife wrote:
>>> I've only been doing MySQL for a few weeks and I've run into a little
>>> problem..
>>> I have a column named tags and a column named name. I'm trying to find
>>> the tags that are assigned to the name.
>>> I've set the tag column to LONGTEXT as it will be used to store a
>>> large list of words. I need to put the first 5 results into a
>>> variable, then the next 5, and so on.
>>> Code:
>>> $first = mysql_query("SELECT tags,name FROM table WHERE
>>> name='$username' LIMIT 5") or die(mysql_error());
>>> while($row = mysql_fetch_array($first)) {
>>> echo $row['tags'];
>>> }
>>> It doesn't get only the first 5 results, it prints everything out.
>>> What's wrong w/ the code? And, am I going in the wrong direction with
>>> this? Is there another way I should be using?
>>> If there's any confusion it's set up like so (examples):
>>> User
>>> Natthew
>>> Tags
>>> word another word and another word
>>> Thanks.

>> This will give the first 5 rows. If you have multiple values in the a
>> column, MySQL doesn't know or care - it's all one row.
>>
>> Google on "database normalization". This is contrary to first normal
>> form (each value in a column must be atomic).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================

>
>
> Hey Jerry, wouldn't it be easier to put the first 5 tags he's wanting
> to print out in a SUBSTRING()?
>
>


Nope. He'll eventually run into other problems also if he doesn't
normalize his database.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13143 seconds with 12 queries