0

Please help me with this. I am not a good in explaining and my grammar is not that good so please bear with me.

My client wants a website which auto search a manufacturing part number from a certain website.

http://www.digipart.com/

The code for the auto search is working and there's no error. However, my client wants to check for each manufacturing part number which is saved from database if it have a search result here is my code:

$searchmfgpn =@mysql_query("select mfg_pn from bom_crunching; ");
//@mysql_query($searchmfgpn,$connect)or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
while($row = mysql_fetch_array($searchmfgpn))
{
    $searchkeyword =$row['mfg_pn'];
    echo "<pre>";
    echo $searchkeyword;    
    echo "</pre>";
    $digipart ="http://www.digipart.com/part/".$searchkeyword;
    //echo "<iframe src=".$digipart." width ='1200' height ='600'></iframe>";
    $string = "We are sorry, but no result was found for '$searchkeyword' Please try again."; 

    if (strpos($digipart,$string) !== false) {
    echo 'Not Available.';
    } else {
    echo 'Available';
    }

}

the code didn't gave me any errors, however the code I used to check if it is available or not is incorrect. It only check for the URL. I want to check for the whole page, which is I don't know what code should I use.

How can I fixed this? Any help will be appreciated!!

Myrts Grc
  • 53
  • 5

1 Answers1

1

It looks like you're expecting $digipart to be the HTML of the search results page, and then you're checking if the error is on the page using strpos($digipart, $string). This is incorrect.

$digipart is set to "http://www.digipart.com/part/".$searchkeyword; -- It is not the HTML of the page, but instead it is just the URL itself as a string. So when you're comparing the error ($string) to the $digipart variable, it will always be false.

Wes Foster
  • 8,770
  • 5
  • 42
  • 62
  • oh that's why, I am only getting the Available. I use this as my reference http://stackoverflow.com/questions/7118823/check-if-url-has-certain-string-with-php but by the way can you help me to solve my problem|? – Myrts Grc Jul 22 '15 at 04:55
  • The question you referenced is not checking the page's HTML, it's just checking the URL to see if it has the word "car" in it. Unfortunately, I cannot rewrite your code for you. If you have more questions, feel free to ask. – Wes Foster Jul 22 '15 at 04:58