Question:
MySQL: SELECT DISTINCT skipping the first row?
anonymous
2009-02-07 19:44:14 UTC
Hi,

I'm working with PHP and MySQL again and I've hit a snag. I'm using SHOW TABLES in combination with SELECT DISTINCT to create a dynamic menu.
The problem is that the SELECT DISTINCT code seems to ignore the "subtype" value of the first row. For example, if the subtype value for the first record is wood, it won't show up in the menu, and none of the other records that match "wood" don't cause it to show up in the menu either.

Any help would be appreciated...I'll post the code in as additional info.
Four answers:
The Singing Answerman
2009-02-07 21:46:00 UTC
You call a fetch_row and store the result in $numrows2, but calling num_rows is what you meant to do. So your first row is skipped in the subsequent loop. I bet if you comment out line 13 and run it again you'll see what I mean, and your output will appear complete.



Yeah that "while" loop's just gonna continue where the cursor's at. Don't throw in your hat! It's all gonna show how you ask it to be! While we're at it, don't forget to thwart HTML injection attacks by calling htmlentities where applicable!



I've sung this for you at: http://noise.dillfrog.com/audio/fawm2009/selectdistinct.mp3
Daniel S
2009-02-07 20:23:54 UTC
It would probably be much better to just define the menu in a separate PHP file and include it where you need it. Or, if you want it to be dynamic, list the menu options in an array in a separate PHP file and include it where you need it. I don't mean to be rude, but using a database for this makes no sense.
anonymous
2009-02-07 21:05:48 UTC
If you want to make a dynamic menu from a database, create a table that makes sense for creating a menu from. Then you do a single SELECT-WHERE and your dataset is the menu items.
esperanza
2016-05-23 05:48:17 UTC
What do you mean by "last five rows"?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...