Jump to content

Eiseth

Members
  • Posts

    58
  • Joined

  • Last visited

Everything posted by Eiseth

  1. is this a homework? // create an array of range (1-14) // turn your present numbers into an array // loop each number in the range // check if the current number is not in the array // echo it or save whatever
  2. But the problem is once they get comfortable with bad practices such as mysql_* some people find it hard or don't have time to unlearn and relearn new things again Look at how many code snippets are posted in this board day to day that uses mysql_* in their live site, the horrrrroooorr
  3. Oh sorry thought it return date object, my bad
  4. Looks like he's not developing on live site (based on his post), why not teach him how to connect with database properly too?
  5. You can not compare date and string using == Try casting $today to string if($count=='' || (string) $today === 'Sunday 00:00:00')
  6. Because your script is taking too long to process due to larger files http://www.php.net/manual/en/ini.core.php#ini.memory-limit Either adding this at the top of your page ini_set('memory_limit', '-1'); or refactor your code
  7. Nooooo!! use PDO or mysqli instead
  8. try flipping the array and compare their keys based on your code $next = ''; $prev = ''; $curr = ''; $ar = array(1624,2626,1628,1627); echo "<pre>",print_r($ar),"</pre>"; $flip_array = array_flip($ar); $curr = $flip_array['1628']; foreach ($flip_array as $a){ if ($a + 1 === $curr) $prev = $a; if ($a - 1 === $curr) $next = $a; } echo 'current = '. $curr."<br/>"; echo 'previous = '. $prev."<br/>"; echo 'next = ' . $next; // result current = 2 previous = 1 next = 3
  9. Because of this code if ($_POST[$var]!="") { $_SESSION[$var]=$_POST[$var];} Whenever you input nothing("") the condition will be false thus your session will not change Try something like // this will check your session if it's not empty and you send an empty post if ($_POST[$var]!="" || (!empty($_SESSION[$var]) && $_POST[$var] === '')) { $_SESSION[$var]=$_POST[$var]; }
  10. Try BC Math functions http://www.php.net/manual/en/ref.bc.php
  11. Is this after you submit your form? Can you post your form and import1.php? Are you using enctype="multipart/form-data in your form? <form action="import1.php" method="POST" enctype="multipart/form-data">...</form>
  12. What do you achieve with this anyway?
  13. try using persistent connection http://php.net/manual/en/pdo.connections.php
  14. Sublime Text 2 + Consolas font
  15. try inserting it into a function // Put this in your function.php function connect_db() { try { $connection = new PDO('mysql:host=localhost;dbname=mydbname', 'myusername', 'mypassword'); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $connection->setAttribute(PDO::ATTR_PERSISTENT, true); } catch (PDOException $e) { // Proccess error echo 'Cannot connect to database: ' . $e->getMessage(); } return $connection; } // Then include the functions.php in your file and call it $dbh = connect_db(); // Perform query // put this inside try/catch to catch the error // You don't need to prepare statements if you're not inserting input from outside source $stmt = $dbh->query('SELECT COUNT(*) FROM songlist');
  16. Use http://jsoneditoronline.org/ to format your json to a readable file Then look for a element that "[numbers]" beside it (e.g. in twitter json it is results[20]), usually that is where you gonna loop Try this, but I'm not sure though because I don't know the structure of your JSON $phpArray = json_decode($test); foreach ($phpArray->vehicles as $item) { // do what you want echo $item->spotted . '<br>'; echo $item->localized_name . '<br>'; }
  17. Are you trying to parse an html from other live site? If so, try using DOMDocument and DOMXPath to parse html and get the element that you want <?php // Hide errors $oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); // Instantiate domdocument so we can fetch the html $dom = new DOMDocument(); $dom->loadHTMLFile('http://forums.phpfreaks.com/'); // put your website to scrape here // Instantiate domxpath to perform query so we can search an html element by their ids/classname. $xpath = new DOMXPath($dom); // This query will find all the <input type="hidden"> // use "//input[@id='elementid']" if you want to search by their id $entries = $xpath->query("//input[@type='hidden']"); // Loop through each result then get the "value" attribute foreach ($entries as $entry) { echo $entry->getAttribute('value') . '<br>'; } libxml_clear_errors(); libxml_use_internal_errors( $oldSetting );
  18. Did you include headerinc.php on your index.php? Are you sure you have session_start() at your index.php?
  19. What I mean is for the default value of $_SESSION['start'] not the $_REQUEST['start'] That code has nothing to do with the value of $_REQUEST['start'] We just replace the "" with NULL so that if (!isset($_SESSION['start']) will run if the the value of $_SESSION['start'] is null. Using the "" as a default value of $_SESSION['start'], your if statement will never run becase !isset($_SESSION['start') is always FALSE
  20. Yup, it's a shortcut for if else statement. "?" will run if the statement is true or ":" if it isn't
  21. $_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : ""; This $_SESSION['start'] will either had a value of $_REQUEST or a default ""; just use NULL as a default value $_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : null;
  22. Because $_SESSION[''start'] is set to = '' which is TRUE, so the if statement won't run Either use NULL as default value or use the !empty()
  23. In index.php file, did you try to change your header location to home.php when the user logged in? Change this header("location: index.php"); exit(); to this header("location: home.php"); exit;
  24. Put session_start() at the top of your index.php then ... // login user if ($userCount == 1) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; } $_SESSION["id"]= $id; $_SESSION["user_login"] = $user_login; $_SESSION["password_login"] = $password_login; header("location: home.php"); // redirect to home.php instead of index.php } ...
  25. I like ampps for windows, easy to change between 5.2 - 5.4, has lots of scripts and frameworks. http://www.ampps.com/
×
×
  • 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.