Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. No, If you are using fetchAll then remove those lines.
  2. Use file_get_contents to get the HTML of your webpage. Then pass it to $pdf->writeHTML() $html = file_get_contents('http://site.com/page-to-convert.php'); $pdf->writeHTML($html, true, false, true, false, '');
  3. fetchAll returns an array of results. You'll want to use a foreach loop instead foreach($sthandler->fetchAll(PDO::FETCH_ASSOC) as $data){ $email2 = $data['emailaddress']; $newlist= "2"; $updatelistid = "UPDATE zzemail_list_subscribers set listid = :newlist WHERE emailaddress = :email"; $sthandler3 = $database->prepare($updatelistid); $sthandler3->execute(array(':email' => $email2, ':newlist' => $newlist )); $clearars = "DELETE FROM aa_thirtydaysubs WHERE emailaddress= :email"; $sthandler6 = $database->prepare($clearars); $sthandler6->execute(array(':email' => $email2)); } If you used the fetch method then you'd use a while loop.
  4. use Option1, get the users data and store it in the session when they login. When you change the users data in the session, then update the database with the changes too.
  5. How do you know when to start shift at 1 or 2?
  6. The json definition for data.aurora.idx doesn't end in a semi-colon. This causes the regex to capture the if statement that follows it, which then causes json_decode to fail and so the data for it is not returned. As a hack, change function find_VI_json($data) { $VI_data = array(); to function find_VI_json($data) { $VI_data = array(); // HACK Fix - add semi-colon after two curly braces $data = preg_replace('~(}})\s*~', "$1;\n", $data);
  7. Been playing and have come up with a function that will scrape all VI.* variables from the page and convert them into associative array function json_decode_nice($json, $assoc = FALSE) { $json = str_replace(array("\n","\r"),"",$json); $json = str_replace("'", "\"", $json); // convert the date into a timestamp $json = preg_replace_callback('~new Date\(([^)]+)\)~', function($dateParams) { // get the date parameters $tmp = explode(',', $dateParams[1]); if(count($tmp) < 6) $tmp[5] = 0; list($year, $month, $sec, $day, $hour, $min) = $tmp; // remove the javascript math operation for the month $month = substr($month, 0, strpos($month, '-')); // create the timestamp return mktime($hour, $min, $sec, $month, $day, $year); }, $json); $json = preg_replace('/([{,])(\s*)([^"]+?)\s*:/','$1"$3":',$json); return json_decode($json,$assoc); } function find_VI_json($data) { $VI_data = array(); // find all VI.* variables that have JSON preg_match_all("~VI.([^\s]+) = (\[?{[^;]+}\]?)~is", $data, $matches); foreach ($matches[2] as $key => $json) { // decode JSON to array $jsonArray = json_decode_nice($json, true); // if an array was returned then JSON was decoded. if(is_array($jsonArray)) { // get the javascript variable name which this JSON belongs to $jsVar = $matches[1][$key]; // is this variable an array? if(strpos($jsVar, '[') !== false) { // get the array name $jsVar = substr($jsVar, 0, strpos($jsVar, '[')); // append jsonArray to variable array $VI_data[$jsVar][] = $jsonArray; } else $VI_data[$jsVar] = $jsonArray; } } return $VI_data; } To convert all JSON variables to an array just call $VI = find_VI_json($data); When you want to get a javascript variable you'd use its name, eg $VI['data.aurora.idx] to get the VI.data.aurora.idx json array
  8. Use the same code from my last post but change imgConf\[\d+\] to data.aurora.text in the regex
  9. Yes, the start of the for loop should read $x = 0; for($i = 0; $i < 31; $i++) Edit. Ohh shoot. $seq['shift2'] should of been $seq['kerja2'] if($seq['kerja2'][$i] < 7) $shift2 = ($x % 2 == 0) ? 2 : 1; // alternate between 2 and 1 elseif($seq['kerja2'][$i] == 7) { $shift2 = 'Off'; $x++; // increment x for each 'Off' }
  10. lol, How much data are you ripping? The code here is almost the same as the quakeInfo code, the only thing that has changed is the regex. I am also using the json_decode_nice function I posted earlier to decode the json easier. preg_match_all('~VI.imgConf\[\d+\] = ({[^}]+});~', $data, $matches); $imgConf = array(); foreach ($matches[1] as $conf) { // convert the date into a timestamp $conf = preg_replace_callback('~new Date\(([^)]+)\)~', function($dateParams) { // get the date parameters list($year, $month, $day, $hour, $min) = explode(',', $dateParams[1]); // remove the javascript math operation for the month $month = substr($month, 0, strpos($month, '-')); // create the timestamp return mktime($hour, $min, 0, $month, $day, $year); }, $conf); // covert the javascript json into PHP json and return an associative array $imgConf[] = json_decode_nice($conf, true); } printf('<pre>%s</pre>', print_r($imgConf, true));
  11. Try preg_match_all('#VI.data.aurora.idx = ({.*[^}]+}})#is', $data, $matches); /* This function was found at http://uk1.php.net/json_decode#95782 */ function json_decode_nice($json, $assoc = FALSE){ $json = str_replace(array("\n","\r"),"",$json); $json = str_replace("'", "\"", $json); // <--- I added $json = preg_replace('/([{,])(\s*)([^"]+?)\s*:/','$1"$3":',$json); return json_decode($json,$assoc); } // covert the javascript json into PHP json and return an associative array $auroraData = json_decode_nice($matches[1][0], true); printf('<pre>%s</pre>', print_r($auroraData, true));
  12. Add $x = 0; before the for loop Now change the shift2 code to if($seq['shift2'][$i] < 7) $shift2 = ($x % 2 == 0) ? 2 : 1; // alternate between 2 and 1 elseif($seq['shift2'][$i] == 7) { $shift2 = 'Off'; $x++; // increment x for each 'Off' }
  13. bind_param cannot handle multiple values at the same time. Each individual id will need to be bound separately. You could do // create placeholder for each id $deleteIDsSQL = implode(',', array_fill(0, count($deleteIDs), '?')); $query = "DELETE FROM table_name WHERE `id` IN($deleteIDsSQL)"; // now bind each id individually call_user_func_array(array($delete, 'bindparams'), $deleteIDs); $success = $delete->execute();; However this should also be fine. $deleteIDs = array_filter(array_map('intval', $_POST['sel_ids'])); $deleteIDsSQL = implode(', ', $deleteIDs); $query = "DELETE FROM table_name WHERE `id` IN($deleteIDsSQL)"; $dbb->query($query);
  14. You can run queries just fine within if/else statements. What have you tried? What doesnt make sense if your query will add duplicate data to your table Example: $query = "INSERT INTO constructors (Constructor1, Constructor2) VALUES ('$constructors[$u]', '$constructors[$u]')"; // ^------ duplicated -----^
  15. then $query=("SELECT title, DATE_FORMAT(event_date,'%Y-%m-%e')AS event_date FROM sw_appointments WHERE YEAR(event_date) = $year AND MONTH(event_date) = $month"); $results = $wpdb->get_results($query,ARRAY_A); $events = array(); foreach( $results as $result ) { $events[] = $result['event_date']; } printf('<pre>%s</pre>', print_r($events, true)); Should work fine.
  16. Try my code again as I had an error in my code when I posted it. Also post the output of print_r($result);
  17. To add each event_date to to the $events array you'd use foreach( $result as $results ) { $events[] = $results['event_date']; } Alternatively you could just do $events = $wpdb->get_results($query,ARRAY_N);
  18. <?php // array for lembur sequane $seq['lembur'] = array(); $seq['lembur'][0] = 3; // array for kerja sequance $seq['kerja'] = array(); $seq['kerja'][0] = 1; // array for shift sequance $seq['shift'] = array(); // the max number foreach sequance $seqances = array('lembur' => 7, 'kerja' => 14); // generate the sequances for($i = 0; $i < 31; $i++) { // generate the number sequances for lembur and kerja foreach($seqances as $key => $maxSeq) { // if current postion is set, then skip it if(isset($seq[$key][$i])) continue; // get previous number in current squance $num = $seq[$key][$i - 1] + 1; // is number greater than the max sequance number // reset sequance if($num > $maxSeq) $num -= $maxSeq; // add number to current sequance $seq[$key][$i] = $num; } // the shift sequance if($seq['kerja'][$i] < 7) $shift = 1; elseif($seq['kerja'][$i] < 14) $shift = 2; else $shift = 'Off'; $seq['shift'][$i] = $shift; } ?> <style> th { color: red; width: 20px;} td { text-align: center; } </style> <table> <tr> <th>Tanggal</th> <th><?php echo implode('</th><th>', range(1, 31)); ?></th> </tr> <?php foreach($seq as $key => $sequance): ?> <tr> <td><?php echo ucwords($key) ?></td> <td><?php echo implode('</td><td>', $sequance); ?></td> </tr> <?php endforeach; ?> </table>
  19. You was logged into your site when you ran my code?
  20. Your link is visible! The problem is $_SESSION['id'] value has not been outputted, most probably due this variable not being defined before hand, has no value or you have not started the session. What is the output of <?php printf('<pre>%s</pre>', print_r($_SESSION, true)); ?>
  21. Can you tell me how you are testing the code. The code I have posted is free of any PHP/HTML errors and will output a link just fine.
  22. By this do you mean you get a completely blank page? If you do, then check your servers error log for php errors. Or turn error reporting on at the top of your PHP script. ini_set('display_errrors', 1); error_reporting(E_ALL);
  23. Well that is the correct syntax, If your link is not appearing your code might be outputting invalid HTML which is causing the link to not appear. When you run your PHP code check the HTML source code via Right click > view source. Can you spot an HTML error?
  24. The curly braces need to go around the whole variable, as {$_SESSION['id']} echo "<li><a href='profile.php?={$_SESSION['id']}'>My profile</a></li>"; // ^---- brace ----^
  25. My code suggestions should work fine. What di d you change your code to?
×
×
  • 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.