Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: AWS help

  1. #1
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783

    Unhappy AWS help

    I'm using Chris's DB structure to store Amazon node info, as below:

    Code:
    example:
    pid	amazonid  parentid  textid    name     MODE  
    1 	3118561   283155              50th     books
    I want to use an SQL call to get the amazonid and MODE based on a URL's array.

    So, with (for example) www.domain.com/cat/1/

    1 - is the PID

    I am trying to use:

    PHP Code:
    $var_array explode("/",$REQUEST_URI);

    if (
    $var_array[2] == 0) { $cat '4178281'$mode 'books';}

    else {

    $sql "SELECT * FROM blank_categories WHERE pid='$var_array[2]'";
    $result mysql_query($sql);

    if (
    $result == 0) { $cat '4178281'; } else { $cat mysql_result($result0'amazonid');}

    if (
    $result == 0) { $mode 'books'; } else { $mode mysql_result($result0'MODE'); }

    ;} 
    And then later the variables $cat and $mode are used for 'node' and 'mode' respectively.

    However, it's just not working! Nothing seems to be parsed, even if the array is empty (when it should go to the defaults, as above).

    What am I doing wrong?
    Stepping On Wires - the new blog

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,049
    When accessing the index I don't use

    domain.com/cat/0

    I use

    domain.com/cat/

    I don't think your use of

    $var == 0

    To test for true/false is working.

    For the first bit I use

    if($var_array[2] == "")

    After your query I do this:

    if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>");
    exit();
    }

    Then later down:

    while($main = mysql_fetch_array($result)){
    $pid = $main[pid];
    $SearchString = $main[amazonid];
    $name = $main[name];
    $parent = $main[parentid];
    $title = $name . " - Power TOols";
    $mode = $main[mode];
    }

    Then later down:

    if($Mode == "-unknown-"){
    $Mode = "universal";
    }

    $AmazonXml = Amazon($SearchType, $SearchString, $Mode, $SortString, $Offer, $Type, $PageNum);
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    Thanks for the code, Chris, but still no luck.

    This is the main block of code trying to piece all the variables together:

    PHP Code:
    $var_array explode("/",$REQUEST_URI);

    if (
    $var_array[2] == "") { $cat '4178281'$mode books;}

    else {

    $sql "SELECT * FROM blank_categories WHERE pid='$var_array[2]'";
    $result mysql_query($sql);

    if (!
    $result) { echo("<P>Error performing query: " mysql_error() . "</P>");
    exit();
    }

    while(
    $main mysql_fetch_array($result)){
    $pid $main[pid];
    $cat $main[amazonid];
    $name $main[name];
    $parent $main[parentid];
    $title $name " - Domain.com";
    $mode $main[MODE];
    }

    if(
    $mode == "-unknown-"){
    $mode "universal";

    Then these are called later:

    Code:
    $params = array(
    		    'browse_node' => $cat,
    		    'page'        => $page,
    		    'mode'        => $mode,
    		    'tag'         => 'my-amazon-thingy',
    		    'type'        => 'heavy',
    		    'sort'        => '-orig-rel-date',
    		    'devtag'      => 'my-dev-token'
    );

    But I get an error:

    We encountered an error at our end while processing your request. Please try again
    Warning: Invalid argument supplied for foreach() in /usr/home/gift/public_html/cat on line 96
    Page 1 of 0 -


    Line 96 is:

    PHP Code:
    foreach ($items as $i
    Which then goes into outputting the data into HTML...

    *sigh*
    Last edited by MarkB; 02-08-2004 at 10:03 AM.
    Stepping On Wires - the new blog

  4. #4
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,049
    I guess start doing some error checking. Echo out every variable you think should be there and see if it is. Echo out the number of rows returned from your query so that you know it is working.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  5. #5
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    I'm afraid I have no idea what's involved to do that...
    Stepping On Wires - the new blog

  6. #6
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,049
    echo out the var_array, get the number of results from the query and echo that out. ($numResults = mysql_num_rows($result)

    Every variable you expect to be there echo it out to make sure it really is there.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  7. #7
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    Somehow it's working now LOL

    Thanks Chris!
    Stepping On Wires - the new blog

  8. #8
    Senior Member chromate's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    2,348
    Start at the root and work upwards. After you set your $sql variable, echo it to make sure it makes sense.

    PHP Code:
    $sql "SELECT * FROM blank_categories WHERE pid='$var_array[2]'"
    echo 
    $sql
    If that looks like it should work... use this to check the results...

    PHP Code:
    $main mysql_fetch_array($result);
    print_r($main); 
    If it doesn't show anything, then there's a problem with your database. Copy and paste what we got earlier from echoing the $sql var and run it through your database manually (using phpMyAdmin or whilst logged in to MySQL shell)

    If that results in nothing, then you know your database is set up wrong.

    Ignore line 96 for now. You're getting an error there because there's a problem with your code before that which is causing amazon to reject your request. Because of that $items contains nothing, which is why PHP has a problem with line 96.

    The problem is somewhere in your code "pre amazon request".

  9. #9
    Senior Member chromate's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    2,348
    Forget all of the above then ! lol

  10. #10
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    hehe - thanks Chromate

    Now I just need to figure out how to list subcategories within categories
    Stepping On Wires - the new blog

  11. #11
    Registered
    Join Date
    Jan 2004
    Posts
    224
    EDIT: See my post below.
    Last edited by MattM; 02-10-2004 at 03:30 PM.

  12. #12
    Registered
    Join Date
    Jan 2004
    Posts
    224
    I just tried this code:
    PHP Code:
    <?

    $sql 
    "SELECT * FROM blank_categories WHERE pid='2'"
    $main mysql_fetch_array($result); 
    print_r($main);
    ?>
    I receive: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

  13. #13
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,049
    $result = mysql_query($sql)
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  14. #14
    Registered
    Join Date
    Jan 2004
    Posts
    224
    Thanks Chris

  15. #15
    Registered
    Join Date
    Jan 2004
    Posts
    224
    Chris, is there a way to automatically list all of the categories on a page or do you have to do this manually? For example, on Discount Power Tools, you have listed all the categories on the left side.
    Last edited by MattM; 02-10-2004 at 08:56 PM.

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
  •