Jump to content

[SOLVED] why no data at all? wad should I do?


caine

Recommended Posts

I duno if I should post this message here, but it is something to do with the mysql. The problem is the code can detect the necessary data that I wan,t but it cannot read the data, therefore cannot be stored into my database table. I think may be there is problem with the fread part. What should I do? Besides, how to program to check if the redundant data exists in db so that there's no further storing of same data?

[code]<html>
<head>
<title>Bulletin Data</title>
</head>
<body>


<?php

include 'connect.php';

$URL="http://bulletin.mmu.edu.my/v3/view/bytodaytitle.mmu";

$f = fopen($URL, "r");
  if($f){
echo "asdasdasdasd";
        while(!feof($f))
        {
$pre = fread($f, 1000);
echo "pre=".$pre;
$source = $source.$pre;
echo "source=".$source;
echo "url=".$url;
    }
    }
    else
    {
        echo 'Unable to open '.$URL.'.';
        die;
    }
   
       


//extract the date into database
$date_string= substr_count($source, "<td width=\"100%\" colspan=\"4\">");
$date1 = strpos($source, "<td width=\"100%\" colspan=\"4\"><font face=\"Verdana, Arial\" size=\"1\"
                          color=\"#000066\">List of Today's Bulletin : <b>", 0);
$date_end1 = strpos($source, "</b></font></td>", $date1);
$date1 = $date1 + 111;
$date = substr($source, $date1, $date_end1- $date1);
$date = check($date);

@mysql_query("INSERT INTO `bul_data` VALUES ('$date')", $db);
 
$total= substr_count($source, "<td width=\"20%\" >");

//extract necessary information into database
$pos=0;
for($counter=0;$counter<$total;$counter++)
{
$line1 = strpos($source, "<td width=\"20%\" ><font face=\"Verdana, Arial\" size=\"1\">", $pos);
$end1 = strpos($source, "</a></td></font>", $begin1);
$line1 = $line1 + 54;
$end1 = $end1 - $line1;
$department = substr($source, $line1, $end1);
$department = check($department);

$line2 = $line1 + $end1 + 1;
$line2 = strpos($source, "<a href=\"", $line2);
$end2 = strpos($source , "\" target=\"main\"" , $line2);
$line2 = $line2 + 9;
$end2 = $end2 - $line2;
$link = substr($source , $line2, $end2);
$link = check($link);

$line3 = $line2 + $end2 + 1;
$line3 = strpos($source , "onMouseOut=\"b()\">" , $begin3);
$end3 = strpos($source , "</font></a></td>" , $begin3);
$line3 = $line3 + 17;
$ended = $end3 - $line3;
$title = substr($source , $line3 , $ended);
$title = check($title);

$line4 = $line3 + $ended + 1;
$line4 = strpos($source , "<td width=\"17%\" align=\"center\"><font face=\"Verdana, Arial\" size=\"1\">" , $begin4);
$end4 = strpos($source , "</td></font>" , $begin4);
$line4 = $line4 + 68;
$end4 = $end4 - $line4;
$campus = substr($source , $begin4 ,$line4);
$campus = check($campus);

$pos = $line4 + $end4 + 1;

@mysql_query("INSERT INTO `bul_data` VALUES ('$title', '$department', '$campus', '$link')", $db);

}

function check($string)
{

$string = htmlspecialchars($string, ENT_QUOTES);
//$string = str_replace("&", "&amp;", $string);
//$string = str_replace("<", "&lt;", $string);
//$string = str_replace(">", "&gt;", $string);
//$string = str_replace("'", "&apos;", $string);
//$string = str_replace("\"", "&quot;", $string);
return $string;
}


//function ripnew($URL)
//{
// $newURL="http://bulletin.mmu.edu.my/v3/view/$URL";
// $f = fopen($newURL, "r");
//  if($f)
//        while($pre = fread($f, 1000))
// $source = $source.$pre;
//     else
//     {
//         echo 'Unable to open '.$URL.'.';
//         return false;
// }
 
// $begin =  strpos ($source,"</table>", 0);
// $begin = $begin + 8;
// $end = strpos($source,"</body>",$begin);
// $end = $end - $begin;
// $detail = substr($source, $begin, $end);

// return $detail;
}

?>

</body>
<html>[/code]

The echos are for debugging purpose. Hope to hear some replies. Thanks.
Link to comment
Share on other sites

Oh, may be you are right. I never notice that. I hoped to insert the data associated with the current publications date into the db right after the extraction. However, by referring to the html source code, the date info appears right before the recursive news item(which contains the title, department, campus and link, hence i use the for loop). What will be the modifications that need to be done?
Link to comment
Share on other sites

This is the db table structure that I'd created:

CREATE TABLE 'bul_data' (
DATE varchar(50) NOT NULL default '',
TITLE varchar(255) default NULL,
DEPARTMENT varchar(255) default NULL,
CAMPUS varchar(255) default NULL,
LINK varchar(255) default NULL,
PRIMARY KEY (DEPARTMENT)
);

Actually for the result display, I have to output the news sorted according to DEPARTMENT and CAMPUS.
The db name is bulletin. Hopefully these are the information you needed.
Link to comment
Share on other sites

I'd modified the mysql part, but there's still no data stored. I still cannot identify wad's the problem.

[code]<html>
<head>
<title>Bulletin Data</title>
</head>
<body>


<?php
include 'connect.php';

$URL="http://bulletin.mmu.edu.my/v3/view/bytodaytitle.mmu";

$f = fopen($URL, "r");
  if($f){
echo "jskjskss";
$pre = "";
        while(!feof($f))
{

$pre = $pre.fread($f, 10000000);
echo "pre=".$pre;
$source = $source.$pre;
echo "source=".$source;
echo "url=".$URL;
}
}
    else
    {
        echo 'Unable to open '.$URL.'.';
        die;
    }
   
//extract the date into database
$date_string= substr_count($source, "<td width=\"100%\" colspan=\"4\">");
$date1 = strpos($source, "<td width=\"100%\" colspan=\"4\"><font face=\"Verdana, Arial\" size=\"1\"
                          color=\"#000066\">List of Today's Bulletin : <b>", 0);
$date_end1 = strpos($source, "</b></font></td>", $date1);
$date1 = $date1 + 111;
$date = substr($source, $date1, $date_end1- $date1;);
$date = check($date);
 
$total= substr_count($source, "<td width=\"20%\" >");

//extract necessary information into database
$pos=0;
for($counter=0;$counter<$total;$counter++)
{
$line1 = strpos($source, "<td width=\"20%\" ><font face=\"Verdana, Arial\" size=\"1\">", $pos);
$end1 = strpos($source, "</a></td></font>", $begin1);
$line1 = $line1 + 54;
$end1 = $end1 - $line1;
$department = substr($source, $line1, $end1);
$department = check($department);

$line2 = $line1 + $end1 + 1;
$line2 = strpos($source, "<a href=\"", $line2);
$end2 = strpos($source , "\" target=\"main\"" , $line2);
$line2 = $line2 + 9;
$end2 = $end2 - $line2;
$link = substr($source , $line2, $end2);
$link = check($link);

$line3 = $line2 + $end2 + 1;
$line3 = strpos($source , "onMouseOut=\"b()\">" , $begin3);
$end3 = strpos($source , "</font></a></td>" , $begin3);
$line3 = $line3 + 17;
$ended = $end3 - $line3;
$title = substr($source , $line3 , $ended);
$title = check($title);

$line4 = $line3 + $ended + 1;
$line4 = strpos($source , "<td width=\"17%\" align=\"center\"><font face=\"Verdana, Arial\" size=\"1\">" , $begin4);
$end4 = strpos($source , "</td></font>" , $begin4);
$line4 = $line4 + 68;
$end4 = $end4 - $line4;
$campus = substr($source , $begin4 ,$line4);
$campus = check($campus);

$pos = $line4 + $end4 + 1;

$qry = "INSERT INTO 'bul_data' SET DATE ='{$date}', TITLE = '{$title}',
        DEPARTMENT = '{$department}', CAMPUS = '{$campus}', LINK = '{$link}'";

@mysql_query($qry, $db);


}

function check($string)
{

$string = htmlspecialchars($string, ENT_QUOTES);
//$string = str_replace("&", "&amp;", $string);
//$string = str_replace("<", "&lt;", $string);
//$string = str_replace(">", "&gt;", $string);
//$string = str_replace("'", "&apos;", $string);
//$string = str_replace("\"", "&quot;", $string);
return $string;
}

//function ripnew($URL)
//{
// $newURL="http://bulletin.mmu.edu.my/v3/view/$URL";
// $f = fopen($newURL, "r");
// if($f)
//      while($pre = fread($f, 1000))
// $source = $source.$pre;
//     else
//     {
//         echo 'Unable to open '.$URL.'.';
//         return false;
// }
 
// $begin =  strpos ($source,"</table>", 0);
// $begin = $begin + 8;
// $end = strpos($source,"</body>",$begin);
// $end = $end - $begin;
// $detail = substr($source, $begin, $end);

// return $detail;
//}

?>

</body>
<html>[/code]
Link to comment
Share on other sites

That's an unusual syntax for INSERT, although I do think it will work... try echoing the $qry to the screen to make sure that your variables make it in correctly, and then check for any mysql errors by examining the return value from mysql_query.
Link to comment
Share on other sites

the qry does appear sth. It shows something like these:

[quote]qry=INSERT INTO 'bul_data' SET DATE='2006-11-18', TITLE='*New* STUDENT STATUS' DEPARTMENT='EXAM' CAMPUS='Melaka </tr></td></font></table>' LINK='bulletin_main.mmu?s=30045&by=today'[/quote]

But don't know what's the exact problem with the empty db table data. Besides, LINK will not appear frequently for each news item.
Link to comment
Share on other sites

[code]qry=INSERT INTO 'bul_data' SET DATE='2006-11-18', TITLE='*New* STUDENT STATUS' ,DEPARTMENT='EXAM', CAMPUS='Melaka </tr></td></font></table>' ,LINK='bulletin_main.mmu?s=30045&by=today'[/code]

Sorry, there are mistakes. Commas do exist. Do you mean that the $qry output display should not be this way?
Link to comment
Share on other sites

I had modified the mysql syntax according to the mysql 4.1.13. But there is still no data in db. The output is still disappointing.

$qry = "INSERT INTO bul_data (DATE, TITLE, DEPARTMENT,CAMPUS, LINK) VALUES ( `$datetime`,`$title`,`$category`,``, `$link`)";

$res = mysql_query($qry) OR die(mysql_error());

echo "qry=".$qry;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.