Jump to content

ScoobyDont

Members
  • Posts

    43
  • Joined

  • Last visited

Everything posted by ScoobyDont

  1. Bitterly disappointed that you need to get your crystal ball out, as an administrator you should know they have bought a Magento 1.0 ecommerce site from theme forest/ebay with a special offer of 42 addons/plugins And what chokes me even more, you have not even offered 2 lines of code to bring the load times down.
  2. Thank you, I fully understand that and thank you for your input, but everything I seem to do with this framework seems to give me problems. So I have ditched it, so I no longer need any more answers on the topic. Yesterday I carried out some testing with Laravel, Cake and CodeIgniter and out of the 3 I personally like CI so going to run with that. Thanks again for all your help
  3. Oh great, to be honest it was to help me start to understand MVC of which I first thought it seemed quite simple until I tried to do a simple bloody count Now I am starting to wonder what ever was wrong with <? $carcount = $db->query("SELECT id FROM vehicledetails WHERE id=id"); $carscounted = $carcount->rowCount(); ?> It was a course on Udemy,(£9.99) and to be fair I thought it had given me an insight into MVC but by your response maybe not. OT but which framework would you recommend for a beginner/advancing php'er
  4. Something like this should work <?php foreach $rows as $row) : ?> <div class="card"> <h4 class="card-title">Card Title</h4> <p class="card-text"> User: <?php echo $row['name']; ?> <br> Date: <?php echo $row['date']; ?> </p> </div> <?php endforeach; ?> Obviously you need to style the card as you see fit
  5. Wow thank you for your detailed repsonse, The MVC is one I followed on a tutorial online, here is a copy of my Database Lib <?php /* * PDO DATABASE CLASS * Connects Database Using PDO * Creates Prepeared Statements * Binds params to values * Returns rows and results */ class Database { private $host = DB_HOST; private $user = DB_USER; private $pass = DB_PASS; private $dbname = DB_NAME; private $dbh; private $error; private $stmt; public function __construct() { // Set DSN $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname; $options = array ( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); // Create a new PDO instanace try { $this->dbh = new PDO ($dsn, $this->user, $this->pass, $options); } // Catch any errors catch ( PDOException $e ) { $this->error = $e->getMessage(); } } // Prepare statement with query public function query($query) { $this->stmt = $this->dbh->prepare($query); } // Bind values public function bind($param, $value, $type = null) { if (is_null ($type)) { switch (true) { case is_int ($value) : $type = PDO::PARAM_INT; break; case is_bool ($value) : $type = PDO::PARAM_BOOL; break; case is_null ($value) : $type = PDO::PARAM_NULL; break; default : $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } // Execute the prepared statement public function execute(){ return $this->stmt->execute(); } // Get result set as array of objects public function resultset(){ $this->execute(); return $this->stmt->fetchAll(PDO::FETCH_OBJ); } // Get single record as object public function single(){ $this->execute(); return $this->stmt->fetch(PDO::FETCH_OBJ); } // Get record row count public function rowCount(){ return $this->stmt->rowCount(); } // Returns the last inserted ID public function lastInsertId(){ return $this->dbh->lastInsertId(); } } If you could see any errors that is causing the problem it would be appreciated, I will also look at what you have previously sent and get back to you if I get stuck
  6. hi, I have changed the code a little bit and put everything in my index page to try and to get it to work, I am not getting the Undefined error anymore I am just getting a 0 value with everything I do. The new revised code Model <?php public function countVehicles (){ $this->db->query("SELECT COUNT(id) FROM vehicles WHERE id = :id"); $counter = $this->db->rowCount(); return $counter; } And Controller <?php public function index(){ $counter = $this->vehicleModel->countVehicles(); $data = [ 'counter' => $counter ]; $this->view('vehicletracker/index', $data); } And View <?php <h2><?php echo $data['counter'];?></h2> Like mentioned I am just getting a return of 0, If someone can point me in the right direction it would be much appreciated And please KISS (Keep It Simple as I am Stupid)
  7. Hi, thanks for your response I have tried SELECT COUNT, but I still get the same "Undefined index: total" Is there a way I can check if the controller is getting the data?
  8. Hi I will try and explain this as best I can, as I am not sure if the "include" is causing the problem. What I am trying to achieve is count the total number of vehicles in the "vehicles" db table and pass it to views (I have recently moved over to MVC so still learning so please be kind and keep it simple for me please) I have a folder in views called "vehicletracker" , within this folder I have 2 files "index.php" and "widget.php".........The "widget.php" file is an "include" within "index php". The problem I am having is passing data from the controller to the view, I keep getting an "Undefined index: total" error and wonder if someone can help and show me where I am going wrong. This is my Model <?php class Widget { private $db; public function __construct(){ $this->db = new Database; } public function countVehicles(){ $this->db->query("SELECT * FROM vehicles"); return $this->db->rowCount(); } } This is my controller <?php class Widgets extends Controller{ public function __construct(){ $this->widgetModel = $this->model('Widget'); public function widget (){ $data['total'] = $this->widgetModel->countVehicles(); $this->view('vehicletracker/widget', $data); } } And my view <h2 class="text-white"><?php echo $data['total']; ?></h2> Thanks in advance for any help you can give
  9. Hi, Sorry lost you a little, this is the db Obviously it has'insert_time' and 'update_time' which is all well and good I am struggling to understand or get to grips with what I have to do to keep 'update_time' static for front end as like my image in OT What I want is:- Previous States status 1 = updated @ 20.09 Current State status 2 = updated @ 20.11 But currently if I changed the status to 2 I would get this results Previous States status 1 = updated @ 20.11 Current State status 2= updated @ 20.11 Would I be best to do 'fwrite' to a new file or is there another way
  10. Hi, I have managed to get it partially working but now stuck again, When I change the status the time changes in the db..which is what I wanted I will now try and explain what I want to do next When I change from Status 1 to Status 2 is it possible to grab the time of status change and make it static so it wont change when the status alters in the db again from 2-3 Will I need another column in the db or is there something I can do with php Thanks in advance
  11. Ooops my bad, sorry But thanks for adding the solution for me.
  12. Hi Is it possible to go above 12mths using %m, so for example 5 years = 60mths I am using this code to change the colour of panels which works ok until I make the due date 1yr 2 mths away it makes the panel go red, I need it to stay green and echo 14 mths <?php $expire = $dates->datedue; $date = new DateTime($expire); $now = new DateTime(); ?> <div class="col-md-3"> <div class="panel <?php if ($now->diff($date)->format("%m") < 3) { echo 'panel-red'; } else if ($now->diff($date)->format("%m") < 6) { echo 'panel-orange';} else { echo 'panel-green'; } ?>"> <div class="dark-overlay">Due Date</div> <div class="panel-body"> <h4 class="duedate"><?php echo $now->diff($date)->format("%m Months");?></h4> </div> </div> <?php if ($now->diff($date)->format("%m") < 3) { echo '<div class="text-center"><button class="btn btn-success"> Book Now</button></div>'; } ?> </div> So the question is Is it possible to have more than 12mths?
  13. Sorry just seen the mistake here and corrected it $db = $db = new PDO('mysql:host='.HOST.';dbname='.DATABASE.'', USER, PASSWORD);
  14. Right OK do you mean like this public function UserDetails($user_id) { try { $db = $db = new PDO('mysql:host='.HOST.';dbname='.DATABASE.'', USER, PASSWORD); $query = $db->prepare("SELECT users.user_id , users.registration , users.email , vehicle.reg_id , vehicle.vehicle , vehicle.registration , vehicle.chassis FROM users JOIN vehicle ON vehicle.registration = users.registration WHERE users.user_id = :user_id"); $query->bindParam("user_id", $user_id, PDO::PARAM_STR); $query->execute(); if ($query->rowCount() > 0) { return $query->fetch(PDO::FETCH_OBJ); } } catch (PDOException $e) { exit($e->getMessage()); } } And can I ask 1 more question about my function do I remove this catch (PDOException $e) when it goes live
  15. Right OK now I have sussed this and thank you again Barand for pointing me in the right direction, What if I have 2 tables with 30 columns each do I have to use shorthand or is there another way when I followed an old tutorial a few years ago and I used this function to get all the data without having to write all the columns names etc etc Would this or could this still work function user_data($user_id) { $data = array(); $user_id = (int)$user_id; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if ($func_num_args > 1) { unset ($func_get_args[0]); $fields = '`' . implode ('`, `', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `register` WHERE `id` = $user_id")); return $data; } }
  16. Sorry I have just sussed it using this public function UserDetails($user_id) { try { $db = DB(); $query = $db->prepare("SELECT users.user_id, users.registration, users.email, vehicle.reg_id, vehicle.vehicle, vehicle.registration, vehicle.chassis FROM users, vehicle WHERE users.registration = vehicle.registration"); $query->execute(); if ($query->rowCount() > 0) { return $query->fetch(PDO::FETCH_OBJ); } } catch (PDOException $e) { exit($e->getMessage()); } }
  17. Right a few more hours trying and I am getting now where fast..Is it the rest of the function ok This is where I am at at the minute public function UserDetails($user_id) { try { $db = DB(); $query = $db->prepare("SELECT user_id, registration, email FROM users JOIN vehicle ON vehicle.registration = users.registration"); $query->bindParam("user_id", $user_id, PDO::PARAM_STR); $query->execute(); if ($query->rowCount() > 0) { return $query->fetch(PDO::FETCH_OBJ); } } catch (PDOException $e) { exit($e->getMessage()); } } If I jiggle it I can retrieve the Registration number from users table but cant retrieve the vehicle and chassis number from the vehicle table Any help is much appreciated
  18. Thanks Barand for your advice, without boring you with the whole detail of the site I am trying to create I have decided to go with registration, as this is the unique to both vehicle and user the login page requires a registration and email to log in so it should not be possible for the owner to have two vehicles with the same reg no If like Jacques1 your are thinking why not put it all into 1 table then in the perfect world for me this is what I would do but I cant, I am hoping to take data from other databases whos main unique identifier will be the registration so I have to go what ALL databases will have in common to a specific user which will be the Registration No Thanks again I will have a try at a couple more queries and if I get stuck I will get back for more advice
  19. Right thank you for your advice, and without sounding rude, I wanted help with my function, not the structure of my databases, like already said I am just finally moving away from mysql and entering the world of pdo and to me it seemed like I have just learnt French but now I have to learn German. So not only do I want help with the query it would also be a learining curve for me and maybe others to understand how to join multiple tables and retrieve related data from each. Most forums expect you to try/search and smash your pc up before you ask the question, which is what I have done, So going back to my initial question:- how do I query the two tables and retrieve all the info from the tables and that the vehicle details belong to the right user???? Thanks in advance
  20. Like mentioned I want to put a lot more columns in both 'users' and 'vehicle' and I wanted it to look a bit cleaner Your response gives the impression that what I am trying to do is impossible..
  21. Right OK, sorry will try and explain what I am trying to do in a little more detail On the registration form the user enters 1, Registration 2. Email 3. Vehicle 4 Chassis No this data is then passed into two tables , 1&2 insert into 'users' and 3&4 inserts into 'vehicle' (I will be building on the data in these two tables, just need to link them first and retrieve the data This is the users table ANd this vehicle I put registration in both as I thought this may be used to help create a relationship between the 2 but not sure how to implement it, hence the post So my question is how do I query the two tables and retrieve all the info from the tables and that the vehicle details belong to the right user Hope this is a little clearer of what I am trying to achieve
×
×
  • 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.