|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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()? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
![]() |
| Outils de la discussion | |
|
|