#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    10
    Rep Power
    0
    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    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=%s?location=%s>%s</a><br>%s', "city.php3", rawurlencode($myrow["City"]), $myrow["City"], "n");
    }

  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    while ($myrow = mysql_fetch_array($result)) {
    printf('<a href=%s?location=%s>%s</a><br>%s', "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="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..."
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    10
    Rep Power
    0
    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='city_page.php3?location=$location'>$location</a></h3>";
    $i++;
    ENDWHILE;
    ENDIF;
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    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?
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    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
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    So you think that Shju's method above is cleaner than mine, Ummh am I missing something?
  14. #8
  15. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    "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?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    My point exactly, thanks FreeBSD
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    10
    Rep Power
    0
    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
  20. #11
  21. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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).]
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    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.

Similar Threads

  1. select distinct with more than 1 field
    By hoagnes in forum MySQL Help
    Replies: 13
    Last Post: January 30th, 2004, 01:43 PM
  2. select DISTINCT with a WHERE statement
    By emk in forum MySQL Help
    Replies: 4
    Last Post: January 27th, 2004, 10:41 AM
  3. Replies: 1
    Last Post: January 13th, 2004, 07:14 PM
  4. select distinct from multiple tables
    By dmors in forum Database Management
    Replies: 1
    Last Post: January 9th, 2004, 02:56 AM
  5. select distinct problem
    By mrengc in forum MS SQL Development
    Replies: 1
    Last Post: December 23rd, 2003, 08:50 AM

IMN logo majestic logo threadwatch logo seochat tools logo