Page 1 of 1

How to replace text with appropriate variable

Posted: Sat Oct 16, 2010 4:10 pm
by guitars4god7
I am working on my site and adding the ability for users to like different pages and I would like to be able to keep track of the number of likes each website url has and insert them into my database. So far it works fine for if I want to submit one url to check but I would like to set it up as a cron job to check multiple url's using a function. The problem that has me stumped is how do I take the "http://www.test.com" out of 'query' => 'select total_count from link_stat where url = "http://www.test.com";' and replace it with a variable. Every method I have tried has failed and i'm not sure if it has something to do with facebooks php sdk or not. Any help would be very much appreciated. Chance

Code: Select all

<?php

require './facebook.php';
include 'config.php';

$facebook = new Facebook(array(
  'appId'  => 'my app id',
  'secret' => 'my app secret',
  'cookie' => true,
));

$website = "http://www.test.com";

$result = $facebook->api(array(
	'method' => 'fql.query',
	'query' => 'select total_count from link_stat where url = "http://www.test.com";'
));

$fblikes = $result[0]['total_count'];
mysql_query("UPDATE likes SET count = '$fblikes' WHERE website = '$website'");

?>		

Re: How to replace text with appropriate variable

Posted: Sat Oct 16, 2010 4:21 pm
by josh

Code: Select all

$string = 'foo';
$otherString = 'bar';

echo $string . ' ' . $otherString;
echo "$string $otherString";
Both of those echo statements do the same. Its called concatenation in the PHP manual. Be sure to use mysql_real_escape_string() to escape the values.

Re: How to replace text with appropriate variable

Posted: Sat Oct 16, 2010 4:34 pm
by guitars4god7
No that's not it I'm afraid. I understand string concatenation but if that were the case I could just do something like this (which isn't concatenation but it wouldn't need to be) I think its something with fb's php sdk cause if I do this I get the following error.
Fatal error: Uncaught Exception: 601: Parser error: unexpected '$' at position 51. thrown in C:\Documents and Settings\Chance\Desktop\New Site\xampplite\htdocs\facebook.php on line 515
I can post the facebook.php file if you want to look. Is there some way I can make a variable inside the array or something? Can array statements have variables in them?

Code: Select all

<?php

require './facebook.php';
include 'config.php';

$facebook = new Facebook(array(
  'appId'  => 'my app id',
  'secret' => 'my app secret',
  'cookie' => true,
));

$website = '"http://www.test.com"';

$result = $facebook->api(array(
	'method' => 'fql.query',
	'query' => 'select total_count from link_stat where url = echo $website;'
));

$fblikes = $result[0]['total_count'];
mysql_query("UPDATE likes SET count = '$fblikes' WHERE website = '$website'");

?>		


Re: How to replace text with appropriate variable

Posted: Sat Oct 16, 2010 9:22 pm
by requinix
guitars4god7 wrote:No that's not it I'm afraid. I understand string concatenation but if that were the case I could just do something like this
No, actually, you don't understand it. Because if that were the case you could just do something like this.

Code: Select all

'query' => 'select total_count from link_stat where url = "' . $website . '"'