Jump to content

Mr_Pancakes

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

About Mr_Pancakes

  • Birthday 02/13/2006

Profile Information

  • Gender
    Male
  • Location
    Southwest USA

Mr_Pancakes's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. easy fix: change that single "=" character to "==" [code] if ($val == '1') {   echo " CHECKED"; } [/code] the single "=" character is setting $val to 1 and will always be true.
  2. you can also insert an HTML break as well. [code] echo "blahhhhh <br />"; [/code] and if you wanna get picky, you could add a server line break to it all to line feed your code: [code] echo "blahhhhh <br />\n"; [/code]
  3. actually, upon a second review, count($or) woudn't work regardless because $or is equal to a string while the if statement is comparing to an integer. try first setting $or equal to an integer as well. [code] $or = 50; [/code]
  4. try this instead: [code] if (count($or) > 58) print "58 greater than Variable."; else print "58 is less than Variable."; [/code] also, you don't need those "break"s in your code. try it - it'll work fine without them. another way to create your if statements is with the { and } characters. you might find this method to be easier to organize and view your code when you start using more than 1 line of code in an if statement. [code] if (count($or) > 58) {       print "58 greater than Variable.";       // a second line of code is acceptable when you use { and }       // and even more lines of code } else {       print "58 is less than Variable.";       // even more code } [/code] hope this helps. cheers, .s
  5. [u]there are two ways to approach your problem:[/u] one somewhat troublesome solution you mentioned is to have a seperate boolean field (true or false) for each of your vehicle's features (like Power Steering, Heated Seats, etc.). so your table would look something like this: TABLE: [b]vehicles[/b] [table][tr][td][u]vehicle_id  |[/u][/td][td][u] power_steering  |[/u][/td][td][u] heated_seats  |[/u][/td][td][u] ...etc.[/u][/td][/tr] [tr][td]1[/td][td]1[/td][td]1[/td][td]...[/td][/tr] [tr][td]2[/td][td]1[/td][td]0[/td][td]...[/td][/tr] [tr][td]3[/td][td]0[/td][td]0[/td][td]...[/td][/tr] [tr][td]...[/td][td]...[/td][td]...[/td][td]...[/td][/tr] [/table] whereas the "1" stands for "true" and "0" for "false", in each of the vehicle feature columns (or typically called "fields" instead of "columns"). the major problem with this solution is that it takes up WAY too much room in your database. think about it... if you have say 50 possible vehicle features, and car "x" only offers 2 of those features, you've wasted database space by storing 48 "falses". [i]you should only store features of a car that describe what it actualy is, and never what the car is not.[/i] a better approach that saves database space and improves efficiency is to set each of your checkboxes to a value of a "feature_id" number. then when a user submits the page, concatenate all values (feature_ids) of your checked boxes into a single comma seperated field and store in your database. for example, your table structure will look like this: TABLE: [b]vehicles[/b] [table][tr][td][u]vehicle_id  |[/u][/td][td][u]feature_ids[/u][/td][/tr] [tr][td]1[/td][td]2,4,5,10,12[/td][/tr] [tr][td]2[/td][td]1,2,3[/td][/tr] [tr][td]3[/td][td]4,44,400[/td][/tr] [tr][td]...[/td][td]...[/td][/tr] [/table] TABLE: [b]features[/b] [table][tr][td][u]feature_id  |[/u][/td][td][u]feature_name[/u][/td][/tr] [tr][td]1[/td][td]Power Steering[/td][/tr] [tr][td]2[/td][td]Heated Seats[/td][/tr] [tr][td]3[/td][td]Kegerator in Trunk[/td][/tr] [tr][td]...[/td][td]...[/td][/tr] [/table] each vehicle_id in the "vehicles" table describes what the id number stands for in the "features" table. then to display this info: [list] [*]1.) query the table "vehicles" for a target "vehicle_id" and it's "feature_ids" [*]2.) query the table "features" for all "feature_id"s and "feature_name"s [*]3.) use the php function explode() to parse out each target feature_id from step 1 into an array [*]4.) use a foreach() loop to step through each feature_id in your exploded array from step 3 [*]5.) in this loop, match your target feature_id (step 3) with it's parent feature_id stored in step 2 [*]6.) display the corresponding feature_name to the page in your desired format [/list] your welcome. i have random sympathy for beginners b/c ive been there. cheers, steve
  6. [quote author=sylesia link=topic=117259.msg478346#msg478346 date=1165231522] only I have 15 of those boxes, and I do not want to have 15 if else statements... [/quote] you could call a function to print "checked" that is defined at the top of your page (or in a different page that is referenced in this page via the inlcude() function): [code] <?php function printChecked($value) {   if ($value == 'EM') print "checked"; } ?> ... <html> ... <input TYPE="checkbox" NAME="StrongDimensions[]" VALUE="ME" <?php printChecked($answer[0]); ?>> ... </html> [/code] [quote author=sylesia link=topic=117259.msg478391#msg478391 date=1165240943] Also, tried what you suggested and it works when its all I do, but for some reason, when i combined it with HTML, I get a time out error.  Not sure what is wrong with my code... <? echo $StrongDim; $i = 0; $view = explode (",",$StrongDim); while($view[$i] != "XX"){echo $view[$i]; $i = $i + 1;}?> [/quote] it has nothing to do with the HTML, it is the PHP that is stuck in a neverending loop somewhere in your page. if i understand what you're trying to do with "ME,PH,XX" (which is just not print "XX"?), then try this instead: [code] <?php echo "$StrongDim <br />"; $view = explode (",",$StrongDim); foreach($view as $key => $val) {     if ($val != "XX") echo "$val <br />"; } ?> [/code]
  7. you first problem can be solved by using the function explode(); to parse your string into an array. in your case, if the string pulled from your database is "HE,EM,OT" then you could do the following: [code] // get string from database $your_db_string = "HE,EM,OT"; $answer = explode(",", $your_db_string); echo $answer[0]; echo $answer[1]; echo $answer[2]; [/code] [u]results in:[/u] HE EM OT your second problem is a bit unclear. all i could say about it from what i understand is that it would be more efficient to use a 1 or 0 in your database to represent checked or unchecked. then use a simple evaluation of the 1 or 0 to echo a checked="checked" in your html input tag. if you can better explain your second problem, it might be easier to answer. hope this helps, cheers, steve
  8. easy fix - just change your single quotes to double: [code] if (is_dir("downloads/$id")) ... [/code] cheers, .s
  9. you could do this instead: [code] ul { list-style: none; } a[href$=".pdf"]:before { content: url(Images/myico_PDF.gif); } [/code] although by nature, using css isn't the best approach to solve this problem because this (or your previous) solution doesn't work in IE. i'd use a simple php function to assign a custom pdf, doc or xls css class to each li tag with a unique list style image.
  10. in your processFiles.php, try adding the pre-existing folder name to where your upload will be placed. [code] $copy = copy($folder_location . $_FILES['uploadFile'. $x]['tmp_name'],$file_name); [/code] where, $folder_location is already existing. if you need to create the folder right then, you can use the mkdir() function. cheers.
  11. do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster. i think i might have what you're looking for. try: [code] function name_filter($name) {   $name = mysql_escape_string(strip_tags($name));   $query = mysql_query("SELECT `word` FROM filter WHERE type = 'N'");   $word = mysql_fetch_array($query);   foreach ($word as $check) {       // swap out the preg_match() function with:       $pos = strpos($check, $name);       if ($pos === false) {               // the $check value was not found in $name, continue.       } else {               // the $check value was found in $name, disallow username.       }   } // end foreach } // end function [/code]
  12. try: [code] if (isset($_POST['L1']) && empty($_POST['L1'])) { echo "Its Empty"; } else if (isset($_POST['L1']) && !empty($_POST['L1'])) { echo "It's Full"; }[/code] or more efficiently as: [code] if (isset($_POST['L1']){   if (empty($_POST['L1'])) {       echo "Its Empty"; }   else {       echo "It's Full";} else {   echo "Its Empty"; } [/code]
  13. im not quite sure what the result of that scipt you're calling is. but if you store that result in a variable you could write that value to your test.html doc by using the fopen(); fwrite(); and fclose(); functions. [code] $myFile = "test.html"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Your contents.\n"; // where your contents are from that script you're calling. fwrite($fh, $stringData); $stringData = "Even more contents.\n"; // might need to append your contents while processing your data. fwrite($fh, $stringData); fclose($fh); [/code] results in test.html looking like: Your contents. Even more contents.
  14. opps, you're right - try just empty() instead,. (ive gotten used to using some custom functions of my own)
  15. i think your problem is in the use of isset(). isset() tells you whether the variable exists, and in this case $FT will always be true no matter what its' value is after the page is submitted once because the variable is created at that point. try using a combination of isset() and is_empty(). maybe something like: [code] if (isset($_POST['L1']) && !is_empty($_POST['L1'])) { $FT=$_POST['L1']; echo $FT; echo "It's Full. Really it's full!"; } [/code] also, you don't need "== true" in your first statement. if you take it out, the if statement by default inquires as to if the statement is true or not, therefore evaluating the same way. and in your second if statement, you could use "!" instead of "== false". they both do the same thing, except this way is a little cleaner to read sometimes - and it looks pretty =)~.
×
×
  • 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.