PHP - Display Records In Months And Days Table
Hello,
I am trying to display rainfall totals for the year so far in a table with months going across and days going down. Like so: -- Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1 2 3 4 5 6 7 8 etc And then have the rainfall totals for each day in the table, I am quite experienced with PHP however I cant work out how I would do this The data is stored in a mysql table called "wx_daily", and the rainfall column is called" RainTotal". The dates are stored in the "Date" column in mysql Date format. Im using the following mysql query: SELECT * FROM wx_daily WHERE YEAR(Date) = '2011' ORDER BY Date Asc Thanks, Mark Similar TutorialsHi, I have db field with date. I want to make select statement with where clause when part of the date (month) is true. Example, i have records from 2020-2-1 until 2020-4-3, i want to select records for march only 2020-3-1 to 2020-3-31. how to do that? I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy My script is finally working as intended, but I want to add some additional data results. I am trying to resolve how I can display a count of ONLY the records updated by my query: // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches In this query I count ALL records selection: // START :: Create query to be displayed as final results of original codes table. $result = mysql_query("SELECT * FROM orig_codes_1a") or die(mysql_error()); I want to display a count on this part of the query: ....concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2).... This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=342917.0 Hi guys. So I have a little coding down but I am stuck on this problem: /* Using only a array and a foreach loop, write a program that prints the days of the week *\ $days = array { 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', }; //This is where I need help with the code echo "$day \r\n"; ?> Thanks in advance! I am trying to make automated scoresheets for a soccer league. The problem i am having is it is only displaying the first record and repeating. Could someone please help me out with this? Thanks in advance. Code: [Select] <?php /* connection and protection */ include 'dbc.php'; // MATCH DATA $details = mysql_query("SELECT * FROM thirdsched_south WHERE id = '1'") or die(mysql_error()); // matchs data $match = mysql_fetch_array( $details ); // HOME TEAM $hometeam = mysql_query("SELECT * FROM players WHERE teamid = 'cloverda' AND approved ='1'") or die(mysql_error()); // store home data $home = mysql_fetch_array( $hometeam ); // AWAY TEAM $awayteam = mysql_query("SELECT * FROM players WHERE teamid = 'lefcb' AND approved ='1'") or die(mysql_error()); // Store AWAY DATA $away = mysql_fetch_array( $awayteam ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="public_smo_scripts.js"></script> <link href="styles.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .style1 { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 13px; } .style2 {font-size: 14px} .style3 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px; } --> </style> </head> <body onload="window.print()"> <table width="930" border="1"> <tr> <td colspan="2" class="style1 style1"><div align="center"><img src="bccsl-gmsh-hd.jpg"/></div></td> </tr> </table> <table width="930" border="1"> <tr> <td width="455" class="style1 style1"><div align="center" class="style2">Division: Third- South</div></td> <td width="459" height="32" class="style1 style1"><div align="center" class="style2">Date: <? echo $match['date']; ?> </div></td> </tr> <tr> <td class="style1 style1"><div align="center" class="style2">Time: <? echo $match['time']; ?> </div></td> <td height="36" class="style1 style1"><div align="center" class="style2">Field: <? echo $match['field']; ?> </div></td> </tr> <tr> <td class="style1 style1"><div align="center" class="style2">Home Team: <? echo $match['hometeam']; ?> </div></td> <td class="style1 style1"><div align="center" class="style2">Away Team: <? echo $match['awayteam']; ?></div></td> </tr> </table> <table width="930" border="1" cellspacing="0" cellpadding="0"> <tr> <th width="230" class="style1 style1" scope="col"><div align="center">Name</div></th> <th width="41" class="style1 style1" scope="col">#</th> <th width="41" class="style1 style1" scope="col">G</th> <th width="41" class="style1 style1" scope="col">A</th> <th width="71" class="style1 style1" scope="col">Cards</th> <th width="47" rowspan="38" class="style1 style1" scope="col"><img src="bccsl-gmsh-MD.jpg" width="47" height="657" /></th> <th width="227" class="style1 style1" scope="col"><div align="center">Name</div></th> <th width="46" class="style1 style1" scope="col">#</th> <th width="46" class="style1 style1" scope="col">G</th> <th width="43" class="style1 style1" scope="col">A</th> <th width="73" class="style1 style1" scope="col">C</th> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first'];?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td class="style1 style1"><div align="center"><? echo $home['first']; ?> <? echo $home['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center"><? echo $away['first'];?> <? echo $away['last'];?></div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> <tr> <td bgcolor="#666666" class="style1 style1"><div align="center"></div></td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"><div align="center"></div></td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> <td bgcolor="#666666" class="style1 style1"> </td> </tr> <tr> <td height="43" class="style1 style1"><div align="center" class="style2">TOTALS</div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"><div align="center" class="style2">TOTALS</div></td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> <td class="style1 style1"> </td> </tr> </table> <table width="930" border="1"> <tr> <td width="447" class="style3">MANAGERS<br /> SIGNATU _______________________________</td> <td width="467" class="style1"><p class="style2">MANAGERS<br /> SIGNATU ________________________________</p></td> </tr> <tr> <td height="48" class="style1"><p class="style2">REFEREE<br /> SIGNATU _______________________________</p> </td> <td class="style1 style2">REFFEREE<br /> COMMENTS:</td> </tr> <tr> <td colspan="3" class="style1 style1"><div align="center" class="style2">Game Report is due within 24hrs. Email Report to scores@bccsl.org or fax to 604-677-5846</div></td> </tr> </table> </body> </html> Hi all. I have an issue and don't know how to go about it. I have a table that contains user orders. I want to move only orders that will be due in 10 days time to another table. How can I achieve that? thanks enter code hereI am New to PHP but i did pull off (with help of a friend) this piece of code. i am stuck at the part to display Image (it is Blank) and move through records (nothing happens). This is the whole PHP code. Any positive response will be highly appreciated. Thanx in advance. Hello: I am trying to select all the records from a table, and display them. Having an issue... This is the code: Code: [Select] <ul> <?php $query = mysql_query("SELECT id,mySectionTitle FROM myWebSiteData"); while($menuData = mysql_fetch_array($query)) { <li><a href="a_websiteData.php?id=" .echo $menuData['id'] ."">echo $menuData['mySectionTitle']</a></li> } ?> </ul> This is the error: Code: [Select] Parse error: syntax error, unexpected '<' in /html/admin/a_websiteData.php on line 91 line 91 is the one that starts with "<li>" What am I missing, or what would be the best way to do this? Hello Everyone, I wanted to know how to Display records from a Table one by one at difference time intervals. Kindly suggest Hello All, Iam completely new (3days old) to sql, php, html, so could do with a little help. Ok so I just found out about this wonderfull world and thought i would give it a try and I like it. But as I have no real idea of what Iam doing Iam finding it abit tricky to change some of the code I found at. http://www.phpfreaks.com/tutorial/simple-sql-search By the way thanks for this. So far I have setup a wamp server and got it all working fine and tweeked the above details in the url. This works great (well chuffed). But I could do with changing two things for now. 1). I could do with beeing able to search multiple things in the one text box for example. If I inputed "hello world" or "hel wor" it would search through the 19,000 lines in my database and find all instances of "hello" and "world" or "hel" "wor" in the same line's, it dosent matter what column they are in and output those lines. The code has the option to search all feilds "matchall" but not multiple words or parts of words.(hope that made sense I dont know all the terminology) It could be like using wild cards I suppose??. Is this possible or would I need multiple search boxes and if so how would I do that? 2). I would like the results to be returned in a table with headings for each column. If any one can help this would be great and thanks in advance for checking the long post out. Nick. Sorry if this is out there already but not to sure what I need to search for!??!?!? Ill include what Iam using so far. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'root'; $dbPass = ''; $dbDatabase = 'Stk_search'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, Stock_Code, SV_Part_Number, SV_Description, SV_Search_Key FROM stkdb1 WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['Stock_Code'])?"`Stock_Code` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['SV_Part_Number'])?"`SV_Part_Number` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['SV_Description'])?"`SV_Description` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['SV_Search_Key'])?"`SV_Search_Key` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`Stock_Code` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `Stock_Code`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['Stock_Code']}<br />{$row['SV_Part_Number']}<br />{$row['SV_Description']}<br />{$row['SV_Search_Key']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Stock_Code: <input type="checkbox" name="Stock_Code" value="on" <?php echo isset($_GET['Stock_Code'])?"checked":''; ?> /> | SV_Part_Number: <input type="checkbox" name="SV_Part_Number" value="on" <?php echo isset($_GET['SV_Part_Number'])?"checked":''; ?> /> | SV_Description: <input type="checkbox" name="SV_Description" value="on" <?php echo isset($_GET['SV_Description'])?"checked":''; ?> /> | SV_Search_Key: <input type="checkbox" name="SV_Search_Key" value="on" <?php echo isset($_GET['SV_Search_Key'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> I have several forms which will request the user to select one of several options where the most common choices will be pronounced, and might look something like: Select Option A Select Option B Select Option C Select Option D Click here for more choicesThe client is responsible to determine which ones to display (opposed to hiding within "more choices") and the server is responsible to provide the list of options along with some means to determine which ones are most common. For a new user, the order will be based on my "best guess", however, whenever a user selects a given option its ranking for that user only should go up, and in addition more recent activities should have more bearing on the returned order. In addition, there will be more than one of these lists and each of these lists will expose a public identifier (most will use a string but some might use an incrementing integer series) instead of the primary key. I have some fragmented ideas how to best implement but would like other people's thoughts on how to best do so. Starting with the list schema, undecided on which approach below. Any preferences or something else altogether? Solution 1: abstract_list - id (INT PK) - discriminator (string) - name (string unique with discriminator) - ranking (TBD whether float or integer. This represents my initial "best guess") list1 (list2, etc) - id (FK to abstract_list.id) - discriminator (FK to abstract_list.discriminator) - public_id (string or integer based on specific list. unique with discriminator) Solution 2: abstract_list - id (INT PK) - discriminator (string) - name (string unique with discriminator) - ranking (TBD whether float or integer. This represents my initial "best guess") - public_id (Application responsible to cast as string or integer. unique with discriminator) list1 (list2, etc. This class has no properties and only a method to cast the public ID as required. Seems like a waste...) - id (FK to abstract_list.id)
user_list_ranking - abstract_list_id - user_id - ranking (TBD) To retrieve the list options, will query abstract_list and LEFT JOIN user_list_ranking and then sort on some mathematical formula acting on abstract_list.ranking and COALESCE(user_list_ranking.ranking, 0). To promote recent activity, maybe increment user_list_ranking.ranking every time the user selects a given option and also decrement all other options of the associated list. To prevent excessive windup, cap the the value to some max value (i.e. If list1 has a total of 10 records, cap it three times that value resulting in 30), and cap the minimum at zero. Uncharted territory here and am very open to other approaches. I am undecided whether I should just return an ordered array of the options, or also include either an order integer or some normalized value from 0 to 1. If there is a common way to do this, please let me know what it is so I may mimic it. If not, please provide any critique or recommended changes to my intended approach. Thanks Hi all, I am having difficulty getting my UPDATE script to work. Basically the info is being pulled from a form and then being UPDATED, but it doesn't actually update and I am presented with no errors. It finds the record correctly and displays in the fields in the form as it should, just no update! Any ideas? Thanks in advance... Code: [Select] <?php error_reporting (E_ALL ^ E_NOTICE); $usr = "fdgdg"; $pwd = "dgdg"; $db = "dgdg"; $host = "dgdg.ddg.dg.50dgdg /***********************Get Record***********************/ $ref = (!empty($_GET['ref']))?trim($_GET['ref']):""; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid){ echo("ERROR: " . mysql_error() . "\n"); } $db_selected = mysql_select_db(database, $cid); $query = sprintf("SELECT * FROM fleet where fleetref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%"); $result = mysql_query($query) or die($query."<br>".mysql_error()); $record = mysql_fetch_assoc($result); if(mysql_num_rows($result) > 0) { echo "<strong>Updating fleet vehicle</strong>"; $fleetref=$record["ref"]; $fleetmake=$record["fleetmake"]; $fleetmodel=$record["fleetmodel"]; $fleetberth=$record["fleetberth"]; $fleetyear=$record["fleetyear"]; $fleetlength=$record["fleetlength"]; $fleetchassis=$record["fleetchassis"]; $fleetengine=$record["fleetengine"]; $fleetlayout=$record["fleetlayout"]; $fleettype=$record["fleettype"]; $fleetcomments=$record["fleetcomments"]; $pricelow=$record["pricelow"]; $pricemid=$record["pricemid"]; $pricehigh=$record["pricehigh"]; $fleetof=$record["fleetof"]; }else{ echo "<div id=\"pages\"><strong>Record not found</strong> - Edit Directory</div>"; $fleetmake=""; $fleetmodel=""; $fleetberth=""; $fleetyear=""; $fleetlength=""; $fleetchassis=""; $fleetengine=""; $fleetlayout=""; $fleettype=""; $fleetcomments=""; $pricelow=""; $pricemid=""; $pricehigh=""; $fleetof=$record["fleetof"]; } if ($fleetof == $account) { /***********************Save Record***********************/ # this is processed when the form is submitted # back on to this page (POST METHOD) if (isset($_POST['submit'])){ $fleetmake=$_POST["fleetmake"]; $fleetmodel=$_POST["fleetmodel"]; $fleetberth=$_POST["fleetberth"]; $fleetyear=$_POST["fleetyear"]; $fleetchassis=$_POST["fleetchassis"]; $fleetengine=$_POST["fleetengine"]; $fleetlayout=$_POST["fleetlayout"]; $fleetlength=$_POST["fleetlength"]; $fleettype=$_POST["fleettype"]; $fleetcomments=$_POST["fleetcomments"]; $pricelow=$_POST["pricelow"]; $pricemid=$_POST["pricemid"]; $pricehigh=$_POST["pricehigh"]; # setup SQL statement $query = sprintf("UPDATE `fleet` SET `fleetmake` = '%s',`fleetmodel` = '%s',`fleetberth` = '%s',`fleetyear` = '%s',`fleetchassis` = '%s',`fleetengine` = '%s',`fleetlayout` = '%s',`fleetlength` = '%s',`fleettype` = '%s',`fleetcomments` = '%s',`pricelow` = '%s',`pricemid` = '%s',`pricehigh` = '%s' WHERE `fleetref` ='%s' LIMIT 1", mysql_real_escape_string($fleetmake),mysql_real_escape_string($fleetmodel),mysql_real_escape_string($fleetberth),mysql_real_escape_string($fleetyear),mysql_real_escape_string($fleetchassis),mysql_real_escape_string($fleetengine),mysql_real_escape_string($fleetlayout),mysql_real_escape_string($fleetlength),mysql_real_escape_string($fleettype),mysql_real_escape_string($fleetcomments),mysql_real_escape_string($pricelow),mysql_real_escape_string($pricemid),mysql_real_escape_string($pricehigh),mysql_real_escape_string($fleetref)); #execute SQL statement $result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error()); # check for error if (!$result){ echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo "<P>Fleet vehicle updated</P>\n"; } } else {echo "Sorry, you are not authorised to edit this vehicle, please contact the system administrator for further help.";} ?> Hi I'm using this code to insert multiple records. The code executes but nothing is entered into my database. This usually happens when there's a mismatch in data types.
How do I ensure that description goes in as text which in sql is wrapped in single quotes, but also make sure the other variables go in as numeric.
// an array items to insert $array = array( 'theid' => $theid, 'descr' => $descr, 'costperunit' => $costperunit, 'quantity' => $quantity, 'costperlot' => $costperlot ); // begin the sql statement $sql1 = "INSERT INTO descriptions (jobid, description, costperunit, quantity, costperlot) VALUES "; $it = new ArrayIterator( $array ); // a new caching iterator gives us access to hasNext() $cit = new CachingIterator( $it ); // loop over the array foreach ( $cit as $value ) { // add to query $sql1 .= "('".$cit->key()."','" .$cit->current()."')"; if( $cit->hasNext() ) { $sql1 .= ","; } } Hi all. I built an online finance tracking thingy for myself and I got it to work using the following database table and PHP code. I didn't write the PHP code, rather, I edited it to suit my needs. It works great for my needs. I have a way to enter records and view the last 180 records in a table. The thing is, while viewing the table, I would lke to be able to edit and delete records. I don't know enough to be able to do this. Can it be done? I realize my PHP code would probably, for the most part, be totally different. Thanks for any help with this. Here is my DB table structu Code: [Select] DROP TABLE IF EXISTS `money`; CREATE TABLE IF NOT EXISTS `money` ( `id` int(5) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `type` varchar(18) NOT NULL, `checking` decimal(5,2) NOT NULL DEFAULT '0.00', `cash` decimal(5,2) NOT NULL DEFAULT '0.00', `description` varchar(25) NOT NULL, `who` varchar(25) NOT NULL, `note` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; And here is the PHP: Code: [Select] <?php $result = mysql_query ('SELECT date, type, checking, cash, who, description, note' . ' FROM money' . ' ORDER BY date DESC LIMIT 0,180') or die(mysql_error()); echo "<table border='1' cellpadding='5'>"; echo "<tr><th>Date</th><th>Type</th><th>Checking</th><th>Cash</th><th>Who?</th><th>Description</th><th>Note</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['type']; echo "</td><td>"; echo $row['checking']; echo "</td><td>"; echo $row['cash']; echo "</td><td>"; echo $row['who']; echo "</td><td>"; echo $row['description']; echo "</td><td>"; echo $row['note']; echo "</td></tr>"; } echo "</table>"; ?> Hi, I have contact form in my website project. Users fill First name ,Last Name ,Email etc information. I do not want to create database and table to store this information. I want to store this information in XML file. When user will add information then information will be added in XML file. Any solution for this ? - Thanks I'm sorry to be back so soon, but I'm up against another mystery. I'm using the code below to enter a bunch of css data from a spreadsheet into a mysql table. I think the data file is OK. The array created by the script checks out with print_r. (There are many more records than shown. I truncated it to save space.) The problem is that I get this error regarding my sql statement, not the data or anything else: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'check, name, phone, email, entry_fee, print_fee, image_name, description, med...' at line 1 in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php:242 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php(242): PDO->prepare('INSERT INTO tbl...') #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php on line 242 I've typed it in a dozen times to make sure there are no errors and keep getting the same error. I tried running a test file and gradually increasing the number of placeholders and at some point I always end up getting the same error, I can delete the most recent addition and it works again. Then I can add another placeholder exactly as before and it works the second time. It feels like a ghost in the machine. Any idea what I am doing wrong? An I typing something I don't see? <?php require '__classes/Db.php'; $csvData = '1,FALSE,Carol Lettko,,,TRUE,FALSE,Carol_Lettko-DSC_3022.jpg,Baby Herons/Brickyard,photo,,, ,,,925-285-0320,cjl164@aol.com,,,Carol_Lettko-DSC_0164.JPG,Heron/Brickyard,photo,,, ,,,,,,,Carol_Lettko-IMG_5723.jpg,Kayaker/Brickyard,photo,,, ,,,,,,,,,,,, 2,FALSE,Louise Williams,,,TRUE,FALSE,Louise_Williams-BirdsOfAFeatherAOPR.jpg,Alligator with Words,Book Excerpt,,, ,,,510-232-9547,lkw@louisekwilliams.com,,,Louise_Williams-Hope-TheFairyChickenAOPR.jpg,Hope The Fairy Chicken,,,, ,,,The d exatrfrfvct/.*tygrvurr,,,,,,,,, ,,,,,,,,,,,, 3,TRUE,Dorothy Leeland,,lelanddorothy@gmail.com,TRUE,FALSE,DJ_Lee-bridge at dusk 700px width.jpg,Bridge,photo,,, ,,,,,,,DJ_Lee-friends 700px width.jpg,Friends,photo,,, ,,,,,,,DJ_Lee-hybiscus 700 px wide.jpg,Hibiscus,photo,,, ,,,,,,,,,,,, 4,FALSE,Rita Gardner,,,TRUE,FALSE,Rita_Gardner-Explosion - Gardner photo.JPG,Explosion,photo,,, ,,,,tropicrita@msn.com,,,Rita_Gardner-Ferry Point tables and chair - Gardner.JPG,Ferry Point Tables,photo,, , ,,,,,,,Rita_Gardner-Forks - Gardner photo.JPG,Forks,photo,,, ,,,,,,,,,,,, '; $lines = explode(PHP_EOL, $csvData); $array1 = array(); foreach ($lines as $line) { $array1[] = str_getcsv($line); } $stmt = $pdo->prepare("INSERT INTO tbl_person_data (number, check, name, phone, email, entry_fee, print_fee, image_name, description, medium, select, orient, site) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); foreach ($array1 as $row) { $stmt->execute('$row'); } echo '<pre>'; print_r($array1); echo '</pre>'; ?>
Hi, I have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks How do you do this? Thanks in advance. [ Newbie Alert ] Hi i have an array of 39 arrays. Only 5 are shown below so that you have an idea before i ask my question. <? array(39) { [0]=> array(3) { [0]=> string(18) "unit name 1" [1]=> string(9) "category name 1" [2]=> string(20) "Course 1" } [1]=> array(3) { [0]=> string(54) "unit name 2" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [2]=> array(3) { [0]=> string(29) "unit name 3" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [3]=> array(3) { [0]=> string(64) "unit name 4" [1]=> string(30) "category name 3" [2]=> string(20) "Course 2" } [4]=> array(3) { [0]=> string(57) "unit name 5" [1]=> string(24) "category name 1" [2]=> string(20) "Course 1" } [5]=> array(3) { [0]=> string(50) "unit name 6" [1]=> string(24) "category name 4" [2]=> string(20) "Course 2" } } i want a php solution to print category names in table headers , unit names in table rows and course name(s) in table caption.I have tried foreach loop but how to remove duplicate entries as you can see category name 1 and 2 will become two separate headers instead of one and same is the case with Course 1 and 2. i have googled but could'nt find any solution. i don't want to remove duplicate entries , all i want to display them once in a table as described above. |