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!!

Member Avatar for diafol

When you say client, do you mean you're creating production code for somebody else? If so, you are be aware that you are using deprecated code.

Get rid of the ; inside the SQL.
Use PDO or mysqli NOT mysql_* functions.

You are showing it via iframe in your site? Probably not the best way. Why don't you simply create a link to the actual site itself:

echo "<a target='_blank' href='http://www.digipart.com/part/$searchkeyword'>$searchkeyword</a>";

You can try using SimpleHtmlDom library to achieve your goals. Scrap the results from your query and save to DB or display on to the page.

SimpleHTMLDom

Member Avatar for diafol

I agree with GC, but this is a little frowned upon.

The data presented on the parts pages is in a number of different formats - different table structures for different companies. Different price list formats (single vs multiple) - multiline cell content. Bit of a challenge to scrape, although not impossible. If the site changes its layout / structure then your site will fail until you update the scraper / parser. If it wasn't a client-based work, where you need a very robust solution, this would be a fun DIY project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.