caine Posted November 5, 2006 Share Posted November 5, 2006 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("&", "&", $string); //$string = str_replace("<", "<", $string); //$string = str_replace(">", ">", $string); //$string = str_replace("'", "'", $string); //$string = str_replace("\"", """, $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. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/ Share on other sites More sharing options...
fenway Posted November 5, 2006 Share Posted November 5, 2006 I'm very confused about your insert statements... it looks like you're storing the date in the same field as the title? There's no column list. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-119960 Share on other sites More sharing options...
caine Posted November 6, 2006 Author Share Posted November 6, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-120139 Share on other sites More sharing options...
fenway Posted November 6, 2006 Share Posted November 6, 2006 I'm not sure I understand that that first insert is doing outside the loop... and could you post your table structure? Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-120440 Share on other sites More sharing options...
caine Posted November 7, 2006 Author Share Posted November 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-120685 Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 OK... I'm still not sure why you can two insert statements. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-120731 Share on other sites More sharing options...
caine Posted November 8, 2006 Author Share Posted November 8, 2006 Thanks ya, if you know about further improvement and modifications, I hope to learn about them. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-121508 Share on other sites More sharing options...
caine Posted November 9, 2006 Author Share Posted November 9, 2006 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("&", "&", $string); //$string = str_replace("<", "<", $string); //$string = str_replace(">", ">", $string); //$string = str_replace("'", "'", $string); //$string = str_replace("\"", """, $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] Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-121995 Share on other sites More sharing options...
fenway Posted November 10, 2006 Share Posted November 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-122771 Share on other sites More sharing options...
caine Posted November 16, 2006 Author Share Posted November 16, 2006 Does it look like this?echo "qry"=.$qry?Or may it be the IIS setting which prohibits online users from "fopen" the url, since the display shows nothing for "pre"=.$pre and "source"=.$source? Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-125459 Share on other sites More sharing options...
fenway Posted November 16, 2006 Share Posted November 16, 2006 Yes, that would be the correct line to execute, without the = sign. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-125711 Share on other sites More sharing options...
caine Posted November 18, 2006 Author Share Posted November 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-126619 Share on other sites More sharing options...
fenway Posted November 19, 2006 Share Posted November 19, 2006 I see missing commas and/or unmatched quotes... also, why the unconventional insert syntax? Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-127185 Share on other sites More sharing options...
caine Posted November 20, 2006 Author Share Posted November 20, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-127343 Share on other sites More sharing options...
fenway Posted November 20, 2006 Share Posted November 20, 2006 Well, other than what I hope are backticks around the table name, I guess it would work... Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-127611 Share on other sites More sharing options...
caine Posted November 23, 2006 Author Share Posted November 23, 2006 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; Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-129032 Share on other sites More sharing options...
fenway Posted November 23, 2006 Share Posted November 23, 2006 So you're not die()-ing? And I'm not sure why you have backticks. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-129244 Share on other sites More sharing options...
caine Posted November 28, 2006 Author Share Posted November 28, 2006 I replaced '' with backticks, becoz when I tried with '', nothing returned for $qry in Mozilla. But, backticks doesn't helps too because there's still no data in my database. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-131473 Share on other sites More sharing options...
fenway Posted November 29, 2006 Share Posted November 29, 2006 Backticks won't work -- and you'll need single quotes, not double-quotes. Quote Link to comment https://forums.phpfreaks.com/topic/26194-solved-why-no-data-at-all-wad-should-i-do/#findComment-132082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.