Jump to content

jcanker

Members
  • Posts

    252
  • Joined

  • Last visited

Everything posted by jcanker

  1. There's not enough code here to be sure, because for starters I'm not sure why you've initialized your for loop the way you have. Why start $i at 2? what is $n? That aside, it probably doesn't have anything directly to do with the error you're seeing. Is the line $laagstegetal = $tabel[$m-1][3]; The only spot where you initalize $laagstegetal? Did you retype this code into the forum window or did you copy/paste? A cause of your issue isn't jumping out at me, but if you have retyped it rather than copy/paste, having $laagstegetal .= $tabel[$m-1][$i]; instead of: $laagstegetal = $tabel[$m-1][$i]; certainly would cause the issue you're seeing
  2. Long story short: You can't use headers if you output ANYTHING first. That echo statement in the beginning is output. (And Pikachu2000 has helped me a million times on this board, it seems. Best to listen to his advice )
  3. UPDATE: You can probably ignore most of the stuff I posted below. When I finished, I noticed that you're trying to find an ARRAY KEY, not value using in_array(). in_array() only looks at values, not keys. If you want to see if a key exists in an array, use array_key_exists($key,$array). I'm including the rest of what I had answered just in case (and because I spent the time to write it ) This is a function I have in an include file that greatly simplifies the task of parsing out the results of a returned MySQL query. function db_result_to_array($result) { $res_array = array(); for ($count=0; $row = @mysql_fetch_array($result); $count++) $res_array[$count] = $row; return $res_array; } Just run your query: PDO or using mysql_query($query) and whatever the returned results are (here I'll call it $result) $result = db_result_to_array($result); foreach ($result as $row) //this will parse through each row of the returned array, not each column { //this function allows you to access the returned row currently being processed by mysql column name, so you can run your in_array() here: if(in_array($mySearch, $row)){...} } That should work, although I've never used it this way. Because this is coming directly as a query from the DB, you should know which column would contain the value you're looking for. Just run an if statement on that. In the above example, the foreach would contain a line similar to: if($row['nameOfMysqlColumnThatWouldContainTheValueImLookingFor'] == $varNameThatHoldsTheValueImLookingFor){...} Seems to me that's much simpler than searching the array for a value when you know where it will be. NOTE: Also keep in mind that in_array() won't look through lower levels of a multidimentional array. You have to navigate to that level first and then search for it. You can do this in nested while or for loops with a few counters.
  4. The workflow process will be: Create a form with <select> elements with <options> for each exercise. The ACTION on that form will go to a php page which will grab the value of the selected OPTION when it was submitted. (Note: You CAN have the form submit to itself, e.g., the same php page. In this case, you start by looking for the _POST or _GET variables being set and processing them from the get-go, setting variables as appropriate throughout the rest of the page. This limits your total number of php pages in your site, but can get VERY messy without careful preplanning. ) That php page takes the value submitted by the form and runs the appropriate query, something like (a generic example) $submittedVariable = $_POST['exercise']; //don't forget to sanitize POST and GET, even though I leave that out for brevity here $query = "SELECT description FROM excercises WHERE exercise = '".$submittedVariable."' LIMIT 1; $result = mysql_query($query); //it's safer to use PDO, but that's another discussion entirely. This is the quick easy way to make the query if(!$result) { //use this for debugging purposes only--never reveal to users what your database structure is like. After you get it working properly replace this message with something more generic but specific enough that you know the error occurs in this spot, not at another location in your code echo "<p>Error retrieving the description. The query used was ".$query."<br/>The returned error was: ".mysql_errno().": ".mysql_error()."</p>"; } /* now process the returned query and grab the description, settting a variable with the description value. To make this quick and easy I use a function which I have in an include file: function db_result_to_array($result) { $res_array = array(); for ($count=0; $row = @mysql_fetch_array($result); $count++) $res_array[$count] = $row; return $res_array; } This function allows me to reference the specific MySQL column by column name when I process it: */ $result = db_result_to_aray($result); foreach($result as $row) { $desription = $row['description']; } /* Now, at this point you COULD give an AJAX feel to your page by setting the description in the SESSION array so the original page can access it: */ $_SESSION['description'] = $description; /* and then, if everything went smoothly, we haven't had any output to the screen, so that allows us to just redirect back to the original page. */ $referring_page = 'Location: http://'.$_SERVER['HTTP_REFERER']; //you may just want to hardcode in the page that has the original form because HTTP_REFERER is set by the browser and can't always be trusted header($referring_page); Now back on the page with the select form, at the beginning, you just look to see if $_SESSION['description'] is set. If it is, then use that text in the appropriate location in the page and then unset($_SESSION['description']); after you assign it to a variable. That way you're keeping it inside the if(isset($_SESSION['description'])) block. Once it's assigned to a variable you can use the var anywhere on the page you need to, and although you're using 2 separate PHP pages, the page just seems to refresh itself when the initial select form is submitted, showing the results and giving your page an AJAX feel without really using AJAX. I hope you can follow that...I know I ramble a bit in long explanations (and there may be a typo or two in the code, so use judgement on missing ) or ;'s etc The keyboard on my laptop isn't as responsive as it used to be and sometimes my fingers go faster than it wants to process
  5. What I think you are envisioning really is AJAX, not php. AJAX allows you to dynamically change the page based on user interaction by passing data to a backend server (usually php), getting data in response, and then updating an element of the webpage with the returned data (or changing it based on the response, such as logging in, etc). What you're trying to do with php can be done, but it will require multiple steps. Without AJAX, you'll have to submit the form data each step in order to change the content of other elements in the form. I''ll create an example in the next post, but I'm going to click submit so you know I'm working on this ATM
  6. There's a couple of ways to do it---100 ways to skin a cat, right? You can always use the UNIXtime and just do the math to add: 1 minute = 60 seconds 1 hour = 60min*60sec = 3600 seconds 1 day = 24*60min*60 sec = 86400 seconds 1 Week =7*24*60*60 = 604800 seconds But the caveat to that is unless you do a little work to it first, the UNIXdate is a TIMESTAMP, so it returns the current time, so the math will be from the current time, not 00:00 of the date. The other option, and one that is becoming more popular, is to use the PHP date/time object (which also has procedural style capabilites). This is newer, so if you're running on 4.x you'll have to upgrade to 5.x. Object oriented style: <?php $date = new DateTime('2000-01-01'); $date->add(new DateInterval('P10D')); echo $date->format('Y-m-d') . "\n"; ?> Procedural style: <?php $date = date_create('2000-01-01'); date_add($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d'); ?> Both result in the same output PHP manual page: http://www.php.net/manual/en/datetime.add.php
  7. I read three javascript/ajax books trying to learn it. I stumbled through them (I'm much more familiar with php, and the client side was new to me.) Then as I was researching a problem I was having I couldn't avoid the jQuery library, so I got jQuery: Novice to Ninja by Earle Castledine and Craig Sharkie. Lots of examples (although in a few spots they aren't consistent with class names across scaffolding examples, but I found that it just keeps me on my toes:) They are corrected on the sitepoint website) and most importantly, it's constructed in a case-study fashion where an imaginary customer wants X done to the site; now they like that idea and want Y done next, and so on. In that fashion, they introduce you to the jQuery library and get you thinking in jQuery while building on "real life" examples. By the time I hit chapter 3 I felt like I had completely wasted my time with the javascript/AJAX books and should've just gone to this one first.
×
×
  • 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.