★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/002282.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  Links from SELECT DISTINCT

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Links from SELECT DISTINCT
cube
Junior Member
posted August 04, 2000 07:59 PM     Click Here to See the Profile for cube   Click Here to Email cube     Edit/Delete Message Reply w/Quote
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
posted August 04, 2000 09:47 PM     Click Here to See the Profile for freddydoesphp   Click Here to Email freddydoesphp     Edit/Delete Message Reply w/Quote
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);


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");
}

Shiju Rajan
Member
posted August 05, 2000 06:07 AM     Click Here to See the Profile for Shiju Rajan   Click Here to Email Shiju Rajan     Edit/Delete Message Reply w/Quote

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)) {
//loop through the cities

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";
//print the cities..
}
}else{
//no records are available..
echo "No cities!!!\n";
exit;
}


In city.php3,get the details of that location.

------------------
SR -
webshiju.com

"The fear of the LORD is the beginning of knowledge..."

cube
Junior Member
posted August 05, 2000 08:08 AM     Click Here to See the Profile for cube   Click Here to Email cube     Edit/Delete Message Reply w/Quote
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? */
$number = MYSQL_NUMROWS($result);

/* Print these results to the screen*/
$i = 0;

IF ($number == 0) :
PRINT "<CENTER><P>At the moment there are no locations available.</CENTER>";
ELSEIF ($number > 0) :
PRINT "Logo on top<BR>";
WHILE ($i < $number):
$location = mysql_result($result,$i,"location");
PRINT "<h3><a href='/old?u=http%3A%2F%2Fwww.devshed.com%2FTalk%2FForums%2FForum5%2FHTML%2Fcity_page.php3%3Flocation%3D%24location&y=1999'>$location</a></h3>";
$i++;
ENDWHILE;
ENDIF;

freddydoesphp
Member
posted August 05, 2000 01:00 PM     Click Here to See the Profile for freddydoesphp   Click Here to Email freddydoesphp     Edit/Delete Message Reply w/Quote
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
posted August 05, 2000 11:24 PM     Click Here to See the Profile for firepages   Click Here to Email firepages     Edit/Delete Message Reply w/Quote
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.

------------------
Simon Wheeler
FirePages -DHTML/PHP/MySQL

freddydoesphp
Member
posted August 06, 2000 10:57 AM     Click Here to See the Profile for freddydoesphp   Click Here to Email freddydoesphp     Edit/Delete Message Reply w/Quote
So you think that Shju's method above is cleaner than mine, Ummh am I missing something?

freebsd
Member
posted August 06, 2000 02:19 PM     Click Here to See the Profile for freebsd     Edit/Delete Message Reply w/Quote
"Thank you both very much for your help!"

So both of you got credit for answering his question.
Credit isn't equivalent to money here in devshed. So why need to seize other's credit?

freddydoesphp
Member
posted August 06, 2000 04:16 PM     Click Here to See the Profile for freddydoesphp   Click Here to Email freddydoesphp     Edit/Delete Message Reply w/Quote
My point exactly, thanks FreeBSD

cube
Junior Member
posted August 06, 2000 04:24 PM     Click Here to See the Profile for cube   Click Here to Email cube     Edit/Delete Message Reply w/Quote
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
posted August 07, 2000 04:06 AM     Click Here to See the Profile for Shiju Rajan   Click Here to Email Shiju Rajan     Edit/Delete Message Reply w/Quote
Actually this discussion is really unnecessary.


Freddy,

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



------------------
SR -
webshiju.com

"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
posted August 07, 2000 11:08 AM     Click Here to See the Profile for freddydoesphp   Click Here to Email freddydoesphp     Edit/Delete Message Reply w/Quote
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

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.