Jump to content

Destramic

Members
  • Posts

    969
  • Joined

  • Last visited

Everything posted by Destramic

  1. i've had a read...and alot seems a bit complex but i couldnt find the part where it labels table two and three in a relationship...if you could help me please
  2. exellect mikosiko, just what i needed...also another thing if you have 3 tables they'd be called table 1 = table table 2 = relationship table table 3 = ? if you could help please...thank again for your help
  3. Hey guys I have a quick question i've made a table alias below but what do you call it when you put the table alias front of the column names?...SELECT n.news FROM news n
  4. wow i think that is exactly what i want thanks for your reply...a just a quick on what do you call a column when add the alias infont of it eg. n.news_id...would it be called a column alias? thanks again
  5. hey guys i have an array but want to add "n." infront of each key value...example n.news_id, n.user_id etc...is there a simple way/function of doing it other than changing the values through a loop? Array ( [news] => Array ( [0] => news_id [1] => user_id [2] => news [3] => date [4] => time ) )
  6. hey guys im trying to workout what relationship my tables are: one to one, one to many, many to many. here are my tables and query news --------- news_id user_id news ---------- users --------- user_id username --------- news_comments -------------- news_comment_id news_id comment ------------ query: SELECT n.news_id, n.news, n.date, n.time, u.username, count(nc.news_id) AS comments FROM news n LEFT JOIN news_comments nc ON n.news_id = nc.news_id LEFT JOIN users u ON n.user_id = u.user_id Group by n.news_id now i just want to know if im correct by saying my users table is one to one and the news_comments is one to many...im just trying to learn....thank you
  7. Destramic

    sum

    i figured it out now SELECT n.news_id, n.news, n.date, n.time, u.username, count(nc.news_id) AS comments FROM news n LEFT OUTER JOIN news_comments nc ON n.news_id = nc.news_id INNER JOIN users u USING (user_id) Group by n.news_id thanks for your help
  8. Destramic

    sum

    im just having no luck at all i really dont see what the probelm is here is the tables news ----------------- news_id news date time user_id news_comments ------------------------- news_comments_id news_id (forigen key) comments can you please tell me why its no working? SELECT `n.news_id`, `n.news`, `n.date`, `n.time`, `n.user_id`, COUNT(nc.news_id) AS `comments`, FROM news AS n LEFT JOIN news_comments AS nc ON nc.news_id = n.news_id ORDER BY date
  9. Destramic

    sum

    this is what ive been trying to do but im having no luck...what am i doing wrong please SELECT news_id, news, date, time, user_id, session_id, username, password, email, user_access, COUNT(news_comments.news_id) AS comments FROM news INNER JOIN users USING (user_id), JOIN news_comments USING (user_id), GROUP BY news_id ORDER BY date
  10. Destramic

    sum

    yes that is what i want i need to cound the news comments do i need another join for this?
  11. Destramic

    sum

    hey guys ive tried to impliment a sum count in my query and i have the wrong syntax somewhere along the lines...can me anyone help please? SELECT news_id, news, date, time, user_id, session_id, username, password, email, user_access FROM news INNER JOIN users USING (user_id), SUM(news_id) AS comments FROM news_comments GROUP BY news_id ORDER BY date
  12. is there away to do it as a one to many relationship or add to the query i already have?
  13. thanks alot this works great...also what would be the best way to count my news_comments table by news_id in this query below please? SELECT news_id, user_id, news, date, time, user_id, session_id, username, password, email, user_access FROM news INNER JOIN users USING (user_id) ORDER BY news ASC
  14. ive got it working now guy...what would you mean by a natural join please?...could you create an example out of my sql above?
  15. im having a probelm with this query on a one to one relationship...anyone know why please? SELECT n.news_id, u.username, n.news, n.date, n.time FROM news n LEFT JOIN users u ON news u.user_id = n.user_id ORDER BY news ASC
  16. looks complicated...i think i'll have to have a play around and have a read up because its not making much sence at the moment sorry
  17. that works great thank you
  18. it doesnt work if you do this $table = "news_comments"; $chars = str_split($table); echo $chars[0]; i want it to return NC...the code i written above does the same as yours really
  19. what im trying to d is substr a table name just to get the fisrt character so i can use it as an AS...example FROM news AS n $table = "news"; $as = substr($table, 0, 1); sigular named tables are fine...but if the table is named something like this news_comments and have many underscores i want it to return nc...what is the best way to achieve this please?
  20. do you have a better example of that class for each item please? thank you
  21. thanks for your post i think i found what i need "STATIC" so i can just call my from methods like this form::validate_field(); unless you guys have a better idea? and also @agnace how is spl_autoload_register() any different from using function __autoload($class_name) { if (file_exists(ROOT . DS . 'library' . DS . $class_name . '.class.php')) { require_once ROOT . DS . 'library' . DS . $class_name . '.class.php'; } else if (file_exists(ROOT . DS . 'application' . DS . 'controllers' . DS . $class_name . '.class.php')) { require_once ROOT . DS . 'application' . DS . 'controllers' . DS . $class_name . '.class.php'; } else if (file_exists(ROOT . DS . 'application' . DS . 'models' . DS . $class_name . '.class.php')) { require_once ROOT . DS . 'application' . DS . 'models' . DS . $class_name . '.class.php'; } else { echo "Class " . $class_name . " failed to load.<br />\n"; } }
  22. That code about was just an example...but I think you are on the right track with what you said but how do I make the form class a static for the rest of the classes I include in the controller please?
  23. but the form class is already called from the controller $form = new form; but then the model is added but i want to be able to call the form inside the model like $form->validate(); without having to load the class again or set a global $form = new forms(); //or global $form;
  24. hey guys im wondering the best way to call a class without repeating code for instance i load my classes using the autoload function but when i want to use my FORM class i have to set it as a global to before being able to call a function is there a way without doing this all the time function __autoload($class_name) { include $class_name . '.php'; } controller class controller extends mysql { public function __contruct() { global $form; $model = new model(); // loads automatically $form = new forms(); } } class model { function test() { global $form; // repeating code again to call forms $form->validate_field('test'); } } as you can see in the model i have to set the form global as in controller before calling a function....is there a better way that what im doing please? if you dont understand please let me know thank you
  25. thanks guys...wouldnt know what i'd do without you
×
×
  • 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.