Jump to content

salman_ahad@yahoo.com

Members
  • Posts

    167
  • Joined

  • Last visited

    Never

Everything posted by salman_ahad@yahoo.com

  1. table1 : col1 = topicid , col2 = topic table2 : col1 = sentid, col2 = sentence require_once("includes/connection.php"); $trends = mysql_query("SELECT topicid, topic FROM table1"); $sent = mysql_query("SELECT sentid, sentence FROM table2"); //I need to concatenate every topic in table1 //with every sentence in table2 and create array of sentences. help me with snippet please.
  2. I have a table "testtable" in MySQL col1 = id //primary key col2 = text <?php //test.php .. $result = mysql_query("SELECT * FROM testtable"); if($result) { //What code shall I write to delete empty text associated with any id ?>
  3. Seanlim: you are best I regularly have concerns...will look forward for your help in future!!
  4. table name = trendingtopics col1 = topicid //I assigned the id 1 to 10 (hard coded) col2 = topic //These 10 topics should be updated which are present in $ttopics[] P.S: We are not getting topicid from that api.
  5. You are correct ttopics[] = array () //it holds the strings $ttopics[] = "topic1"; $ttopics[] = "topic2"; .... $ttkey should hold the key in the array:0 to 9 How do we do it?
  6. <?php require_once("includes/connection.php"); $json = file_get_contents('http://some_api'); Some api I am retrieving the names $data = json_decode($json); $ttopics = array(); foreach ($data->trends as $trend) { $ttopics[] = $trend->name ; those names I am storing in array } foreach ($ttopics as $ttkey=>$topic){ for each array entry as $ttkey $result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$ttkey}'"); if($result) { $num = mysql_num_rows( $result ); if ($num == 0) { $querypost = mysql_query ("INSERT INTO trendingtopics VALUES ('$ttkey', '$topic')"); } else{ $row = mysql_fetch_array($result); if($row['topic']!=$topic) $querypost = mysql_query ("UPDATE trendingtopics SET topic = '$topic' WHERE topic='$ttkey'"); } } } ?> the topics(ttkey) are not inserting.
  7. current table hard coded entry topicid ------topic --------------------- 1-------------a 2 -------------b .. .. 10 -------------j //I have to update this table with strings present in $ttkey <?php ... foreach ($ttopics as $ttkey=>$topic){ $ttkey has the topics (10 strings). These need to be updated instead of a,b ...j $result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$ttkey}'"); if($result) { $num = mysql_num_rows( $result ); if ($num == 0) { $querypost = mysql_query ("INSERT INTO trendingtopics VALUES ('$ttkey', '$topic')"); } else{ $row = mysql_fetch_array($result); if($row['topic']!=$topic) $querypost = mysql_query ("UPDATE trendingtopics SET topic = '$topic' WHERE topicid='$ttkey'"); } <? There is something wrong in my syntax. Please help
  8. //I am still not able to update <?php ... foreach ($ttopics as $ttkey=>$topic){ ttkey has the topics (strings) $result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$ttkey}'"); Then why are checking for "topicid" nstead of topics if($result) { $num = mysql_num_rows( $result ); if ($num == 0) { $querypost = mysql_query ("INSERT INTO trendingtopics VALUES ('$ttkey', '$topic')"); } else{ $row = mysql_fetch_array($result); if($row['topic']!=$topic) $querypost = mysql_query ("UPDATE trendingtopics SET topic = '$topic' WHERE topicid='$ttkey'"); } <? current table hard coded entry topicid topic --------------------- 1 a 2 b .. .. 10 j Now we need to update with the strings present in $ttkey Please help
  9. My "topics" table contains 10 entires *--------------* topicid topic ------ *--------------* 01 Bye 02 Hi 03 Hello ..... 10 Morning *--------------* <?php //topics.php require_once("includes/connection.php"); .... .... ttopics[]= //I have 10 strings here which have changed by now. foreach ($ttopics as $ttkey) { //I am trying to update my "topics" table whenever these strings change, based on the topicid (primary key). //Please correct my code. $id = mysql_real_escape_string('topicid'); $topic = mysql_real_escape_string('topic'); $result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$id}' and topic='{$topic}' "); if($result) { $num = mysql_num_rows( $result ); if ($num == 0) { $querypost = mysql_query ("INSERT INTO trendingtopics (topic) VALUES ('$ttkey')"); } } I am getting an error. Lets say the position of Morning is first and Bye is last. It should update the database accordingly. If there is a new entry, say "phpfreaks" in first position. It should update according.
  10. Thanks but how do I run it for the first time? <?php //This is my code I want to run every hour. $lastRun = time(); if ($lastRun + 3600 < time()) { runIt(); $json = file_get_contents('http://some_api'); $data = json_decode($json); $ttopics = array(); foreach ($data->trends as $trend) { $tt[] = $trend->name ; } foreach ($tt as $ttkey) { echo $ttkey.'<br \>'; } } ?> I know I am making some blunder.. please correct me.
  11. How can I log the time it was run? And run it again when an hour is over. A little more detail, code would help me.
  12. I need to run a php file every one hour. Is there any other solution apart from cron job?
  13. Thanks Guys...it worked. I will try include() too... My first php class is test1.php <?php class MyFirstClass{ private $string1="Hello",$string2="Testing",$string3="Hi"; function getString1(){ return $this->string1; } function getString2(){ return $this->string2; } function getString3(){ return $this->string3; } } ?> My second php class is test2.php <?php require('test1.php'); class MySecondClass{ private $var1,$var2,$var3; public function __construct(MyFirstClass $firstClass){ $this->getFirstClassVars($firstClass); $this->printFirstClassVars(); } function getFirstClassVars($firstClass){ $this->var1 = $firstClass->getString1(); $this->var2 = $firstClass->getString2(); $this->var3 = $firstClass->getString3(); } function printFirstClassVars(){ print $this->var1."<br/>"; print $this->var2."<br/>"; print $this->var3."<br/>"; } } $firstClass = new MyFirstClass(); $secondClass = new MySecondClass($firstClass); ?> And this is what I needed. It worked.
  14. Thanks Salate and all, it worked. Now I need to separate this classes as two php, MyFirstClass.php and MySecondClass.php. Save them in the same folder and try. If there is any other slight change I need to make. Please help.
  15. Are you guys helping or confusing... thanks though.. let me try
  16. This is my code. I have three strings in MyFirstClass. I am trying to call them in MySecondClass <?php class MyFirstClass{ private $string1="Hello",$string2="He",$string3="Hi"; function getString1(){ return $this->string1; } function getString2(){ return $this->string2; } function getString3(){ return $this->string3; } } class MySecondClass{ private $var1,$var2,$var3; __Construct(MyFirstClass $firstClass){ getFirstClassVars($firstClass); printFirstClassVars(); } function getFirstClassVars($firstClass){ $this->var1 = $firstClass->getString1(); $this->var2 = $firstClass->getString2(); $this->var3 = $firstClass->getString3(); } function printFirstClassVars(){ print $this->var1."<br/>"; print $this->var2."<br/>"; print $this->var3."<br/>"; } } $firstClass = new MyFirstClass(); $secondClass = new MySecondClass($firstClass); ?> I am getting this error "syntax error, unexpected T_STRING, expecting T_FUNCTION" at this line __Construct(MyFirstClass $firstClass){
  17. Where exactly I have to write this function? Can I write this is any class or separate. And how do I call it where I need it?
  18. I have test1.php{ $string1; $string2; .... ... //10 strings in this class $string10; } Another class test2.php { ..... .... I want to use those 10 strings here, how should I do it? }
  19. ltrim is not working. I also tried { .... $sentences = split('[.!?]',$para); $sentences = ltrim($sentences,'\"'); i also tried $bad = array("\xc2","\x80","\x8c","\x9d","\x98","\x99"); $find[] = '“'; // left side double smart quote $find[] = 'â€'; // right side double smart quote $find[] = '‘'; // left side single smart quote $find[] = '’'; // right side single smart quote $find[] = '…'; // elipsis $find[] = '—'; // em dash $find[] = '–'; // en dash $replace[] = '"'; $replace[] = '"'; $replace[] = "'"; $replace[] = "'"; $replace[] = "..."; $replace[] = "-"; $replace[] = "-"; foreach ($sentences as $final) { str_replace($find,$replace,$final); str_replace($bad,"",$final); I TRIED EVERYTHING, BUT THE QUOTES DOESN'T SEEM TO BE GOING FROM MY SENTENCES FORMED...
  20. If we give a big article for say. It will obviously have many sentences. I am splitting my article (paragraph) into sentences based on delimiters (.!?) By using the regular expression of MadTechie I am seeing only three sentences are formed in any large amount of paragraph I submit. I should get rest of the sentences till the paragraph finish right?? But the output is only 3 sentences using MadTechie's expression. Any solution??
  21. I have a variable $result I want to use it outside my loop, how can I?? ... foreach ($sent as $result) { ... ... //$result undergoes some calculation. } ... foreach ($result as $result2) I want to use $result again later in the code... { echo $result2; } It gives me Invalid argument supplied for foreach()...
  22. I fixed it... I had given wrong local variable earlier.
  23. I am taking sentences through a form on page. Then checking some condition and trying to insert them in database. I have issues while inserting... foreach ($sentences as $final) { ...... else { if(strlen($final) <= 120){ echo $final.'.<br />';} else echo substr($final,0,120). '.<br />'; //Inserting of final(sentences) in database starts $sent = mysql_real_escape_string($_POST ['$final']); $error= "Error while inserting, either User present or other. Please check database"; $inserted= "sentences inserted"; $result = mysql_query("SELECT sent FROM sentences WHERE sent='{$final}' "); if($result) { $num = mysql_num_rows( $result ); if ($num == 0) { $querypost = mysql_query ("INSERT INTO sentences (sent) VALUES ('$final')"); echo $inserted; } else echo $error; } } } Please correct my logic error.
×
×
  • 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.