SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member SPTony's Avatar
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little bit of help here. dumb MYSQL functions

    Ok, so i'm coding this program to allow certian items to be show... heres the code:

    PHP Code:
                $CountAdd mysql_query("SELECT * FROM Adds WHERE FriendID = $MyFriend");
                while (
    $CountAddRows mysql_fetch_array($CountAdd)) {
                
    $Yo $Exclude;
                
    $EX $CountAddRows['AddedID'];
                
    $Exclude " AND FriendID !='$EX' ";
                
                
    $Yes $Exclude $Yo;
                
                            }
                            
                        
                
                
    $ShowUsers = ("SELECT * FROM Users Where FriendID !='$MyFriend'" $Yes " ORDER BY TotalPoints DESC LIMIT 100"); 


    i echoed $showusers and this is the out put


    SELECT * FROM Users Where FriendID !=' 57412139' AND FriendID !='89232231' ORDER BY TotalPoints DESC LIMIT 100



    how come...

    it doesnt show the first one but it shows the others...

    i'm confused.

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you look at it, you'll notice a small error at
    FriendID !=' 57412139' A SPACE before 5 after first quote


    You can do this as its easier syntax.

    SELECT * FROM Users Where FriendID not in ('57412139','89232231') ORDER BY TotalPoints DESC LIMIT 100

    This way, you can add any number without worrying about syntax or somethning.
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Member SPTony's Avatar
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AH!!! Thank you so much... its always the little things.

  4. #4
    SitePoint Member SPTony's Avatar
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dang... never mind still doesnt work... it limits it to not showing 2 how do I make it do unlmited?

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    may be try this
    PHP Code:
    $resultArr = array();
    $CountAdd mysql_query("SELECT * FROM Adds WHERE FriendID = $MyFriend");
                while (
    $CountAddRows mysql_fetch_array($CountAdd)) {
                
    $Yo $Exclude;
                
    $EX[] = $CountAddRows['AddedID'];
                
                            }
                            
                        
                
                
    $ShowUsers = ("SELECT * FROM Users Where FriendID not in('" implode("','",$EX) . "') ORDER BY TotalPoints DESC LIMIT 100"); 
    Haven't tested it.
    ---------------------------
    Errors = Improved Programming.
    My Site

  6. #6
    SitePoint Member SPTony's Avatar
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works grand! thank you so much!

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This could be done as a single query...

  8. #8
    SitePoint Addict
    Join Date
    Sep 2005
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $Exclude = " AND FriendID !='$EX' ";

    should be

    $Exclude .= " AND FriendID !='$EX' ";

    Notice the concatination period next to the equal sign?

    You were overwriting the variable.
    PHP Shopping Cart Software Easy Ecommerce Shopping Cart Script.
    PHP Super Cart is 100% template driven.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •