Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Title, description and pubDate are child elements, not attributes foreach($xml->channel as $channel) { $incident_data_title = $channel->item->title; $incident_data_desc = $channel->item->description; $incident_data_date = $channel->pubDate; $incident_data_updated = DATE("D, M d, g:i a", STRTOTIME($incident_data_date)); echo 'Title: ' . $incident_data_title . '<br>'; echo 'Desc: ' . $incident_data_desc . '<br>'; echo 'Date: ' . $incident_data_date . '<br>'; }
  2. This may help. You will need to edit the include file "dbconnect.php" to set host, user,password and default db then run "ChangePwd.php". The other php files are for building the menus of table and col names dynamically. When you select the column to be updated it will display a preview of the record to be updated if the password field is matched. Note that this assumes you are storing your passwords as plain text. If not you will need to add your hashing code to the update bit at the top of the ChangePwd.php file and also the search code in "ChangePwd_ajax_p.php" changePwd.php changePwd_ajax_c.php changePwd_ajax_p.php changePwd_ajax_t.php dbconnect.php
  3. You want to know where the price = MAX(price). The WHERE clause is a boolean expression and selects those records where it evaluates to TRUE. Your WHERE clause (WHERE MAX(price)) always evaluates to true unless the max price is 0 and so selects all records edit: Because you use an aggregation function (MAX, MIN, SUM, COUNT etc) without a group by, you only get a single row returned.
  4. It's times like this you are glad you normalized your data so a string literal value only occurred in one record in one table. If you do take the multi-looping approach given to you by Mac_Gyver, I would recommend you first do a select and display the values and their locations prior to doing a replace just in case it finds some you do not want to change.
  5. Here's one way <?php // CREATE AN ARRAY OF 39 ITEMS AS TEST INPUT $arr = array(); for ($i=1; $i<=39; $i++) $arr[] = "ITEM $i"; // BREAK ARRAY INTO CHUNKS OF 3 ITEMS $chunks = array_chunk($arr, 3); // OUTPUT THE ARRAY IN A 3-COLUMN TABLE echo "<table border='1' cellpadding='2'>"; foreach ($chunks as $chunk) { echo "<tr><td>" . join("</td><td>", $chunk) . "</td></tr>"; } echo "</table>"; ?> Gives
  6. try $filen = '2014 Jan - yadayada.csv'; list($Y, $m) = sscanf($filen, '%s %s - %s'); $start = date('Y-m-d', strtotime("01 $m $Y")); $end = date('Y-m-t', strtotime("01 $m $Y")); $fp = fopen($filen,'r'); $data = array(); $rec = fgetcsv($fp, 1024); // read and ignore header line while ($rec = fgetcsv($fp, 1024)) { array_unshift($rec, $start, $end); $rec[11] = filter_var($rec[11], FILTER_SANITIZE_NUMBER_INT); $rec[12] = filter_var($rec[12], FILTER_SANITIZE_NUMBER_INT); $rec[14] = filter_var($rec[14], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $data[] = $rec; } echo '<pre>',print_r($data, true),'</pre>'; Gives Array ( [0] => Array ( [0] => 2014-01-01 [1] => 2014-01-31 [2] => Stuart Street Timelapse 28/05/2013 [3] => http://www.youtube.c...j2yanlol [4] => [5] => Limbo (7th Hour Instrumental)-Noah Becker [6] => USA2P1265247 [7] => Marta Krupa [8] => VG Group [9] => Dance,electric,pop,club,great,female,zedd,dea [10] => 0 [11] => 2 [12] => 2 [13] => Sound Recording [14] => 0.01 ) [1] => Array ( [0] => 2014-01-01 [1] => 2014-01-31 [2] => NIGHT CLUB GROOV3 - DANCE FITNESS WORKOUT - WITH BENJAMIN ALLEN [3] => http://www.youtube.c...weatlive [4] => [5] => Dance Sweat Live [6] => USQY51161867 [7] => [8] => VG Group [9] => [10] => 30 [11] => 4814 [12] => 4844 [13] => Composition [14] => 6.44 ) )
  7. Why not just try it and see? echo $_GET['value'];
  8. ... WHERE YEAR(dbdate) = $year AND MONTH(dbdate) = $month
  9. No need for the switch for each month. For example $filenames = array( '2014 Jan - yadayada.csv', '2014 Feb - yadayada.csv', '2014 Mar - yadayada.csv', '2014 Apr - yadayada.csv' ); printf ("%-30s | %-15s | %-15s\n\n", "Filename", "Start Date", "End Date"); foreach ($filenames as $filen) { list($Y, $m) = sscanf($filen, '%s %s - %s'); $start = date('Y-m-d', strtotime("01 $m $Y")); $end = date('Y-m-t', strtotime("01 $m $Y")); printf ("%-30s | %-15s | %-15s\n", $filen, $start, $end); } Gives Filename | Start Date | End Date 2014 Jan - yadayada.csv | 2014-01-01 | 2014-01-31 2014 Feb - yadayada.csv | 2014-02-01 | 2014-02-28 2014 Mar - yadayada.csv | 2014-03-01 | 2014-03-31 2014 Apr - yadayada.csv | 2014-04-01 | 2014-04-30 As for your other problems, intval and floatval will only convert as far as the first non-numeric character echo intval('4,567'); // ==> 4 echo floatval('$5.999'); // ==> 0 so you need to strip out the '$' and the commas (str_replace). Could help more if I knew what your input looks like and what you are trying to insert into
  10. SELECT * FROM products WHERE gender = 'Mens' AND type = 'T-Shirt' AND price = ( SELECT MAX(price) FROM products WHERE gender = 'Mens' AND type = 'T-Shirt' )
  11. Something like this <?php $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); // use your credentials $sql = "SELECT songtitle FROM mytable"; $playlist = array(); $res = $db->query($sql); while ($row = $res->fetch_assoc()) { $playlist[] = $row['songtitle']; } $songs = join('","', $playlist); ?> <script type='text/javascript'> var playlist = new Array("<?php echo $songs; ?>"); </script>
  12. here's one way $filename = '2014 Jan - Claims Report.csv'; list($Y, $m) = sscanf($filename, '%s %s - %s'); echo "Year = $Y <br>"; // convert 'Jan' to '1' echo "Month = " . date('n', strtotime("01 $m $Y")); // recognises dd MMM YYYY format /*** OUTPUT *** Year = 2014 Month = 1 */
  13. You are doing a lot of unnecessary processing. You can replace $id3 = $_POST['selector_cat_p']; $N = count($id3); for($i=0; $i < $N; $i++) with foreach ($_POST['selector_cat_p'] as $catid) Your query $result = mysqli_query($conn, "SELECT * FROM category_p where id='$id3[$i]'"); is also a waste of time. You use SELECT * when all you want is the $row[id] column, and secondly, why retrieve a row to get the id when you already have the id to do the search in the first place? Thirdly, when you only retrieve one record, why use a while loop ? Finally, you don't do any escaping/sanitizing of data before using in the queries.
  14. It may not do what you want but you asked for an example of what I meant by using a single query and not looping to fetch and update data. That is what I gave you As for your $id problem I have no idea what you are holding in that value at the start of your code so I cannot say whether it is a simple variable or an an array, just that it won't be both. To avoid using it as both, use different variable names.
  15. How many answers do you you want to this question? http://forums.phpfreaks.com/topic/288219-mysql-query-question/?do=findComment&comment=1478080
  16. Here's an example of updating categories using checkboxes. (Uses the tables you originally posted) The form: <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); $homeid = isset($_GET['homeid']) ? intval($_GET['homeid']) : ''; if ($homeid) { $sql = "SELECT cat.id as catid , cat.name , IF(l.category_p_id IS NULL, '', 'checked') as checked FROM home CROSS JOIN category_p cat LEFT JOIN link_category_p_home l ON home.id = l.home_id AND cat.id = l.category_p_id WHERE home.id = $homeid ORDER BY cat.id"; $res = $db->query($sql); $formdata = "<input type='hidden' name='homeid' value='$homeid'>\n"; while (list($cid, $cat, $chk) = $res->fetch_row()) { $formdata .= "<input type='checkbox' name='cat[]' value='$cid' $chk /> $cat<br/>\n"; } $formdata .= "<input type='submit' name='btnSub' value='Update'>\n"; } ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <title>Example- Checkboxes</title> <meta name="author" content="Barand"> <meta name="creation-date" content="05/09/2014"> </head> <body> <form name='form1'> Enter Home ID <input type="text" name="homeid" value="<?php echo $homeid?>" size="5"> <input type="submit" name="btnSubmit" value="Get categories"> <hr/> </form> <form name='form2' method='post' action='php2014_updt.php'> <?php if (isset($formdata)) { echo $formdata; } ?> </form> </body> </html> The update: <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); if (!isset($_POST['homeid']) || !isset($_POST['cat'])) { header("Location: php2014_form.php"); exit; } $homeid = intval($_POST['homeid']); # # Delete existing category links # $sql = "DELETE FROM link_category_p_home WHERE home_id = $homeid"; $db->query($sql) or die($db->error . "<pre>$sql</pre>"); # # Add revised category links # $catdata = array(); foreach ($_POST['cat'] as $catid) { $catdata[] = sprintf("(%d, %d)", $homeid, intval($catid)); } $sql = "INSERT INTO link_category_p_home (home_id, category_p_id) VALUES " . join(',', $catdata); $db->query($sql); header ("Location: php2014_form.php"); ?>
  17. Could be better! You shouldn't be running queries inside a loop. Use a single query to join the tables and get all the required data in a single query. EDIT: I knew I had written similar query to do this sort of thing recently so I did a search - only to find it was earlier in this same thread.
  18. php is probably suffering from the same confusion as I am reading your code. On line 1 of part 1 you refer to $id as a string (or int) value but on line 5 and thereafter you use it as though it is an array. Decide which it is.
  19. If it helps, I'd do like this <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); /* THE TEST DATA +----+---------------------+---------------------+--------+ | id | startdate | enddate | client | +----+---------------------+---------------------+--------+ | 1 | 2014-05-05 10:00:00 | 2014-05-05 15:00:00 | Dan | | 2 | 2014-05-05 16:00:00 | 2014-05-05 18:00:00 | Mary | | 3 | 2014-05-06 09:00:00 | 2014-05-06 11:00:00 | Harry | | 4 | 2014-05-06 15:00:00 | 2014-05-06 16:00:00 | Jane | +----+---------------------+---------------------+--------+ */ $sql = "SELECT DATE(startdate) as date , HOUR(startdate) as stime , HOUR(enddate) as etime , client FROM diary ORDER BY startdate, enddate"; $res = $db->query($sql); // ARRAY OF THE DAILY TIME PERIODS $periods = array_fill_keys(range(9,17), ''); $currentDate = ''; $tableData = ''; while (list($date, $stime, $etime, $client) = $res->fetch_row()) { // HAS DATE CHANGED? if ($date != $currentDate) { if ($currentDate) { // OUTPUT THE ROW FOR THE DAY $tableData .= "<tr><th>".date('D jS M', strtotime($currentDate))."</th>"; foreach ($dayRow as $name) { $cls = ($name=='') ? 'free' : 'booked'; $tableData .= "<td class='$cls'>$name</td>"; } $tableData .= "</tr>\n"; } $dayRow = $periods; // SET ROW ARRAY TO EMPTY TIME PERIODS ARRAY $currentDate = $date; // SET CURRENT DATE TO NEW DATE VALUE } // SET TIME PERIODS AS BOOKED for ($h=$stime, $first = 1; $h<$etime; $h++) { $dayRow[$h] = ($first) ? $client : ' '; // SHOW CLIENT IN FIRST CELL ONLY $first = 0; } } // OUTPUT DATA FOR THE FINAL DAY $tableData .= "<tr><th>".date('D jS M', strtotime($currentDate))."</th>"; foreach ($dayRow as $name) { $cls = ($name=='') ? 'free' : 'booked'; $tableData .= "<td class='$cls'>$name</td>"; } $tableData .= "</tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <title>sample diary</title> <meta name="author" content="Barand"> <style type='text/css'> table { border-collapse: collapse; } th { color: white; background-color: #888; padding: 5px; } td { height: 40px; padding: 5px; } .free { background-color: #CFC; } .booked { background-color: #FCC; } </style> </head> <body> <table border='1'> <tr> <th>Day</th> <th>09-10</th> <th>10-11</th> <th>11-12</th> <th>12-13</th> <th>13-14</th> <th>14-15</th> <th>15-16</th> <th>16-17</th> <th>17-18</th> </tr> <?php echo $tableData; ?> </table> </body> </html> Giving this
  20. Your original post was to show a different shading so I used the array for the CSS class names but you could always use the same array to store the client instead and set the class depending on whether or not there is a client name.
  21. Barand

    Data Import

    The IGNORE should come before the column list
  22. DROP TABLE IF EXISTS `diary`; CREATE TABLE `diary` ( `id` int(11) NOT NULL AUTO_INCREMENT, `startdate` datetime DEFAULT NULL, `enddate` datetime DEFAULT NULL, `client` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ); INSERT INTO diary VALUES (1, '2014-05-05 10:00:00', '2014-05-05 15:00:00', 'Dan'), (2, '2014-05-05 16:00:00', '2014-05-05 18:00:00', 'Mary'), (3, '2014-05-06 09:00:00', '2014-05-06 11:00:00', 'Harry');
  23. Here's a simple example pulling dates and times from a db an displaying in shaded areas in a table. CSS styles to denote whether a time period is "free" or "booked" <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); /* THE TEST DATA +----+---------------------+---------------------+--------+ | id | startdate | enddate | client | +----+---------------------+---------------------+--------+ | 1 | 2014-05-05 10:00:00 | 2014-05-05 15:00:00 | Dan | | 2 | 2014-05-05 16:00:00 | 2014-05-05 18:00:00 | Mary | | 3 | 2014-05-06 09:00:00 | 2014-05-06 11:00:00 | Harry | +----+---------------------+---------------------+--------+ */ $sql = "SELECT DATE(startdate) as date , HOUR(startdate) as stime , HOUR(enddate) as etime , client FROM diary ORDER BY startdate, enddate"; $res = $db->query($sql); // ARRAY OF THE DAILY TIME PERIODS $periods = array_fill_keys(range(9,17), 'free'); $currentDate = ''; $tableData = ''; while (list($date, $stime, $etime, $client) = $res->fetch_row()) { // HAS DATE CHANGED? if ($date != $currentDate) { if ($currentDate) { // OUTPUT THE ROW FOR THE DAY $tableData .= "<tr><th>".date('D jS M', strtotime($currentDate))."</th>"; foreach ($dayRow as $d) { $tableData .= "<td class='$d'></td>"; } $tableData .= "</tr>\n"; } $dayRow = $periods; // SET ROW ARRAY TO EMPTY TIME PERIODS ARRAY $currentDate = $date; // SET CURRENT DATE TO NEW DATE VALUE } // SET TIME PERIODS AS BOOKED for ($h=$stime; $h<$etime; $h++) { $dayRow[$h] = 'booked'; } } // OUTPUT DATA FOR THE FINAL DAY $tableData .= "<tr><th>".date('D jS M', strtotime($currentDate))."</th>"; foreach ($dayRow as $d) { $tableData .= "<td class='$d'></td>"; } $tableData .= "</tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <title>sample diary</title> <meta name="author" content="Barand"> <style type='text/css'> table { border-collapse: collapse; } th { color: white; background-color: #888; padding: 5px; } td { height: 40px; } .free { background-color: #CFC; } .booked { background-color: #FCC; } </style> </head> <body> <table border='1'> <tr> <th>Day</th> <th>09-10</th> <th>10-11</th> <th>11-12</th> <th>12-13</th> <th>13-14</th> <th>14-15</th> <th>15-16</th> <th>16-17</th> <th>17-18</th> </tr> <?php echo $tableData; ?> </table> </body> </html> output attached
  24. You would have three tables Contact contactid | contactname | etc Service serviceid | servicename | etc ContactService id | contactid | serviceid ContactService would contain a row for each service offered by each contact
  25. The only bit I understood was the title "items created or not change in the last 90 days" Try SELECT i.id , i.userId FROM items i LEFT JOIN modify m ON m.itemId = i.id AND m.date > CURDATE() - INTERVAL 90 DAY WHERE m.date IS NULL OR i.created > CURDATE() - INTERVAL 90 DAY
×
×
  • 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.