Jump to content

tgavin

Members
  • Posts

    176
  • Joined

  • Last visited

Everything posted by tgavin

  1. I'm digging into this and am getting a better understanding of how this works - thank you guys for pointing it out to me - I can totally see the value of this! I'm curious though about the FormInterface... class? interface? What does that do? I can build my forms with all of the arguments right inside the Form class, so why are those additional methods set inside FormInterface?
  2. Excellent advice. This is the way I'm going to go. Thanks guys!
  3. Thanks for your help guys. Before I try any of this, I'm thinking: what about just doing the following class Forms extends Bootstrap { .... } Seems simple enough, and works! Would there be any problems with this?
  4. You know, 'Bootstrap extends Forms' is pretty much the first thing I tried, but I didn't want to create a new $bs object, because I wanted to keep it simple and use the $form object for everything. I know it's only the difference in typing $form-> vs. $bs->, but it's easy to forget when you're on a roll. So, if I don't want to create a new object, is my only option to put all of the bootstrap methods in the Forms class? Thanks!
  5. I have a class for building forms and I want to upgrade it to handle Bootstrap. I'd like to use my current methods to build the Bootstrap elements, but I don't want all of this new Bootstrap code cluttering up my current Forms class, so I'd like to put it into its own class in a separate file. Below is a very simple example of what I'm trying to do. Obviously this doesn't work and the code is wrong, however, from this you can hopefully see what I'm trying to accomplish. <?php class Forms { public function input_text($name) { return '<input type="text" name="'.$name.'">'; } } class Bootstrap { public function bootstrap_input_text($name) { $return = '<div class="control-group">'; $return .= '<label class="control-label" for="'.$name.'">First name</label>'; $return .= '<div class="controls">'; $return .= $this->Forms->input_text($name); $return .= '</div>'; $return .= '</div>'; return $return; } } $form = new Forms(); echo $form->bootstrap_input_text('fname');
  6. Thanks guys, Those were the first things I tried actually. Neither of your examples loop through the $types array and display ALL of the types. I don't want to only display the types that are only in the database, I want to display ALL types, and then highlight the type that's ALSO in the database. it's a checklist to show the user the list of documents, plus what's been uploaded and what hasn't. For instance, let's say PDF and Word are found in the database, my printed result would look like this Word (uploaded) Excel PDF (uploaded)
  7. I have an array of document types that I need to display, and then visually show if that type has been uploaded into the database. The code below works, but it's obviously not ideal. it's probably the best way to show you want I want to accomplish though. I'm trying to find a better, more efficient way of doing this without having to make so many queries. Any thoughts? $types = array('Word','Excel','PDF'); foreach($types as $type) { if($db->get_row("SELECT doctype FROM documents WHERE doctype ='$type' AND id = 100")) { echo $type.' (uploaded)<br>'; } else { echo $type.'<br>'; } }
  8. PFMaBiSmAd: Excellent catch! I'm implementing a system that a previous developer had created and he's using bullcrap shortcuts all over the place. Very lazy and insecure. That fixed it, thank you!
  9. I'm encountering a weird one on IIS with PHP 5.4.7 in my script I'm trying to include my config.php file (located in the same directory), so I put require_once('config.php'); as I normally would on Linux. Well, later in my script I'm getting an undefined variable notice, even though the var has been defined in config.php. So I open config.php and do this $base_dir = 'www'; var_dump($base_dir); exit; now, not only do I now see a result from the var_dump, the script doesn't die as it should, and I continue receiving the undefined variable notice at the same point in the script. WTH? Even if I do require_once('config.php); var_dump($base_dir); exit; I get no results - just the undefined var error. it's almost like the config.php file isn't being included. Any ideas?
  10. I know you say the queries are fine, but did you actually check them in phpmyadmin?
  11. I must not be understanding something, because it looks to me it's doing exactly what you're telling it to do. Try this and see if anything changes if($q2_cycle_oil_count > 0) instead of if ($q2_cycle_oil_count >= 1)
  12. apparently it's not empty. what do you get when you run the query in phpmyadmin?
  13. Check your query. Test it in phpmyadmin and make sure you're getting the results you want first. then bring it back into your script.
  14. What does this produce? $count = mysql_num_rows($q1_cycle_oil_results); echo $count;
  15. Thank you. i was too close. this solved the problem. $name = rtrim($data['name'],'[]');
  16. Right, $_POST "food" is an array, and I need to get the values of that array. Instead it returns an undefined index. That's where I'm having the difficulty. I was testing with a string to make sure info was actually being passed. now i see what that wasn't a good idea. sorry for the confusion. This is basically what I'm trying to accomplish if(isset($_POST[$data['name']])) { foreach($_POST[$data['name']] as $value) { if($_POST[$data['name']] == $data['value']) { $return .= ' checked="checked"'; } } }
  17. var_dump($data); array(6) { ["type"]=> string( 8 ) "checkbox" ["name"]=> string(6) "food[]" ["value"]=> string(5) "steak" ["string"]=> string(10) "id="steak"" ["checked"]=> bool(false) ["required"]=> NULL } print_r($_POST); Array ( [food] => Array ( [0] => steak ) [submit] => Submit )
  18. I'm working with a checkbox group called food[]. One of the checkboxes has the value of 'steak'. this is the one i'm testing with. I'm using a function to build and print the checkbox. The function accepts an array ($data) of names and values for each checkbox. The name of the checkbox is contained in $data['name'], which is passed through the function. if I var_dump($data['name']) from within the function it prints 'food[]'. perfect. I'm now trying to get the POST values. if i do this, i get an undefined index error if(isset($_POST[$data['name']])) { var_dump($_POST[$data['name']]); } if i do this, it prints 'steak' if(isset($_POST['food'])) { var_dump($_POST['food']); } what am i doing wrong?
  19. I was using a foreach previously, but changed the code so that I would have multiple <td> columns for the output. How do I incorporate a foreach into my existing code?
  20. So, I can't loop through it? I have to manually print each item?
  21. I'm having a hard time figuring out how to print the value from the $list array. $list[$i] isn't cuttin it. $list = array( 'Car' => 'Car', 'Boat' => 'Boat' ); $columns = 2; $list_count = count($list); $return .= "<table>"; for($i=0; $i < $list_count; $i++) { if($i % $columns == 0) { $return .= "<tr>"; } $return .= "<td><input type=\"checkbox\" name=\"mg[]\" value=\"".$list[$i]."\" class=\"checkbox\" /> ".$list[$i]."</td>"; if(($i % $columns) == ($columns-1) || ($i+1) == $list_count) { $return .= "</tr>"; } } $return .= "</table>";
  22. Array ( [0] => Array ( [0] => 90976 [id] => 90976 ) [1] => Array ( [0] => 90977 [id] => 90977 ) [2] => Array ( [0] => 90978 [id] => 90978 ) [3] => Array ( [0] => 90979 [id] => 90979 ) [4] => Array ( [0] => 90980 [id] => 90980 ) [5] => Array ( [0] => 90981 [id] => 90981 ) [6] => Array ( [0] => 90982 [id] => 90982 ) [7] => Array ( [0] => 90983 [id] => 90983 ) [8] => Array ( [0] => 90984 [id] => 90984 ) [9] => Array ( [0] => 90985 [id] => 90985 ) [10] => Array ( [0] => 90986 [id] => 90986 ) [11] => Array ( [0] => 90987 [id] => 90987 ) [12] => Array ( [0] => 90988 [id] => 90988 ) )
  23. Let's see if this helps. The code has been commented more thoroughly. // get the ID of every episode in this series/season so we can build an array of ID numbers $query_episodes_count = "SELECT id FROM movies WHERE kind='TV Show' AND show_name_slug='".escape('all-in-the-family')."' AND season='".escape(1)."' ORDER BY episode ASC"; $sql_episodes_count = mysql_query($query_episodes_count) or die(mysql_error()); // if episodes exist if(mysql_num_rows($sql_episodes_count) > 0) { // Since we may not be starting at the first episode (position 0 in the array) // we need to get the position in the array so we know which episode ID to look up // pos gives us this position and is passed in the pagination links, built at the bottom of the script // pos is always available $pos = abs((int) $_GET['pos']); // build an array of the episode ID numbers $episodes_array = array(); while($row_episodes_count = mysql_fetch_array($sql_episodes_count)) { //array_push($episodes_array,$row_episodes_count['id']); $episodes_array[] = $row_episodes_count; } // $_GET['id'] is ONLY passed during the FIRST visit to this page // after that we need to get the episode ID from $episodes_array with a key that matches $pos // so we don't start from the beginning of the array if(isset($_GET['id'])) { $id = $_GET['id']; } else { // get the ID from the array that correlates to the key matching $pos //$id = array_search('id',$episodes_array); $id = $episodes_array[$pos]; } // get the show's data so we can display it on the page $query = mysql_query("SELECT * FROM movies WHERE id=$id") or die(mysql_error()); $row = mysql_fetch_assoc($sql); // print the show's information echo $row['title'].'<br />'; // build the pagination if($pos > 0) { // show prev link $pos_prev = '<div style="float:left; padding-right:10px;"><a href="pagtest.php?pos='; $pos_prev .= $pos-1; $pos_prev .= '">previous</a></div>'; } if($pos < count($episodes_array) - 1) { // show next link $pos_next = '<div style="float:left"><a href="pagtest.php?pos='; $pos_next .= $pos+1; // can we put in the next ID? //$pos_next .= '&id='.next($episodes_array); $pos_next .= '">next</a></div>'; } echo $pos_prev; echo $pos_next; }
×
×
  • 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.