Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Location
    eastern tn
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trying to filter out array results with a list created from mysql results

    i'm still learning php, so please be easy on me ;) (i googled till my fingers were sprained!)


    so, i'm trying to check an array, see if the values in a specific key match any of the values in another array (from mysql of user ids), then, if it doesnt match, skip over it, and continue to the next result.
    now, it works showing if they're all matches, but it's not skipping ones that don't match, instead, if it hits one that doesn't match, it just shows a blank page.

    how i got there-
    first, i get the info from json decode results as array = $tag.- keys- (these are just examples)
    Code:
    [0] => Array
      [username] => Info
      [user_id] => Info
      [title] => Info
      [url] => Info
      [image] => Info
      [tags] => Array
        [0] => Info
        [1] => Info
    [1] => Array
      [username] => Info
      [user_id] => Info
      [title] => Info
      [url] => Info
      [image] => Info
      [tags] => Array
        [0] => Info
        [1] => Info
    [2] => Array
      [username] => Info
      [user_id] => Info
      [title] => Info
      [url] => Info
      [image] => Info
      [tags] => Array
        [0] => Info
        [1] => Info
    next, the list of id numbers from mysql (single column)
    results = $idnumbers

    and *try* to filter them out, but i know i'm going wrong somewhere!

    what i want is if say, [1]Array has a [user_id] not in the list from the mysql results, to be dropped off, or ignored, or whatnot..

    Code:
    [0] => Array
      [username] => Info
      [user_id] => Info
      [title] => Info
      [url] => Info
      [image] => Info
      [tags] => Array
        [0] => Info
        [1] => Info
    (and array [1] is gone)
    [2] => Array
      [username] => Info
      [user_id] => Info
      [title] => Info
      [url] => Info
      [image] => Info
      [tags] => Array
        [0] => Info
        [1] => Info
    ..anyways..

    here's my code (edited for content)
    PHP Code:
    <?php

    include 'mysqlloginfile.php';

    // the curl connect stuff
    $url "http://website.com&api_key";
    $ch curl_init($url);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    $response_body curl_exec($ch);
    $status curl_getinfo($chCURLINFO_HTTP_CODE);
    if (
    intval($status) != 200) die("Error: $response_body");
    $response json_decode($response_body);
    $tag $response->results[0];

    //connecting to the database
    mysql_select_db("database"$con);
    $query ="SELECT idnumbers FROM table";
    $result mysql_query($query);

    //where i think i have issues
    while ($row mysql_fetch_array($result)) {
        if (
    $tag->user_id == ($row['idnumbers'])) {
            foreach(
    $response->results as $tag)
                echo 
    "<div><a href=\"".$tag->url."\"><img src=\"".$tag->image_url_75x75."\"><br> <div class=\"desc\">By: <a href=\"http://".$tag->user_name.".etsy.com\">".$tag->user_name."</a></div></div>";
        }
    }
    ?>
    any help would be fantastic! :)

  • #2
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    you could try to use an easier approch. If i understand correctly you want to search in arrays for a certain value. You could try
    PHP Code:
    in_array(WHAT YOUR LOOKING FOR, THE ARRAY) 
    and you could do multiple ones.
    http://php.net/manual/en/function.in-array.php please fix me if i am wrong or that is not what you meant.

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Location
    eastern tn
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm not totally 100%, though this entry seems like it might work for what i need,

    the main problem is that i need to eliminate the array once it's been found, and keep going through the rest of the results


  •  

    Tags for this Thread

    Posting Permissions

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