-
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($result, 0, 'amazonid');}
if ($result == 0) { $mode = 'books'; } else { $mode = mysql_result($result, 0, '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? :(
-
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);
-
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*
-
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.
-
I'm afraid I have no idea what's involved to do that...
-
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.
-
Somehow it's working now :) LOL
Thanks Chris!
-
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".
-
Forget all of the above then ! :) lol
-
hehe - thanks Chromate :)
Now I just need to figure out how to list subcategories within categories :)
-
-
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.
-
$result = mysql_query($sql)
-
-
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.