PHP - Rolling Out A Feature.
I had a question and couldn't really pin-point a forum to put this post in, so I hope this suits my topic.
You always hear "Facebook is rolling out a new feature"; most recently "Twitter is rolling out the New Twitter.com" but it only releases to so many people at time. Or friends will get features on Facebook before I do (like I couldn't like threaded comments until about a month after all my other friends could). I was just wondering if anyone knows the actual method or how large sites go about releasing new features to users? Similar TutorialsI need some help with a dice rolling project. Here is what code I've got so far I just need some help with the for and while loops. I have to simulate the the dice being rolled (between 1-6) 5000 times and track the results in a table. If anyone could help me, I'd be VERY APPRECIATIVE. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>"Statistical analysis of rolling a six-sided die"</title> </head> <body> <h2>Statistical analysis of rolling a six-sided die</h2> <br/> <table width='600' border='1' cellspacing='0' cellpadding='5' align='center'> <?php $side1 = 1; $side2 = 2; $side3 = 3; $side4 = 4; $side5 = 5; $side6 = 6; for ($i =1; $i <= 5000; i++) { $roll = mt_rand(1, 6); } ?> </table> </body> </html> I am writing a stock program and I am going to be getting several averages on volume over different periods, 10, 21, 50,100,120,150,200,240 are my averages.
I would like to make this fairly efficient, seeing as how its going to be a ton of data, I have over 7700 stocks in the database and they will each have all of those averages.
My question is how to do this that is the most efficient, I thought about taking the 10 day then adding 11 to it, then adding 29 to get the 50 day and so on and so forth, or is that too much work and I should just do each average individually?
select avg(volume) from _AAPL where date between ‘2014-02-03’ and ‘2014-05-05’;The above is my current very generic code that does work, now I just need to make a php script, which I can do, I am just curious about how different people would approach this. Thanks for the help. Edited by illcrx, 23 September 2014 - 10:32 PM. Hello everyone,
<?php $sql = ";WITH TOTAL_KWH_WINTER AS ( SELECT CONVERT(VARCHAR(10),cdate,111)AS trans_date, datepart(hh, cdate) as trans_hour, comm_id, MIN((total_energy_a+total_energy_b+total_energy_c)/100) AS minUsage, MAX((total_energy_a+total_energy_b+total_energy_c)/100) AS maxUsage, meter_multiplier FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] where comm_id='$comm_id'and meter_multiplier is not null group by comm_id, CONVERT(VARCHAR(10),cdate,111), datepart(hh, cdate), meter_multiplier ) SELECT *, datepart(weekday, trans_date) as trans_date_day, datepart(month, trans_date) as trans_date_month, ((maxUsage - minUsage)*meter_multiplier) as totalUsage FROM TOTAL_KWH_WINTER where datepart(weekday, trans_date) IN ('1', '2', '3', '4', '5', '6', '7') AND DATEPART(MONTH, trans_date) IN ('10','11','12','1','2','3','4') and trans_date BETWEEN '$startdate2 00:00:01' AND '$enddate2 24:00:00' "; $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ $sumUsageKWH += $row[totalUsage];}sqlsrv_free_stmt($query);?>**************For whatever reason, my browser will not let me put this code where it needs to go, so its up top. Sorry for the inconvenience.************* My concern are code lines 4 through 15 I have PHP code that queryies MSSQL for data called kilowatt hours (kWh), set in a combination of three columns. kWh is set into the db table once every minute and it a value that starts at zero (0) at the beginning of the meters life, then continues until it reaches 10,000,000 before resetting back to zero (0). This happens over weeks, months or years, but it does happen. The code I have listed here makes no consideration of this reset. Since we are alsways querying between a start date and a stop date, we need to know the kWh usage between that period. So, we used maxUsage - minUsage and called that the totalUsage. That works great until the data reset at 10M. At that point, max usage will be some value (ex. 1 kWh), where min usage will be some value (ex. 9,999,999 kWh). the system breaks down at that point. I need to find an algorithm that helps me take into consideration this rolling number set. Thanks for any help! Edited by Butterbean, 16 January 2015 - 09:28 AM. Hi All, I am a newbie and was designing a feature and needed some help. Wondering if i can get some help here. Here is the scenario. I have a website which has an Add Page. In the Add Page, customers can add address details and other information. Sometimes the customers might want to select an address from the existing address database. I have a button on the Add Page, which opens a new window which displays the addresses which can be used. When the customer selects an Address and clicks on the USE button, an POST is done to a new Add Page which displays the address. There is a slight glitch here. When the customers press on the USE button, a new Add Page is opened again in the same window. So how we have two instances of the Add Page. Now what I want to accomplish is that when the customer presses on the USE button, the new window should close and the already opened Add Page should display the selected Address. Is there a way to do this? I would greatly appreciate any input. Thank you, I'm using the wordpress themeplate, that has feature box in main page, which it use the feature images that has been listed on the pages, and it has this little icons that swtich them around every few second, now i need to have a small modification. i need the hover that is appearing on the top of the small boxes to show the tittle center, and also i need it to be linked (a href) to their pages... and the main background photo to be linked to that page as well. please help me url: http://www.makooliprekupec.com/en/ We want to add a chat feature in PHP for a social site can somebody suggest a good solution, a script maybe, where registered users when online can chat with other registered members in the friend list I have made a script to upload a few files from the pc to my server.. like i upload big files which are generally above 50mb of size.. but most of the times as there is some problem with the internet the hours of wait is just ruined.. is there a better way to upload files.. i use the normal function move_uploaded_file($_FILES['song1_upload']['tmp_name'] can anyone give a better idea than this? I have made a script to upload a few files from the pc to my server.. like i upload big files which are generally above 50mb of size.. but most of the times as there is some problem with the internet the hours of wait is just ruined.. is there a better way to upload files.. or anything that if the internet connection is interupted the downloading starts from wer it stopped cuz of the problem.. please help.. i use the normal function for uploading a file move_uploaded_file($_FILES['song1_upload']['tmp_name'] can anyone give a better idea than this? I just came up with this idea I got for my registration script, where when the user has complete all steps in the registration process, he/she comes to a page that displays this: Code: [Select] <h1>Step 3: Activate your account</h1> <h2>Congratulations, <strong><?php echo $_SESSION["user"]["username"]; ?></strong>!</h2> <p>An email has been sent to <strong><?php echo $_SESSION["user"]["email"]; ?></strong> with an activation key, and important information regarding your account. Please check your email to complete registration.</p> Then this: Code: [Select] $email_client = preg_match ("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); $email_link = "<a href='http://www." . $email_client . ".com'>Go to " . $email_client . " mail now!</a>"; echo "<p class='center_align'>" . $email_link . "</p>"; Basically, what it does, is it figures out what email provider the user supplied as their email, and generates a link that allows them to go to that website, without having to type it in the address bar (I think I got that idea from facebook lol; only they probably do it differently). So anyway, It's not complete, and this is where I need someone's help... I assign a preg_match function to $email_client, so if it finds a string like "@yahoo.com", $email_client will be true, but that's not what I want. I want $email_client to equal a string, such as "yahoo" or "aol" based off of what the preg_match function finds, WITHOUT using if/else statements. Before I did an if/else statement for every email provider I could think of, but I think it better if I do it this way, as some people have crazy a** email names lol. So, basically what I want to do is this: Code: [Select] <?php //Step 1: Check email preg_match("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); //Step 2: Somehow assign the "a-zA-z0-9{10}" part to a variable //Step 3: Generate link with that variable used in the "href" attribute and the label ?> But I have no idea how to go about this...Help? Is PHP used to create this type is feature? I already have a MYSQL table set up, how difficult is it to create this sort of feature? On this image, where it says 'filter your results' if a user clicks 'Detached Houses' then only detached houses will be displayed. if a user clicks 'Semi-detached' then only semi detached houses will be shown. Whats the technical term for this type of feature, and can you point me towards any tutorials etc, would really appreciate it. thank you! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314222.0 I would like to have the option of thanking people by the press of a button.
Currently there is a like button but that's entirely different than a thank you button.
Alright, so i got this site, and what i'm trying to do is to allow a user to search for another user using their zip code. However i also want them to be able to select the radius...so say for example someone selects to find a user with in 5 miles of their zip code i want them to get all the people from their zip code as well as the ones that are 5 miles away in radius from their zip code. Does anyone have any examples or pages were i can find tutorials. Any help would be gladly appreciated This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=314473.0 I need help adding a feature to the following php script that goes through folders and reads from txt files. Right now it is just grabbing the sub folder name, title and body and exporting it to a csv in columns A B and C respectively. What I need it to do is grab a summary from each txt file as well and added to the 4th column in the csv. I think the best way to do this would be to grab from the beginning of the body, to pre-defined closing }. So If I set it at 25 it will end the summary on the 25th } found in the txt file from the beginning of the body. All the txt is in spintax format like "The {Fox|Bird|Cat} {Stole|Took} The {Food|Water}" Code: [Select] <?php set_time_limit(0); // set unlimited execution time $base_folder = $_POST['base_folder']; $article_to_capture = (int)$_POST['article_to_capture']; $words = explode(',', $_POST['words']); // print_r($words); die(''); if(!is_dir($base_folder)) die('Invalid base folder. Please go <a href="step1.php"><strong>back</strong></a> and enter correct folder.'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Artcle Scraper Step 2</title> <style type="text/css"> <!-- body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; } --> </style> </head> <body> <h2>Step 2 : Processing the content of the folder. </h2> <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC"> <tr bgcolor="#FFFFFF"> <th width="10%"> </td> <th width="30%">BASE FOLDER NAME</td> <th width="50%"> <?php echo $base_folder;?></td> <th width="10%"> </td> </tr> <?php $subfolder_arr = scandir($base_folder); //print_r($arr1); $total_subfolders = sizeof($subfolder_arr); $subfolder_count = 0; $file_count = 0; $report = ""; $fp = fopen('articles.csv', 'w+'); for($i=0; $i< $total_subfolders; $i++){ $file_name = $subfolder_arr[$i]; if($file_name=='.'||$file_name=='..') continue; $sub_folder_name = $base_folder ."\\". $file_name; $file_type = is_dir($sub_folder_name) ? 'dir' : 'file'; if($file_type=='dir'){ $sub_folder_count++; $rpeort .= "Processing folder $sub_folder_count $sub_folder_name \r\n"; $msg = "Processing folder $sub_folder_count $sub_folder_name \r\n"; ?> <tr bgcolor="#FFFFFF"><td> </td><td colspan="2"> <?php echo $msg;?> </td><td> </td></tr> <tr bgcolor="#FFFFFF"><td> </td><td colspan="2"> <table width="90%" cellpadding="0" cellspacing="0" border="1" bordercolorlight="#0000FF"> <?php // process sub folder $column1 = $file_name; $column2 = '{'; $column3 = '{'; $first = true; $files_arr = scandir($sub_folder_name); $article_processed =0; // article_processed in current sub folder foreach($files_arr as $key=>$val){ if(is_file($sub_folder_name.'\\'.$val) ) { if( substr($val,-4)=='.txt' && (filesize($sub_folder_name.'\\'.$val) <= 35000) && (filesize($sub_folder_name.'\\'.$val) >= 4000)) //file is > 1kb { $size = filesize($sub_folder_name.'\\'.$val); $article_processed++; if($article_to_capture==0 || $article_processed <= $article_to_capture ){ if($first==true) $first=false; else { $column2 .= '|'; $column3 .= '|'; } // read file get title and body $file_content = file($sub_folder_name.'\\'.$val); $file_title = rtrim($file_content[0]); $file_content[0] = ''; $file_arr_size = sizeof($file_content); $words_arr_size = sizeof($words); $t=1; while($t < $file_arr_size){ $file_content[$t] = rtrim($file_content[$t]); //echo $file_content[$t]; //die('inside'); if( $words_arr_size>0 ){ //die('inside'); $temp = str_replace($words, "", $file_content[$t]); $file_content[$t] = $temp; } $t++; //if($t>=3) die('aa'); } $file_body = implode('',$file_content); $column2 .= $file_title; $column3 .= $file_body; ?> <tr><td> <?php //print_r($files_arr); echo $val ."\r\n"; echo round(($size / 1024), 2).' KB'; ?> </td></tr> <?php } //end if .txt } // article processed } // end if is_file } // end foreach ?> </table> </td><td> </td></tr> <?php $column2 .= '}'; $column3 .= '}'; // write to csv / excel file $erro = fputcsv ($fp, array($column1,$column2,$column3) ); } //end if filetype else{ } } // end for fclose($fp); ?> <tr bgcolor="#FFFFFF"> <td> </td> <td colspan=""> File Generated. Download it <a href="articles.csv" target="_blank">HERE</a></td> <td> </td> </tr> </table> </body> </html> Twitter chat features : 1) use ajax to reload the page to get new data from database for every 10 seconds, 2) When the user scroll down to the bottom of page, it load the older 5 data from database. I have 3 files (index.php, message1.php and message2.php) On index.php, I use ajax to reload the page for every 10 seconds to call a php file (message1.php). On message1.php, I use mysql to retrieve 30 records from database and php to display the records to the index.php. ($last_msg_id to hold the id of last data in message1.php, then send the $last_msg_id to index.php) When user scroll down to bottom of the page, it will auto call other php file (message2.php) to display older 5 records from database. (index.php will send $last_msg_id_id to message2.php, so that message2.php will know which was the last data previously and display the older data where id is less than $last_msg_id, eg : $query2 = "SELECT id, message, datetime FROM messages WHERE id < '$last_msg_id' LIMIT 5"; Now my problem is when the ajax reload the index.php, the value of $last_msg_id is become empty. So if the user is on the half way scrolling to bottom of page to get older data, the older data will not show up, it will show up the previous data because the value of $last_msg_id is back to empty after page is reloaded by ajax. May I know how to fix this problem please? Maybe I should not reload the page for every 10 seconds to get new data? If without reload the page, how am I going to get new data when his friends posted new messages on other side? Hi, I wanted to know is there any class or functions which will parse the mail body and find all the features like how many sentences, how many stop words, how many paragraphs, how many punctuation chars, etc. I haven't find anything good in my searching so far. I have parsed the whole body of email and separated the headers and body in variables. Now I want to perform these operations in only in the body. Thank you in advance. Hi all, Thanks for reading. I have this code: Code: [Select] $message = strip_tags($_POST['message'], '<p><strong><em>'); My question is however, is there a way that I could disable the onmouseover features in those tags? Thank you. Hi all, I'm very new to the wonderful world of php, so I'd appreciate any and all help in the matter. I've greatly simplified the code below to hopefully help you in helping me. Thanks! Ok, so I'm integrating a very simple message board feature into my site. The basic idea is that people post a comment, and have the option of replying to existing comments. I'm definitely not looking for a complete forum; just something that allows users to post and reply. I've tackled the posting bit easily enough. I have a form. Users fill in the form and the message, along with user information, is sent to a MySQL database. The information includes the username(Poster), the message(Message), an id that corresponds to the topic in question(Messid), a unique ID code for the message itself (ID), and a number of other variables like date and rank. I then use a while statement to bring up all of the messages that pertain to a particular topic; The output will only show messages that share the same Messid, and they are arranged in terms of descending ID: Code: [Select] <? while($row = mysql_fetch_array($resultcomments)) { $poster=$row['Poster']; $message= $row['Message']; $ID=$row['ID']; echo $message.$poster.$ID; } So far, so good. What I want is for users to be able to click on any one of the particular messages, and post a response comment that will appear directly below the message to which it responds. Any ideas how I might go about such a task? So far, I've created a new MySQL table that corresponds to these "subcomments". Each subcomment has a "subID" that corresponds to the ID of the message to which it responds. By including a while statement within the while statement above, I can successfully list all of the subcomments that correspond to a message directly below it. The problem, of course, is that I have to insert the subID values manually in php_my_admin. I'm hoping there's a way for php to automatically detect the ID value of the message in question... Many many thanks for any assistance I can get. Once this revolution in communication makes me a billionaire, I will be certain to reward you most properly. Thanks again. I have a script that allows me to sort user submitted data either by category OR by date and I'd like to accomplish both at the same time, so my question is how can I do that? This is my script: <?php $select_category = $_REQUEST['sort_category']; $sort_date_var = $_REQUEST['sort_date']; // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (($select_category == 'All') || (!isset($select_category)) && (!isset($sort_date_var))) { // Retrieve the chosen category from MySQL $query3 = "SELECT * FROM con"; $data3 = mysqli_query($dbc, $query3); //Loop through the array of data while ($row3 = mysqli_fetch_array($data3)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row3['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row3['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . $row3['category'] . " | " . date('M d, Y', strtotime($row3['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } if ($select_category) { // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM con WHERE category = '$select_category'"; $data2 = mysqli_query($dbc, $query2); //Loop through the array of data while ($row2 = mysqli_fetch_array($data2)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row2['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row2['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row2['category']) . " | " . date('M d, Y', strtotime($row2['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } // SORT DATE BLOCK if ($sort_date_var) { // Retrieve the chosen category from MySQL $query4 = "SELECT * FROM con ORDER BY contributed_date $sort_date_var"; $data4 = mysqli_query($dbc, $query4); //Loop through the array of data while ($row4 = mysqli_fetch_array($data4)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row4['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row4['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row4['category']) . " | " . date('M d, Y', strtotime($row4['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } ?> The first block is the default state where ALL the data is being shown when the site is being visited. The second block sorts by category and the third by date. The problem is that only ONE of the last two blocks work at a time and I would like to have a combination of date and category sorting. Thanks for all the suggestions. |