views:

127

answers:

3

Hmm.. thats realy different problem I fetch $links from db linke this

$links = $db->GetAll("SELECT * FROM {$tables['link']['name']} WHERE STATUS = '2' AND CATEGORY_ID = ".$db->qstr($id)." {$feat_where} {$expire_where} ORDER BY {$sort_cols[$sort]} {$sort_ord[$sort]} {$limit}");

The array looks like this

array(28) {
    ["ID"]=>
    string(1) "3"
    ["TITLE"]=>
    string(6) "Google"
    ["DESCRIPTION"]=>
    string(6) "Google"
    ["URL"]=>
    string(21) "http://www.google.com"
    ["CATEGORY_ID"]=>
    string(1) "2"
    ["RECPR_URL"]=>
    string(0) ""
    ["RECPR_REQUIRED"]=>
    string(1) "0"
    ["STATUS"]=>
    string(1) "2"
    ["VALID"]=>
    string(1) "1"
    ["RECPR_VALID"]=>
    string(1) "1"
    ["OWNER_ID"]=>
    NULL
    ["OWNER_NAME"]=>
    string(0) ""
    ["OWNER_EMAIL"]=>
    string(0) ""
    ["OWNER_NOTIF"]=>
    string(1) "0"
    ["DATE_MODIFIED"]=>
    string(19) "2009-11-27 13:30:07"
    ["DATE_ADDED"]=>
    string(19) "2009-11-27 13:30:07"
    ["HITS"]=>
    string(1) "0"
    ["LAST_CHECKED"]=>
    NULL
    ["RECPR_LAST_CHECKED"]=>
    NULL
    ["PAGERANK"]=>
    string(2) "0"
    ["RECPR_PAGERANK"]=>
    string(2) "-1"
    ["FEATURED_MAIN"]=>
    string(1) "0"
    ["FEATURED"]=>
    string(1) "0"
    ["EXPIRY_DATE"]=>
    NULL
    ["NOFOLLOW"]=>
    string(1) "0"
    ["PAYED"]=>
    string(2) "-1"
    ["LINK_TYPE"]=>
    string(1) "0"
    ["IPADDRESS"]=>
    string(13) "80.219.78.155"
  }

I have a function which returns the pagerank of a given url GooglePagerank($url);

now how can i add the pagerank to the above array and assign them to smarty? Thanks

A: 

You can add new elements to the array with the [] operator, if you define a valid unique key name. Your data is stored in the $links array. Just add it like this:

$links['PAGERANK'] = $yourPageRankvar;

In your case it would be something like this:

$links['PAGERANK'] = GooglePagerank($links["URL"]);

Assign it to Smarty like this:

$smarty->assign('name', $links);
TheGrandWazoo
thanks ithink your solution would also work
streetparade
A: 

You can assign the result of GooglePagerank() to $array['pagerank'], for example?

BenTheDesigner
A: 

hmm.. that was easier as i thought

 for($i=0;$i<count($links);$i++)
      {
        $links[$i]["PAGERANK"] = GooglePagerank($links[$i]["URL"]);
      }

thats it

as result

 array(28) {
    ["ID"]=>
    string(1) "3"
    ["TITLE"]=>
    string(6) "Google"
    ["DESCRIPTION"]=>
    string(6) "Google"
    ["URL"]=>
    string(21) "http://www.google.com"
    ["CATEGORY_ID"]=>
    string(1) "2"
    ["RECPR_URL"]=>
    string(0) ""
    ["RECPR_REQUIRED"]=>
    string(1) "0"
    ["STATUS"]=>
    string(1) "2"
    ["VALID"]=>
    string(1) "1"
    ["RECPR_VALID"]=>
    string(1) "1"
    ["OWNER_ID"]=>
    NULL
    ["OWNER_NAME"]=>
    string(0) ""
    ["OWNER_EMAIL"]=>
    string(0) ""
    ["OWNER_NOTIF"]=>
    string(1) "0"
    ["DATE_MODIFIED"]=>
    string(19) "2009-11-27 13:30:07"
    ["DATE_ADDED"]=>
    string(19) "2009-11-27 13:30:07"
    ["HITS"]=>
    string(1) "0"
    ["LAST_CHECKED"]=>
    NULL
    ["RECPR_LAST_CHECKED"]=>
    NULL
    ["PAGERANK"]=>
    string(2) "10"
    ["RECPR_PAGERANK"]=>
    string(2) "-1"
    ["FEATURED_MAIN"]=>
    string(1) "0"
    ["FEATURED"]=>
    string(1) "0"
    ["EXPIRY_DATE"]=>
    NULL
    ["NOFOLLOW"]=>
    string(1) "0"
    ["PAYED"]=>
    string(2) "-1"
    ["LINK_TYPE"]=>
    string(1) "0"
    ["IPADDRESS"]=>
    string(13) "80.219.78.155"
  }
streetparade