PDA

View Full Version : AWS help



MarkB
02-08-2004, 04:13 AM
I'm using Chris's DB structure to store Amazon node info, as below:


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:


$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? :(

Chris
02-08-2004, 07:40 AM
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);

MarkB
02-08-2004, 08:00 AM
Thanks for the code, Chris, but still no luck.

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


$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:


$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:


foreach ($items as $i)

Which then goes into outputting the data into HTML...

*sigh*

Chris
02-08-2004, 10:02 AM
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.

MarkB
02-09-2004, 11:44 AM
I'm afraid I have no idea what's involved to do that...

Chris
02-09-2004, 12:06 PM
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.

MarkB
02-09-2004, 12:55 PM
Somehow it's working now :) LOL

Thanks Chris!

chromate
02-09-2004, 01:05 PM
Start at the root and work upwards. After you set your $sql variable, echo it to make sure it makes sense.



$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...



$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".

chromate
02-09-2004, 01:06 PM
Forget all of the above then ! :) lol

MarkB
02-09-2004, 01:59 PM
hehe - thanks Chromate :)

Now I just need to figure out how to list subcategories within categories :)

MattM
02-09-2004, 04:34 PM
EDIT: See my post below.

MattM
02-10-2004, 03:29 PM
I just tried this 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.

Chris
02-10-2004, 03:41 PM
$result = mysql_query($sql)

MattM
02-10-2004, 04:02 PM
Thanks Chris :)

MattM
02-10-2004, 08:53 PM
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.

Chris
02-10-2004, 09:54 PM
What I do is scan the database where parentid = 0.

MattM
02-11-2004, 04:43 PM
How do I display all of the results? It only returns one.

Chris
02-11-2004, 06:00 PM
That depends on your database.

For categories I want displayed at the top of the category structure (ala my homepage) I set their parentid = 0. If you only set one category as such then only one will show.

RockNRollPig
02-13-2004, 12:42 PM
Originally posted by MarkB
I'm using Chris's DB structure to store Amazon node info, as below...
Is Chris's DB structure listed somewhere?

Chris
02-13-2004, 12:46 PM
http://www.websitepublisher.net/forums/showthread.php?s=&threadid=824&perpage=15&pagenumber=14

RockNRollPig
02-13-2004, 12:49 PM
Thanks Chris!