I'm trying to show from data from Graph API, however I'm new with PHP and I'm struggling to get it to work. I've been working with the old API and have only just managed to convert some old code to new code, so it's a little messy. Can anyone see what's stopping this from functioning?
echo print_r( $graphObject, 1 );
echo "<br><h2><b><u>First Company</u></b></h2>";
echo 'Name: '.$graphObject->getProperty('name').;
echo 'Phone: '
if .$graphObject->getProperty['phone']. {
echo .$graphObject->getProperty('phone');
} else {
echo "No phone number available.";
}
I've managed to get the 'Name', but I'm trying to create an IF statement as the page doesn't have a phone number available.
Replace:
if .$graphObject->getProperty['phone'].
with
if (isset($graphObject->getProperty['phone']))
This should work
print_r($graphObject);
echo "<br><h2><b><u>First Company</u></b></h2>";
echo 'Name: ';
if (!empty($graphObject->getProperty('name'))) {
echo $graphObject->getProperty('name');
} else {
echo "No name available.";
}
echo 'Phone: ';
if (!empty($graphObject->getProperty('phone'))) {
echo $graphObject->getProperty('phone');
} else {
echo "No phone number available.";
}
Related
I want to show only one time the heading of parts of speeches for example when user enter the word "Spell" all the parts of speeches and its meaning come every time .
The headings are repeating multiple times . i want to print only one time
There should be a heading Of Noun,Verb,Adjective etc..
like this
Noun.
Verb.
adjective.
this is my code
while($row=mysql_fetch_array($sql)){
echo "<div id='wordid' style='display:none'>".$row["wordid"]."</div>";
echo $count++." : ".$row['definition']. " ";
if($row['pos']=="n"){
echo "(Noun) <br/>";
}
if($row['pos']=="s"){
echo "(Subject) <br/>";
}
if($row['pos']=="p"){
echo "(Proverb) <br/>";
}
if($row['pos']=="a"){
echo "(Adjective) <br/>";
}
if($row['pos']=="v"){
echo "(Verb) <br/>";
}
}
You can keep track of what the last wordid was and only echo the header if it changed.
// initialize to avoid notices
$lastWordId = '';
while($row=mysql_fetch_array($sql)){
if ($lastWordId != $row['wordid']) {
echo "<div id='wordid' style='display:none'>".
$row["wordid"].
"</div>";
$lastWordId = $row['wordid'];
}
echo $count++." : ".$row['definition']. " ";
if($row['pos']=="n"){
echo "(Noun) <br/>";
}
if($row['pos']=="s"){
echo "(Subject) <br/>";
}
if($row['pos']=="p"){
echo "(Proverb) <br/>";
}
if($row['pos']=="a"){
echo "(Adjective) <br/>";
}
if($row['pos']=="v"){
echo "(Verb) <br/>";
}
}
In the code below there's a chunck of code that repeats itself. Can this be done in another way so that the code does not repeat. No matter what I try, I keep ending with the same thing. The code is below, but it's a lot more in the production version. This thing does country location.
if ($GL)
{
echo 'Managed to find your location';
}else{
echo "Could not identify GL. Please select from the list below.";
}
This is the entire thing (stripped down).
$GL = false; //GL is detected using ip to location, and returns boolean
$location = 'UK';//Read from a cookie.
if(isset($location))
{
echo 'We found a cookie with your location<br />';
if(array_key_exists($location,$countries))
{
echo 'We found a country in the array. Carrying on<br />';
}else
{
echo 'Did not find a country in the array. Looking for GL';
if ($GL)
{
echo 'Managed to find your location. Carrying on';
}else{
echo "Could not identify GL. Please select from the list below.";
}
}
}
else
{
echo 'Did not find a location cookie<br />';
if ($GL)
{
echo 'Managed to find your location.Carrying on.';
}else{
echo "Could not identify GL. Please select from the list below.";
}
}
There are a couple simple solutions you could do. Such as:
1) Put it in a function:
function validGL($GL)
{
if ($GL)
{
echo 'Managed to find your location.Carrying on.';
}
else
{
echo "Could not identify GL. Please select from the list below.";
}
}
2) Store a boolean to determine if a valid location was found:
$GL = false; //GL is detected using ip to location, and returns boolean
$location = 'UK';//Read from a cookie.
$locationFound = false;
if(isset($location))
{
echo 'We found a cookie with your location<br />';
if(array_key_exists($location,$countries))
{
echo 'We found a country in the array. Carrying on<br />';
$locationFound = true;
}
else
{
echo 'Did not find a country in the array. Looking for GL';
}
}
else
{
echo 'Did not find a location cookie<br />';
}
if (!$locationFound)
{
if ($GL)
{
$GL_msg = 'Managed to find your location. Carrying on';
}
else
{
$GL_msg = "Could not identify GL. Please select from the list below.";
}
}
You can rephrase it like this:
If location is passed and found within valid list of countries, use that.
If not, if GL is found, use that.
Show the list if all else fails.
In code:
if (isset($location) && array_key_exists($location,$countries)) {
echo 'We found a country in the array. Carrying on<br />';
} elseif ($GL) {
echo 'Managed to find your location. Carrying on';
} else {
echo "Could not identify GL. Please select from the list below.";
}
You can make it a function and just call that function with the GL variable. This way you dont have to repeat the same if over and over.
this is by Far the weirdest thing i have ever seen and i am completely confused. please someone help me with this.
$variable=array();
$count=0;
// now im am going to loop through a resource that i made
while(!feof($job))
{
$data=fgets($job);
// i am search for different things below. search for name, date, employer
// i am using regex to search btw
// presume object in class works fine, and they do.
if(search for eg name in $data, storing in $variable[$count].first($match))
// the problem is at this point i will have access to
// $variable[$count].getFirst(returns value set by first) which was set above;
if(search for eg Employer in $data, storing in variable[$count].next($match))
// i will have access here as well
// $variable[$count].getFirst(returns value set by first) which was set above
if(search for 3rd search in $data, storing in variable[$count].name($match))
// down here after the second if i am not able to see any of my variables set more than 2 if statements ago????
// $variable[$count].getFirst(does not returns the value set by first()) which was set above
if(search for 4th search in $data, storing in variable[$count].foo($match))
// check if everything is set then count++;
}
Now each one of these methods are completely dependent from the next but after 2 if statements. I am just not able to access $variable[count]->getfirst()
the answer is null;
edited
this is the actual code
require "functions/decodeEncodedUrl.php";
require "objects/jobObject.php";
$url=decodeEncodedUrl();
$profile=array();
$companies=0;
$url_search='http://www.jobbank.gc.ca/';
$startReading=0;
$job=fopen($url['url'], 'r')or die("JobBanks is failing to respond.<br>Please Try again Later");
while(!feof($job))
{
set_time_limit(500);
$profile[$companies]= new jobProfile();
$trash=fgets($job);
if(!$startReading)
{
if(preg_match('~RepeaterSearchResults_hypJobItem_[0-9]+~',$trash,$matches))
{
$startReading=true;
}
}
if($startReading)
{
$data=$trash;
if(preg_match("~href=\".*\"~",$data,$matches))
{
$temp=preg_replace("~href=~",'',$matches[0]);
$temp=preg_replace("~\"~",'',$temp);
$profile[$companies]->setLink($url_search.$temp);
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~>[A-Za-z-, ]+\(~",$data,$matches))
{
$temp=preg_replace("~>|\(~",'',$matches[0]);
$profile[$companies]->setPosition(ucfirst($temp));
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~# *[0-9]+~",$data,$matches))
{
$profile[$companies]->setOrderNum(preg_replace("~#| ~",'',$matches[0]));
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~Employer:</strong>.*~",$data,$matches))
{
$temp=preg_replace("~Employer:</strong> ~",'',$matches[0]);
$temp=preg_replace("~<br.*~",'',$temp);
$temp=ucfirst($temp);
$profile[$companies]->setEmployer($temp);
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~[$][0-9]+.*~",$data,$matches))
{
$temp=preg_replace("~/.*~",'',$matches[0]);
$profile[$companies]->setSalary(preg_replace("~[$]~","$ ",$temp));
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~[$][0-9]+.*~",$data,$matches))
{
$temp=preg_replace('~[$A-Za-z0-9. ]*[/] ?~','',$matches[0]);
$profile[$companies]->setRate(preg_replace('~<.*~','',$temp));
var_dump($profile[$companies]);
echo "<br>";
echo "<br>";
}
if(preg_match("~Location:.*~",$data,$matches))
{
$temp=preg_replace('~.*;~','',$matches[0]);
$temp=preg_replace('~^ |,~','',$temp);
$profile[$companies]->setCity(ucfirst($temp));
//echo ucfirst($temp)."<br>";
}
if(preg_match("~Location[:<>/\,A-Za-z ]*~",$data,$matches))
{
$profile[$companies]->setProvince($matches[0]);
//echo " ".$matches[0]."<br>\n";
//echo $profile[$companies]->getLocation()."\n<br>";
}
if(preg_match("~[0-9]{4}/[0-9]{2}/[0-9]{1,2}~",$data,$matches))
{
echo $profile[$companies]->displayHTML();
$profile[$companies]->setDate($matches[0]);
if($profile[$companies]->allDataSet())
{
//echo "data was set"."<br>";
$startReading=false;
$companies++;
}
else
{
$startReading=false;
$companies++;
echo "Data was Not set";
}
}
}
}
fclose($job);
everything works except the $profile[number] doesn't store anything in it at all after the 3 rd if statement when the variable is stored.
If
{
//Profile[number] info stored
}
if
{
//Profile[number] info available
}
if
{
//profile[number] info available
}
if
{
//profile[number] info is gone
}
variable[$count].next($match)
the .next() moves the internal pointer to the next element in the array.
for($c=1;$c<=$num;$c++)
{
$row=mysql_fetch_array(mysql_query("SELECT * FROM `$quiztitle` WHERE id=$c"));
if($row['answer']==$_POST['answer'][$c]) // NOT WORKING
{
echo "correct";
echo "<br>";
}
else
{
echo "incorrect";
echo "<br>";
}
}
on the line where it says "NOT WORKING",
the index [$c] does not get the value from the loop.
but when i specify it and change it to $_POST['answer1'], it is working.
what is the correct syntax for this?
Try this.
for($c=1;$c<=$num;$c++)
{
$row=mysql_fetch_array(mysql_query("SELECT * FROM `$quiztitle` WHERE id=$c"));
if($row['answer']==$_POST['answer'.$c]) // NOT WORKING
{
echo "correct";
echo "<br>";
}
else
{
echo "incorrect";
echo "<br>";
}
}
You're treating 'answer' as an array here, looking for an index within.
You want to concatenate the value.
if($row['answer']==$_POST["answer{$c}'])
Based on your note, it looks like you want:
$_POST["answer$c"]
Correct is:
if ($row['answer'] == $_POST['answer' . $c]) {
....
}
I am trying to echo the message 'No records found' when I get nothing back from the database.
I have done a row count which shows me how many rows I have but I can't seem to echo the 'No records found' message. Is it in the wrong place? Will it not run for some reason?
<?php if(isset($search_results)){
foreach($search_results as $result) {
$rowcount = $result['rowcount'];
if(!$rowcount < 1) {
echo $rowcount;
echo '<div class="search_result"> <b>'.$result['title'].'</b><br />';
echo '<span class="search_result_url">'.$result['link'].'</span><br />';
echo $result['text'].'<br /></div>';
} else {
echo 'No records found.';
}
}
} else {
echo 'Use the search to find what you are looking for. Enter the term or keyord into the search box and press enter..';
}
?>
Take a look at mysql_num_rows(), and use an if() to see whether your mysql_query() returned any results:
$result = mysql_query("SELECT * FROM table");
if(!mysql_num_rows($result))
{
echo 'No results';
}
else
{
// Results - do stuff.
}