| ★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/002282.html | Nouvelle recherche | Portail wanayoo |
|
|
DevShed Discussion Forums
![]() PHP
![]() Links from SELECT DISTINCT
|
| next newest topic | next oldest topic |
| Author | Topic: Links from SELECT DISTINCT |
|
cube Junior Member |
Hi, I have the following problem/challenge... I have a mysql dbase with PHP, in the dbase I have Items from various locations. What I want to do is to use the SELECT DISTINCT to make a list with all the locations. This isn't the problem, now I want to change the locations into links, so if you click on one of them, you will get a list with all the items from that location.. and here I'm lost:-( Anybody outthere that can point me into a certain (if possible the right :-) )direction???? Thanks a lot in advance!!!!! Peace, cube |
|
freddydoesphp Member |
Actually I have done this recently. This code selects distinct cities and creates links to a detail page where I pass the variable $location with this I can query the databse again and get whatever details that I need. $result = mysql_query("SELECT DISTINCT City from listings",$db);
|
|
Shiju Rajan Member |
while ($myrow = mysql_fetch_array($result)) { printf('<a href=/old?u=http%3A%2F%2Fwww.devshed.com%2FTalk%2FForums%2FForum5%2FHTML%2F%25s%3Flocation%3D%25s%26gt%3B%25s%26lt%3B%2Fa%26gt%3B%26lt%3Bbr%26gt%3B%25s&y=1999', "city.php3", rawurlencode($myrow["City"]), $myrow["City"], "\n"); } Make the above lines easy.. if(mysql_num_rows($result)>0){ while ($myrow = mysql_fetch_array($result)) { echo "<a href=/old?u=http%3A%2F%2Fwww.devshed.com%2FTalk%2FForums%2FForum5%2FHTML%2F%5C&y=1999"city.php3\"?location=".rawurlencode($myrow["City"].">".$myrow["City"]."</a><br>\n";
------------------ "The fear of the LORD is the beginning of knowledge..." |
|
cube Junior Member |
Thank you both very much for your help!!!! A managed to do it but in a slightly different way, just needed the direction :-) Cube $query = "SELECT DISTINCT location FROM dbase"; $result = MYSQL_QUERY($query); /* How many of these locations are there? */ /* Print these results to the screen*/ IF ($number == 0) : |
|
freddydoesphp Member |
Shiju, I noticed you have track record of answering the same answer that others have answered time and time again, and it isn't just a matter of two postings happening at the same time, your responses some time show up a day later, do you read others' responses before posting your own? |
|
firepages Member |
Or perhaps Shiju Rajan thinks that sometimes answers to questions are sometimes helped by a little explanation and a clean layout. Sometimes variations on a theme can be very helpful, especially to 'beginners'. I am guilty of sometimes answering questions with code that may not make sense to everbody- even me ! when I look back on them. And Shiju Rajan has been clearly answering questions for a long time before freddy did php in this forum. ------------------ |
|
freddydoesphp Member |
So you think that Shju's method above is cleaner than mine, Ummh am I missing something? |
|
freebsd Member |
"Thank you both very much for your help!" So both of you got credit for answering his question. |
|
freddydoesphp Member |
My point exactly, thanks FreeBSD |
|
cube Junior Member |
No need to fight over this people!! It helped me a lot seeing 2 different solutions to the same problem!! Which helped me understanding PHP/MYSQL better and helped me find my own solution!A lot of the time it's nice to see how other solve something and learn from that! So again thank you both!!! peace, cube |
|
Shiju Rajan Member |
Actually this discussion is really unnecessary.
I know you are a very good php programmer(reading from your answers).I know i can't reach upto your level.See the above example.your code is perfect.Just i tried to write in my way so i can learn from your script.No question of taking credit. i don't believe in that kind of things. I am here for learning php.So please avoid this kind of comments. Thank you
"For the LORD gives wisdom: out of his mouth comes knowledge and understanding.." [This message has been edited by Shiju Rajan (edited August 07, 2000).] |
|
freddydoesphp Member |
Shiju, I see where you are coming from now, and I am sorry for my harshness. But from standpoint when you first responded after me, I was wondering why someone would post a reply to an already valid answer. Again I was mistaken in my ways and am sorry. |
All times are MST (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1997-2000 ngenuity. All rights reserved.
Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.