Jump to content

salman_ahad@yahoo.com

Members
  • Posts

    167
  • Joined

  • Last visited

    Never

Everything posted by salman_ahad@yahoo.com

  1. I used the loops like this recently and worked fine for me... Again it depends on your logic of expected output, let us know ur code in detail //my code for($y=0; $y <= $counter1; $y++) { for($z=0; $z <= $counter2; $z++) { ..} }
  2. Thanks Alex, I know what you mean...the reason I wanted to double check is I am working with real data... Also could my LIMIT be user defined?? $Var=$_POST['limit']; $query_users = mysql_query("SELECT * FROM test LIMIT '".$Var."'") or die(mysql_error()); //its not working...says wrong suntax
  3. I need to select data from table which has multiple WHERE condition... is it correct $query_users = mysql_query("SELECT * FROM users WHERE userid NOT IN (SELECT * FROM *table2*) AND datetime > NOW() - INTERVAL 5 MINUTE") or die(mysql_error()); //is my condition correct ?? checking for two WHERE conditions?
  4. Thanks I also have error which picking user input variable... $Var=$_POST ['Variable'] $query_users = mysql_query("SELECT * FROM users WHERE userid='".$Var."')") or die(mysql_error()); //Why is it not working
  5. Thanks Joel.. Also I need to pick some accounts between a datetime range of last 5 mins..this is what I got. $timenow = time(); $fiveminsb4 = $timenow - 300; $query_users = mysql_query("SELECT userid FROM *table* WHERE datetime BETWEEN '".$timenow."' AND '".$fiveminsb4."')"); //is there a better logic??
  6. How to delete a range of table rows where id=1 to 100 $query = mysql_query("DELETE FROM all (id) VALUES (//range here ??)") or die(mysql_error());
  7. any cron job allows us to run a php file at specific time...but this is what I am trying to do //test.php //users table contains multiple users //message table contains multiple messages $user = mysql_query("SELECT * FROM users") or die(mysql_error()); $message = mysql_query("SELECT * FROM message") or die(mysql_error()); //...guide me for rest of the code //Every user should be sent a message every one hour. Also the message which was not sent to any user. //Lets say user-1 was sent a message-23 at 01:02:03 // user-1 shld receive the next message in queue after one hour user-2 was sent a message-40 at 20:22:00 // user-2 shld receive the next message in queue after one hour ... user-n was sent a message-78 at 12:30:10 // user-n shld receive the next message in queue after one hour Can this user specific script be run as cron??
  8. I have multiple $users in table. I need to send them $message. I need to send the next message available in the database to the next user who got least amount of messages. Or how could I place those users in a session and send the message to the first user in session.. Any help ??
  9. My script obviously did not run the next time...PLEASE CORRECT ME require_once("includes/connection.php"); $query = mysql_query("SELECT lastRun FROM time") or die(mysql_error()); if(mysql_num_rows($query)!=0) { while($row = mysql_fetch_array($query)) { $TimeRun = $row['lastRun']; if ($TimeRun + 3600 < time()) { $to_email = "salman_ahad@yahoo.com"; $subject = "test script"; $message = "Time : Running"; mail($to_email, $subject, $message); $TimeRun = time(); $querypost = mysql_query ("UPDATE time SET lastRun = '$TimeRun'"); } } } else{ //nothing } OR..could I do? function first(){ //All my code sleep(3600); call function second() } function second(){ //All my same code as above sleep(3600); call function first() }
  10. Need more clarification on the solution someone gave me I need to run apart from cron, it is a script... I am not sure if Godaddy allows me chmod any file... need more clarification.
  11. $topic_bit_length = strlen($dataArray1['topic'][$y]."::".$bit); $a = $topic_bit_length + 10; $b = 100 - $a; $sent_shrink = current(explode("\n", wordwrap($dataArray2['sent'][$z], $b))).' Read more';
  12. I know what you are saying, so I reversed my logic //say 100 is total length $a= //some int length $b= 100 - $a $result = current(explode("\n", wordwrap($sentence, $b))) . ' Read more...'; //Now I have $sentence[] as array...how do I do now...
  13. The problem with this is wordwrap's $a characters from left. But we need to remove from right. Any solution ??
  14. I was able to remove $result = substr($sentence, 0, -$a); Any way of adding "read more" at the end ??
  15. It would be better to replace those $a(int) number of characters at the end with "...Read More" or worst case remove them.
  16. <?php $a = //some int value $sentence = "This is the string. Need to rtrim $a number of characters from right of $sentence"; $result_string = rtim($sentence, $a); //can we do this ?? ?>
  17. DID IT!! for($y=0; $y <= $counter1; $y++) { for($z=0; $z <= $counter2; $z++){ $result = $dataArray1['topic'][$y]." ".$dataArray2['sent'][$z]; echo $result; echo "<br \>"; } }
  18. Thanks David... now some more correction please <?php require_once("includes/connection.php"); $dataArray1 = array(); $dataArray2 = array(); $resultArray = array(); $topics = mysql_query("SELECT * FROM trendingtopics ORDER BY topicid") or die(mysql_error()); if(mysql_num_rows($topics)!=0) { $x=0; while($row_topics = mysql_fetch_array($topics)) { $dataArray1['topic_id'][$x] = $row_topics['topicid']; $dataArray1['topic'][$x] = $row_topics['topic']; $x++; } } else { echo "no topic"; } $sentences = mysql_query("SELECT * FROM sentences ORDER BY sentid") or die(mysql_error()); if(mysql_num_rows($sentences)!=0) { $x=1; while($row_sentences = mysql_fetch_array($sentences)) { $dataArray2['sent_id'][$x] = $row_sentences['sentid']; $dataArray2['sent'][$x] = $row_sentences['sent']; $x++; } } else { echo "No sentences"; } //I need to concatenate each topic with each sentence. My two foreach loops are not concatenating as expected... Need correction here foreach($dataArray1['topic'] as $eachTopic) { foreach($dataArray2['sent'] as $eachSent) { $resultArray[] = $eachTopic." ".$eachSent; print_r($resultArray); echo "<br \>"; } } ?> My output is coming as 'Hi' ' ' 'Hello' //'topic1' 'space' 'sentence1' 'Hi' ' ' 'Hello' ' ' 'This' //'topic1' 'space' 'sentence1' 'space' 'sentence2' 'Hi' ' ' 'Hello' ' ' 'This' ' ' 'is' //'topic1' 'space' 'sentence1' 'space' 'sentence2' 'space' 'sentence3' ....... //My expected result 'Hi' ' ' 'Hello' //'topic1' 'space' 'sentence1' 'Hi' ' ' 'This' //'topic1' 'space' 'sentence2' 'Hi' ' ' 'is' //'topic1' 'space' 'sentence3' 'Bye' ' ' 'Hello' //'topic2' 'space' 'sentence1' 'Bye' ' ' 'This' //'topic2' 'space' 'sentence2' ...
  19. I agree with you Daniel, that we need to strive towards learning. If only I could show you that I am working full time in learning and doing as much as I can in parallel. You folks are experts, asking you folks while striving myself helps me learn to code better. Please correct my logic, this one I could figure out...
  20. This is what I got. Please correct my logic, I need to join each topic string with each string. <?php $dataArray = array(); $dataArray2 = array(); $resultArray = array(); require_once("includes/connection.php"); $topics = mysql_query("SELECT * FROM trendingtopics ORDER BY topicid") or die(mysql_error()); if(mysql_num_rows($topics)!=0) { $x=0; while($row_topics = mysql_fetch_array($topics)) { $dataArray['topic_id'][$x] = $row_topics['topicid']; $dataArray['topic'][$x] = $row_topics['topic']; $x++; } } else { echo "no topic"; } $sentences = mysql_query("SELECT * FROM sentences ORDER BY sentid") or die(mysql_error()); if(mysql_num_rows($sentences)!=0) { $x=1; while($row_sentences = mysql_fetch_array($sentences)) { $dataArray2['sent_id'][$x] = $row_sentences['sentid']; $dataArray2['sent'][$x] = $row_sentences['sent']; $x++; } } else { echo "No sentences"; } //I need to concatenate each topic with each sentence foreach($dataArray->topic as $eachTopic) { foreach(dataArray2->sent as $eachSent) { $resultArray[] = $eachTopic." ".$eachSent; } } echo $result; ?>
  21. //please correct my logic. I need to make those variables $topicid, $topic, $sentid & $sent as arrays which I need to use them outside those local loops. <?php require_once("includes/connection.php"); $topics = mysql_query("SELECT * FROM trendingtopics ORDER BY topicid") or die(mysql_error()); $num_rows_topics = mysql_num_rows($topics); if ($num_rows_topics < 1) { echo "No topics"; } else { while($row_topics = mysql_fetch_array($topics)) { $topicid = $row_topics['topicid']; $topic = $row_topics['topic']; //echo $topicid.'<br \>'; //echo $topic.'<br \>'; } } $sentences = mysql_query("SELECT * FROM sentences ORDER BY sentid") or die(mysql_error()); $num_rows_sentences = mysql_num_rows($sentences); if ($num_rows_sentences < 1) { echo "No sentences"; } else { while($row_sentences = mysql_fetch_array($sentences)) { $sentid = $row_sentences['sentid']; $sent = $row_sentences['sent']; //echo $sentid.'<br \>'; //echo $sent.'<br \>'; } } ?> Need to concatenate every $topic[] with every $sent[]. Please help me code better.
  22. It does not give me any output apart from this.. Resource id #4 And I have lot of data in both the tables. Also I need to concatenate every topic with every sentence...eq Hello , Hi , Bye This is me, This is him Hello This is me Hello This is him Hi This is me Hi This is him Bye This is me Bye This is him
×
×
  • 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.