Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. The simplest but somewhat dodgy fix to this is to use output buffering. This allows you to display things in whatever order you want. Eg <?php ob_start(); include "./includes/header.inc.php"; $header = ob_get_clean(); ?> Now you can do echo $header at any time to display the header. Similarly you can buffer the main content by putting ob_start() at the top and $content = ob_get_clean() at the end.
  2. At the lowest level, arrays can be indexed by either an integer, a string or both. You can have both an integer and a string pointing to the same memory space as well (like a reference. Well it is a reference). For example, mysql_fetch_row() returns an array with both integer and string indexes pointing to the same memory. Actually you can point as many indexes of any type to the same memory space (subject to limits from integer overflow in reference counting). Demonic, if you want to check that all the keys are strings, then little guy's code reversed should work. Use is_int() instead of is_string(). What he wrote checks that all the keys are integers.
  3. I think darkwater is right - your code should look like: while($row = mysql_fetch_assoc($result)) { extract($row); $prop = substr($prop_desc, 0, 150); with the rest remaining as it is already.
  4. Hmm, well in that situation you have two arrays, and you need to loop through both at one time. That's a little more complex than a single array. $commission_arr = $_POST['commission']; $id_arr = $_POST['id']; if (!is_array($commission_arr) || !is_array($id_arr)) { die("Either commission or id wasn't an array!"); } foreach ($id_arr as $key => $id) { $commission = $commission_arr[$key]; $sql = "insert into $table (commissions) values ('$commission') WHERE id ='$id'"; mysql_query($sql) or die("Error in $sql: " . mysql_error()); } Here I'm assuming that the indexes for the id and commission arrays will match up, which they should in your case.
  5. You can only edit a post for a few minutes afterward. It's to prevent problems where someone replies to your post, then you edit the content of that post, and everyone gets confused About the problem - I believe the best solution is to make your png.txt like a template, and use special markers for the variables you want to substitute. For example: # The template $var = %VAR%; print $var; # The template processor $template = file_get_contents('template.txt'); $template = str_replace('%VAR%', "$var", $template); And so on for each substitution you want to make. There are more sophisticated template systems such as Smarty, but I think this will be good enough for what you need.
  6. Yep.. I find I don't dream unless I get enough sleep.  And that is rare :)  Actually it's more a question of getting enough quality sleep.  I can have my eyes closed and be unconscious but still not feeling refreshed the next day.  But when I dream, that's usually the times when I'm getting quality sleep.
  7. Wondering how you were compiled?  Do you think about that a lot?  I used to try very hard to find the answers to life, thinking that if I found them, then things would be easy. I don't do that anymore though.  Now I go for the "whatever makes me happy" approach.  Because I realized that even if I found "the answer", it's not going to make me any happier. BTW, everyone believes there is something wrong with them.  It's part of being human.  I think that how we deal with that feeling of "something is wrong" defines who we are.  I think that what's wrong with me is that I don't know enough, and it's because of that I will only make things worse.  And so I devoted much of my life to learning about everything, so I wouldn't make things worse :) No surprise that I ended up as a mathematician/philosopher/programmer .. These days I'm much more free though - I can see that the feeling that something is wrong with me doesn't mean that something actually IS wrong with me.  And separating those out lets me be free :) Ok, very off topic I suppose.  But hardly anyone posts in this section anyway..
  8. Aha. Then you should write it like this: //entry 1 - if ivete sangalo is typed, this will apply. if ($artist == "ivete sangalo") { echo ' <img src=\"link to band image\">'; } //entry 2 - if rammstein is typed, this will apply. elseif ($artist == "rammstein") { echo ' <img src=\"link to band image\">'; } The difference is the "elseif" instead of "if". If you miss that out, then the final else will only apply to the final test. You should find with your current code that the final "else" is being executed for all cases except when $artist = "sorriso maroto" elseif should be added for all "if" except the first one. The general structure is: if (...) { } elseif (...) { } elseif (...) { } else { }
  9. Do you want your final output (png.txt) to be php code? But first you want to substitue some variable with values taken from the original form?
  10. This and this page explain how to use arrays with forms in php. Alternatively you can parse the post data yourself, which I did before I realized that php can do it for me But if you do like you are doing, you will only get the LAST item in $_POST, not all of them. To get all of them you must name your input as "id[]" and "commission[]"
  11. How is it supposed to work? Is the "else" supposed to apply to all "if" or just the last one? For a start with the debugging, I would add this line at the top: print "artist is $artist<br>"; That will at least tell you if $artist is set. To assist with debugging, can you give us a few sets of input and output. Eg "I type '3 doors down' as the artist, and I get a blank page"
  12. This line if ($board[$i][$j]="0") should be this: if ($board[$i][$j] == "0") One reason for leaving a space around the "==" is that it's easier to see whether it's == or =
  13. The underlying type of an integer in php is an int. That is 32 bits on a 32 bit OS, and 64 bits on a 64 bit OS (with a 64 bit version of php). There's a table of limits here: http://en.wikipedia.org/wiki/Limits.h
  14. $_GET['cat'] == "" is also true if cat was not set at all. So in this case you should use isset(). Another option is to check $_GET['cat'] === null (note the 3 =, not 2 =. 3 = is a very strict comparison). If it is === null, then it was not set.
  15. Oops, I misunderstood the word "class" In that case, make sure you've called mysql_escape_string() somewhere. Otherwise you will run into trouble when a quote appears inside one of your strings. For quoting, you need to quote all strings, but you don't need to quote numbers. So ideally you would decide what to do based on the type of the variable. But that's not always easy to do, as PHP typically doesn't have the database schema easily available to it. Quoting everything will work, unless you are using functions like now(), which can't be quoted. That's when things get messy
  16. The full details are here: http://www.php.net/manual/en/types.comparisons.php But the short answer is that you can use isset() to see if a variable is set or not. If isset() returns false, then the variable was not passed in.
  17. Here's my favorite way $max = 12; $set = range(1,$max); for ($i = 0; $i < 4; $i++) { $choice = rand(0,$max-1); $rand_set[] = $set[$choice]; $set[$choice] = $set[$max-1]; $max--; } print "Selected: " . implode(', ', $rand_set) . "\n"; The idea is to remove a random element, move the last element into that empty spot, then reduce the array size by 1. This method works well for lower level languages like C also.
  18. There's a lot of ways to do this - in your class they should have taught you how they expect you to do it. If you want to add single quotes to each variable, just add them at the start and end of the string following VALUES, as well as inside the implode(). That will put quotes around EVERY variable, which may not be what they are expecting you to do, but it'll work. Are they expecting you to use mysql_escape_string() as well? If so, you'll need to call that on each value from the array.
  19. Try this: if (strlen($land_use) > 2) { $query .= " AND land_use LIKE '%$land_use%'"; } What's missing is the quotes.
  20. DOA, it does make sense to have a function that checks for integerness even if the value is not an integer, but is_int() isn't that function If you write such a function you will have to decide what to do about large floats, which typically aren't integers even if they should be integers, due to floating point innacuracy.
  21. I would recommend adding some debugging code. The first to add would be inside each of the branches inside the "cats" loop - something like this: if(!in_array($list_cats,$seen2) && !in_array($list_cats,$multiple)) { print "$list_cats is a new cat<br>"; array_push($seen2,$list_cats); } else { print "$list_cats is a multiple cat<br>"; array_push($multiple,$list_cats); unset($seen2[$list_cats]); } I notice you re-use $multiple without renaming or initializing it - that may or may not be the problem.
  22. ueon, the error I pointed out is causing the loop to run forever. The condition for loop termination is that $int_val4 is not less than $table_num, but you are resetting $int_val4 to null every time through the loop. If you fix that and you still have problems, post your code again here.
  23. What do you intend by this code? $table_width.$int_val4 = $_POST["table_width".$int_val4]; That line actually resets $int_val4.
  24. The input will need to be an integer for that to work .. as long as it is, it should be fine.
  25. EXTR_SKIP doesn't make sense in the way he's using extract(). He wants to overwrite the variables for each row. But I think he is inadvertently overwriting other variables because he used "SELECT *", fetching more than just the ones he is interested in, including the user level.
×
×
  • 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.