Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About jiros1

  • Rank

Profile Information

  • Gender
    Not Telling
  1. Hi Ignace, thanks to your hint I've made the following changes and got it working: GameType: $builder ->add('name', TextType::class, [ 'attr' => [ 'class' => 'form-control', ], ]); $builder ->add('type', EntityType::class, [ 'class' => 'AppBundle:Type', 'choice_label' => function ($type) { return $type->getName(); }, 'multiple' => false, 'expanded' => false,
  2. Thanks for the reply, but by now I'm already using that. I've changed my code so I want to edit my original post, now I'm looking for the edit button... How silly is that I now have selectbox but it replaced my exisiting textfield, I think I know why that is, textfield holds the value for Game.name but the newly added selectbox holds the value of type.name. GameType.php public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add( 'name', EntityType::class, [ 'class' => 'AppBundle:Game',
  3. Hi! For a form I would like to render a selectbox with values from another relation: Type. This is a many-to-one relation, owned by Type. Type has many Games, while Game has one Type My question is, how do I show a selectbox with values from Type? e.g: Game: Monopoly Select Type: (selectbox) - Party game - Strategy - Co-op - etc. ----------------------------------------------- This is what I have: GameType.php <?php namespace AppBundle\Form; use AppBundle\Entity\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; u
  4. Thanks for your quick reply, Jacques1, it looks a lot better now thanks to you: const DB_HOST = 'yourhost'; const DB_USER = 'user'; const DB_PASSWORD = 'pswd'; const DB_NAME = 'db'; const DB_CHARSET = 'UTF8'; $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset='.DB_CHARSET; $databaseConnection = new PDO($dsn, DB_USER, DB_PASSWORD, [ PDO::ATTR_EMULATE_PREPARES => false, // important: Disable emulated prepared statements: PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); class Model { protected
  5. I want to clean up my code by inheriting the database class so I can connect from any class that wants to inherit the database connection. I'm not sure this is the right way but I thought about fixing this by inheriting the __construct function, but how would I call it in this example? Currently I have this; it works, but could this be improved? Or is there a better, cleaner way to do this? $pdo = parent::__construct(); My code: class database { function __construct(){ $servername = "localhost"; $username = "root"; $password = ""; $dbnam
  6. Thanks a lot, I've got it working now! A question though, how come we can do a foreach iteration now? And why doesn't that work for MYSQLi?
  7. Hi, Thanks for taking the time. I'm trying PDO for the first time and I'm trying to make a CRUD codebase. I can insert but I have trouble with the select statement and iterate through the data, Apache gives me this error: Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in index.php:38 This is line 38: $getName = $result; while( $row = $getName->fetch_assoc() ){ echo $row['name']; } This is my code: $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception
  8. It appears that the condition is set right, because if I work with only strings then it works just fine. But when I return null or an array then it doens't work... I just can't get my head around this, what am I missing? //If the visitors can't fit in the gap of available seats. if($visitors<$gap){ //$result = false; $result = "doesn't fit"; } else{ //$result = $seats; $result = "it fits"; } return $result;
  9. I'm trying to make a function that checks if there are enough seats available for visitors. If there's enough room for the visitors, return an array with suggested seats, else return null. Method: I'm making a gap, this gap will be increased by 1 everytime there is a available seat. At the end of my function, I compare if the $visitors fit in the $gap, if they don't return null and if they do, return the array. The problem: My function returns an array even though there's not enough room. My question: How do I let my function return null if there are not enough seats? This is my cod
  10. This is great, it's exactly what I needed. Thanks!
  11. There are seats that need to be assigned to visitors, for each visitor I check if the seat is available, if it is, give the value 'x' for 1 $visitor until there are no visitors left. I want to execute a line of code for x times, x = the value of visitors. As the code is now, I want to suggest 2 visitors a seat by giving the value 'x'. I will use the values as follows: 1 = available 0 = is not available x = was available, and now it's a suggested seat The problem: I want to have a output of two X's, but as the script is now, it generates three X's, and I don't know why. The ques
  12. @Gizmola, based on your example I have made a script that runs through the seats and makes gaps along the way. It checks if the provided quantity of visitors fit in the gaps. My question is how do I make it so that it executes only the first gap? current output: 3 visitorsit fits123Seat: 1(gap size: 5) it fits111213Seat: 11(gap size: 5) It starts at the first available seat from there it increments by one until it reaches the quantity of visitors. This is one gap. This is my code: functions.php <?phpfunction connectDB(){ $servername = "localhost"; $username = "root"; $pa
  13. You can download the Windows version of Composer on the same link you provided. This setup file takes care of everything and if you enable shell menu during setup, you can right click on a folder and use composer directly in that folder. A box shows up where you can enter commands, this is a terminal. I use it too and it's very easy to use.
  14. Thanks for the quick replies! @Barand, I don't need the rows, the seats are only defined as seat numbers, but I understand why you would think that. @Gizmola, your "$gaps[]" approach looks very interesting and might just be what I need. I get a vague idea of your theory but I don't how to actually make this. Can you please elaborate how I can implement your idea? $gaps[] = array('start' => 1, 'end' => 4, 'count' => 4);
  • 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.