Jump to content

peter162in

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by peter162in

  1. It is possible to calculate nearest date out side databse.. but what about nearest records as per date in the database...I still searching for a solution. any idea how to proceed..pls help me.Thanks in advance. I am a new be..not sound enough in good coding... Thank you.. Peter
  2. SELECT DISTINCT s.dog, COUNT(s.dog) AS entries, t.date I think some where u have to use DISTINCT... not sure..
  3. <td><a href="data.php?symbol=$symbol" >$symbol</td> This line passing variable to another page data.php.The data is taken from my sql data base. data looks like this 1. tea 2. cofee 3. tea&coffee When I using get on data.php $symbol = $_GET['symbol']; first two option works perfectly and the third one not working. beacuase there is & ampersand sign in the data. data after apersand sign get disappeared. I read the article of urlencode, htmlentities. not find a solution. please help me when I click the link I can seen the data is passed to data.php.Here my mind really confused.Something really wrong with me. 1.http://localhost/myusage/symbolwise.php?symbol=tea 2.http://localhost/myusage/symbolwise.php?symbol=cofee 3.http://localhost/myusage/symbolwise.php?symbol=tea&coffee for the third link Get not wroking please help me
  4. I have TABLE1 in which data arranged as per date-wise. I want to find data for previous MONTH/DAY when date is given. if there is no data on previous MONTH/DAY, my sql has to loop through to find available data for a nearest date.I am using this code. it is working fine but , It is manual way and limited to 2-5 days. Any idea to help me. Thanks in advance. $date1=$_GET['date']; $difference = strtotime ( '-1 month' , strtotime ( $date1 ) ) ; $date2=date ( 'Y-m-d' , $difference ) . "<br />\n" ; $sql2 = "SELECT item, price FROM table1 WHERE date='$date2'"; //first date $result2 = mysql_query($sql2) or die(mysql_error()); $totalrows = mysql_num_rows($result2); //gets the total number of rows with this information if ($totalrows != '0') { echo "date is not found in database $date2 !"; } else { $difference1 = strtotime ( ' -1 month -1 day' , strtotime ( $date1 ) ) ; echo "$difference1". "<br />". "<br />"; $date3=date ( 'Y-m-d' , $difference1 ) . "<br />\n" ; } $sql2 = "SELECT item, price FROM table1 WHERE date='$date3'"; // second date $result2 = mysql_query($sql2) or die(mysql_error()); $totalrows = mysql_num_rows($result2); if ($totalrows != '0') { echo "date is not found in database $date3!"; } else { $difference1 = strtotime ( ' -1 month -2 day' , strtotime ( $date1 ) ) ; echo "$difference1". "<br />". "<br />"; $date4=date ( 'Y-m-d' , $difference1 ) . "<br />\n" ; echo"$date4"; } $sql2 = "SELECT item, price FROM table1 WHERE date='$date4'"; // third date // Keep on //at leat for 5 days. while($row = mysql_fetch_array($result2)) { // additional code here
  5. Grate !,Thanks a lot. It is working.. I forget to scroll down through the code. seen half only. sorry for that. thank you very much.
  6. Please help something wrong I am a new b in programming. <?php include "dbcon1.php"; $sql = "SELECT date, price FROM `table1` ORDER BY table.date DESC"; $result = mysql_query($sql) or die(mysql_error()); $my_header=<<<EOD <h2><center>PROFIT ANALYSIS<font color="red" size="6"></h2> <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <th>DATE</th> <th>PRICE</th> <th>DIFF</th> </tr> EOD; $my_details = ''; $priordate = ''; $priorprice = null; while ($row = mysql_fetch_array($result)) { $date = $row['date']; $price = $row['price']; if ($priordate == '') { $priordate = $date; echo $priordate; $priorprice = $price; echo $priorprice; } echo $priorprice;// price captured remain as initial price $diff = $priorprice - $price; //PRIORPRICE($priorprice) REMAIN UNCHANGED AS DATE CAPTURED REMAIN THE INITIAL DATE $my_details .=<<<EOD <tr> <td>$date</td> <td><font color="red" size="4"> $price</td> <td><font color="red" size="4"> $diff</td> </tr> EOD; } $my_footer ="</table>"; $final =<<<RESULT $my_header $my_details $my_footer RESULT; echo $final; ?> MY RESULT DATE PRICE DIFF 2009-08-01 1232 0 2009-08-04 1250 18 2009-08-05 1273 41 2009-08-19 1181 -51 PRICE DIFF DISPLAYED FROM THE START DATE ACTUAL RESULT I EXPECT IS DATE PRICE DIFF 2009-08-01 1232 0 2009-08-04 1250 18 2009-08-05 1273 23 2009-08-19 1181 -92 THE DATE IS NOT CAPTURING . PLEASE HELP ME. if loop ?
  7. My complete code here. some where i do a mistake .the $priorprice is not updating in the final result. it remains same. <?php include "dbcon1.php"; $sql = "SELECT date, price FROM `table1` ORDER BY table.date DESC"; $result = mysql_query($sql) or die(mysql_error()); $my_header=<<<EOD <h2><center>PROFIT ANALYSIS<font color="red" size="6"></h2> <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <th>DATE</th> <th>PRICE</th> <th>DIFF</th> </tr> EOD; $my_details = ''; $priordate = ''; $priorprice = null; while ($row = mysql_fetch_array($result)) { $date = $row['date']; $price = $row['price']; if ($priordate == '') { $priordate = $date; echo $priordate; $priorprice = $price; echo $priorprice; } echo $priorprice;// price captured remain as initial price $diff = $priorprice - $price; //PRIORPRICE($priorprice) REMAIN UNCHANGED AS DATE CAPTURED REMAIN THE INITIAL DATE $my_details .=<<<EOD <tr> <td>$date</td> <td><font color="red" size="4"> $price</td> <td><font color="red" size="4"> $diff</td> </tr> EOD; } $my_footer ="</table>"; $final =<<<RESULT $my_header $my_details $my_footer RESULT; echo $final; ?> I think while running if loop is executed once , then it is bypassed on mysql_fetch_array? help please
  8. My complete code here. some where i do a mistake .the $priorprice is not updating in the final result. it remains same. <?php include "dbcon1.php"; $sql = "SELECT date, price FROM `table1` ORDER BY table.date DESC"; $result = mysql_query($sql) or die(mysql_error()); $my_header=<<<EOD <h2><center>PROFIT ANALYSIS<font color="red" size="6"></h2> <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <th>DATE</th> <th>PRICE</th> <th>DIFF</th> </tr> EOD; $my_details = ''; $priordate = ''; $priorprice = null; while ($row = mysql_fetch_array($result)) { $date = $row['date']; $price = $row['price']; if ($priordate == '') { $priordate = $date; echo $priordate; $priorprice = $price; echo $priorprice; } echo $priorprice;// price captured remain as initial price $diff = $priorprice - $price; //PRIORPRICE($priorprice) REMAIN UNCHANGED AS DATE CAPTURED REMAIN THE INITIAL DATE $my_details .=<<<EOD <tr> <td>$date</td> <td><font color="red" size="4"> $price</td> <td><font color="red" size="4"> $diff</td> </tr> EOD; } $my_footer ="</table>"; $final =<<<RESULT $my_header $my_details $my_footer RESULT; echo $final; ?> I think while running if loop is executed once , then it is bypassed on mysql_fetch_array? help please
  9. THANK YOU FOR GREAT HELP. A SMALL PROBLEM FOR THE RESULT while ($row = mysql_fetch_array($result)){ $date = $row['date']; $price = $row['price']; if ($priordate == '') { $priordate = $date;// Date is not looping . I faced this type of problem earlier also because of '{' braces $priorprice = $price; } MY RESULT DATE PRICE DIFF 2009-08-01 1232 0 2009-08-04 1250 18 2009-08-05 1273 41 2009-08-19 1181 -51 PRICE DIFF DISPLAYED FROM THE START DATE ACTUAL RESULT I EXPECT IS DATE PRICE DIFF 2009-08-01 1232 0 2009-08-04 1250 18 2009-08-05 1273 23 2009-08-19 1181 -92 THE DATE IS NOT CAPTURING . PLEASE HELP ME.
  10. NEED TO FIND DIFF . DATA ARRANGED IN DATE AND PRICE. FIND DIFF FOR EVERYDAY. MYSQL AND PHP. <?php include "dbcon1.php"; $sql = "SELECT date,price FROM `tb1` ORDER BY tb1.date DESC"; $result = mysql_query($sql) or die(mysql_error()); $1_header=<<<EOD <h2><center>PROFIT ANALYSIS<font color="red" size="6"></h2> <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <th>DATE</th> <th>PRICE</th> <th>DIFF</th> </tr> EOD; $1_details = ''; while ($row = mysql_fetch_array($result)) { $date = $row['date']; $price = $row['price']; $diff= ????????????????????????/ some body help $1_details .=<<<EOD <tr> <td>$date</td> <td> $price</td> <td> $diff</td> </tr> EOD; } $1_footer ="</table>"; $1 =<<<RESULT $1_header $1_details $1_footer RESULT; echo $1; ?>
  11. Thanks in advance. this is my code I derived from as your help.May be my question is mis interpreted. <?php include "dbcon1.php"; $date1=$_GET['date']; $sql = "SELECT * FROM table WHERE date=$date1; $result = mysql_query($sql) or die(mysql_error()); $totalrows = mysql_num_rows($result); //gets the total number of rows with this information if ($totalrows == '0') { echo"$totalrows". "<br />"; echo "Date is not in database"; $difference = strtotime ( '-1 month,-1 day' , strtotime ( $date1 ) ) ; $date2=date ( 'Y-m-d' , $difference ) . "<br />\n" ; echo"$date2". "<br />"; $sql3 = "SELECT * FROM table WHERE date='$date2'"; $result2 = mysql_query($sql3) or die(mysql_error()); $totalrows1 = mysql_num_rows($result2); //gets the total number of rows with this information echo"$totalrows1". "<br />"; } else { echo "date is found in database woot!"; } ?> Query should loop through if data is not there in the database! Now it is working if data is not there specified date( one date is reduced) . if more than one date is to reduced( data is not there for the second date also - program has to find nearest data available date -it has to loop through. Any Idea. Thank for great reply. I get something which I can think to get part of target. But for more accurate I need help .
  12. How to find out nearest date data available in my sqldata base, If data not exists for a particular date. for eg (without syntax) $date = getdate query select all where date is $date: now no data in the data base for this date. if empty result = $date = $date-1 keep on looping any way to proceed . any old page to get some reference thanks in advance
×
×
  • 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.