Jump to content

glendango

Members
  • Posts

    93
  • Joined

  • Last visited

Everything posted by glendango

  1. your a legend lol..it works. $result = mysqli_query($conn,"SELECT u.company_id, u.name ,u.surname, u.id, count(f.date_made) as num_rows FROM users u LEFT JOIN firsts f ON u.id = f.usr_id where u.company_id='".$_SESSION['company_id']. "' group by u.id ") ; why doesn't my 'group by' go 'red' like my other code?? anyway now that works,,what about getting it all into the same table,,,, at moment i have 4 separate tables for all the info iam trying to display to the user.
  2. i get this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\******\www\li****\firstsleague.php on line 78 when using this : $result = mysqli_query($conn,"SELECT u.company_id, u.name ,u.surname, u.id, count(f.date_made) as num_rows FROM users u LEFT JOIN firsts f ON u.id = f.usr_id group by u.id where u.company_id='".$_SESSION['company_id']."' ") ; also could you explain the theory : should i only have one query for every html table and join tables together?? or is it ok to have say 4 separate select statements all feeding the results into 1 table? cheers
  3. i get an error if i use 'where' and if i make it work , will it all sit in the table correctly?
  4. hi, can anyone advise regarding practice of displaying data from a database to the end user. If you creating 1 large table with a lot of stats in for users, should you have have 1 massive select statement or do it in individual statments like i have. my code works ok but i cant work out how to get the 'Total Year' column to populate..the stats i want appear under the user id's...(see attached jpeg) $result = mysqli_query($conn,"SELECT u.company_id, u.name ,u.surname, u.id, count(f.date_made) as num_rows FROM users u LEFT JOIN firsts f ON u.id = f.usr_id group by u.id having u.company_id='".$_SESSION['company_id']."' ") ; while($firsts=mysqli_fetch_array($result)){ echo "<tr>"; //changes date to english format from a time stamp echo"<td>".$firsts['company_id']."</td>"; echo"<td>".$firsts['id']."</td>"; echo"<td>".$firsts['name']. ' '.$firsts['surname']."</td>"; echo"<td>".$firsts['num_rows']."</td>"; //echo"<td>".$firsts['date_mades']."</td>"; } $result1 = mysqli_query($conn,"SELECT u.company_id,u.name,u.surname, u.id, count(f.date_made) as date_mades FROM users u LEFT JOIN firsts f ON u.id = f.usr_id AND DATE(f.date_made) and year(curdate()) = year(date_made) group by u.id having u.company_id='".$_SESSION['company_id']."' "); while($firsts=mysqli_fetch_array($result1)) //echo "<tr>"; { echo "</tr>"; echo"<td>".$firsts['date_mades']."</td>"; } $result = mysqli_query($conn, "SELECT count(f.date_made) as date_mades FROM users u LEFT JOIN firsts f ON u.id = f.usr_id and u.company_id='".$_SESSION['company_id']."' "); while($firsts=mysqli_fetch_array($result)){ echo "<tr>"; echo"<td>".'Total'."</td>"; echo"<td>"; echo"<td>"; echo"<td>".$firsts['date_mades']."</td>"; //echo"<td>".$firsts['date_madess']."</td>"; } ?>
  5. i changed the where to 'and' and it worked... thanks for your advice... i keep getting errors when i try your code with my session company_id.... i know your code is correct but this is what i ended up with to make my code work... your advice still helped me plaster the query together though as the logic is certain things like where, and etc only work together in certain ways . thx again
  6. i have 2 queries . the first query gives me all the users with the same company_id and displays a '0' against their name if they have no enties. but the second query doesn't display the users with no entries against their name. in this case the query counts dates of entries they have made. I am guessing its something to do with using 'between' and 'where'. any ideas ? thx $result = mysqli_query($conn,"SELECT u.name , u.surname , u.id , u.company_id, count(f.date_made) as date_made FROM users u LEFT JOIN firsts f ON u.id = f.usr_id AND DATE(f.date_made) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() group by u.id having u.company_id='".$_SESSION['company_id']."' ") ; // company session from this month,,above code gives all users even if 0,,below desnt?? $result = mysqli_query($conn,"SELECT u.id , u.name , u.surname , u.company_id, count(f.date_made) as date_made FROM users u LEFT JOIN firsts f ON u.id = f.usr_id AND DATE(f.date_made) WHERE year(curdate()) = year(date_made) and month(curdate()) = month(date_made) group by u.id having u.company_id='".$_SESSION['company_id']."' ") ;
  7. "SELECT u.name , u.surname , u.id , u.company_id, count(f.date_made) as date_made FROM users u LEFT JOIN firsts f ON u.id = f.usr_id AND DATE(f.date_made) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() group by u.id having u.company_id='".$_SESSION['company_id']."' ") ; this seems to have worked..will send a donation as think your bollockings are very useful : what do you think? i set up a session as company_id and put it in the select... is this how business apps are able to link all users by their branches etc or is there a better link you know of to teach to set up users by branch / company / all in a league..a bit like strava but for sales leads.
  8. how would i select the branch id dynamically? i.e. where u.company_id=4​ i need it to group the users with the same branch id. without me actually putting 4 in.. SELECT u.name , u.surname , u.id , u.company_id, count(f.date_made) as date_made FROM users u LEFT JOIN firsts f ON u.id = f.usr_id where u.company_id=4 AND DATE(f.date_made) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() group by u.id ") ;
  9. in the users table and the id is related to table `company`
  10. Sorry to ask again. If i wanted to also use this select statement to only show the users with same branch_id , where would this go? i've tried a few things but keep getting errors. is it to do with sessions or just adding = to branch_id somewhere in the select statement? "SELECT u.name , u.surname , u.id , u.company_id, count(f.date_made) as date_made FROM users u LEFT JOIN firsts f ON u.id = f.usr_id AND DATE(f.date_made) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() GROUP BY u.id "
  11. found the problem! AND DATE(`f.date_made`) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() ​should be AND DATE(f.date_made) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() ​thank you again...
  12. really sorry but iam getting an error. it gives error direct into sql as well. i can see that your requesting the id from the users table so this is a clue to how this then gets displayed.. sorry to waste your time but is the firsts.f and users.u supposed to be there as i cant see what it references. $result = mysqli_query($conn,"SELECT users.name , users.surname , users.id , count(firsts.date_made) as date_made FROM users.u LEFT JOIN firsts.f ON users.id = firsts.usr_id AND DATE(`firsts.date_made`) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() GROUP BY users.id"); while($firsts=mysqli_fetch_assoc($result)){
  13. sorry you ve lost me,... what would that look like? .. grateful for your time and will donate when iam making money
  14. thanks fo reply , this gave me the same result as my version: "SELECT users.name,users.surname, usr_id, count(date_made) as date_made FROM users LEFT JOIN firsts on users.id=firsts.usr_id WHERE DATE(`date_made`) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() group by usr_id ");
  15. $result = mysqli_query($conn, "SELECT users.name,users.surname, firsts.usr_id, count(usr_id) ,count(date_made) as date_made FROM `firsts` left join users on users.id=firsts.usr_id WHERE DATE(`date_made`) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() group by usr_id "); Hi, as you can see i join 2 tables which gives me a small table with: name | surname | firsts for last 7 days | i search results by counting the entries from date_made. If the user has made no 'firsts' in the last 7 days, they don't show up in the table..which is kind of cool but i need the staff who have no firsts to show up in the table with 0 firsts next to them.. sorry for the below text,,it let me paste the table in and on submission printed this : i get this result Name id Last 7 days billy bragg 1 10 James brown 5 1 bless you 6 1 Total 12 i want Name id last 7 days billy bragg 1 10 lisa jones 3 0 James brown 5 1 bless you 6 1 redd eyes 7 0 dunelm bob 11 0 Total 12 my statements are prob rank but good to know if there is a solution. thx
  16. WTF!!! no way is it that obvious.... 4 hours of searching...thank you!!!!!! i know about the sanitizationwill be going over whole app and learning to use the proper methods. guru is this how its done once you have users logged into your app or do you use other ways to enter data into databse from their id. this seems quick and easy though
  17. So when they log in, store information that you need to access frequently in the session. Like the user ID. i think my question is then: how do i access the id for a table?
  18. It's not like they can keep logging in on every single page over and over again. - isn't that what session_start();. is for on every page?
  19. is it common practice to use $session to then insert their id into a db table?
  20. Hi, i ve created an app which works fine while iam the admin. I now want to create users ( i have dummy users in the practice app and all foreign keys work fine) I ve just set up a log in system for users and using $session, which sounds standard from the many tutorials i ve learnt from. But after the log in system all tutorials seem to go dead. Anyway my next step is to allow a user who had logged in ( who by signing up has entered into a 'users' table in MySQL with a unique id) i now want them to fill out forms which will input into table 'firsts'.. Which has the foreign key of their id. am i missing something..how do tell the database to populate the form using the users id. Is it common practice to use $_SESSION['usr_id'] or do i get the users id some other way..i cant work it out for some reason... thanks heres what i have so far .. .not sanitized yet etc session_start();. ????? [user id] $client_title =$_POST['client_title']; $client_name =$_POST['client_name']; $client_contact =$_POST['client_contact']; $client_email =$_POST['client_email']; $notes =$_POST['notes']; $sql = "INSERT INTO firsts (usr_id, client_title, client_name, client_contact, client_email, notes ) VALUES ('$usr_id', '$client_title' , '$client_name' ,'$client_contact' ,'$client_email' ,'$notes' )"; $result = mysqli_query($conn,$sql);
  21. also i ve wondered if you put code on internet like i have asking questions...when using internal server etc for fun.. can bots still make use of your code and 'plant ' shit before you go live on web ( i realise this is a mega newbie question but want to cover all options )
  22. wow scary stuff.. if theyre are loads of people like me coding shit all day then do sites get hacked all the time??? is this what frameworks give you??? a bit of protection? or have many companies been hacked by bad programmers mis selling their skills and not protecting code properly?
  23. The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help::: trouble is you only know y was your problem after you have fixed x .. #life
  24. ha,,i will , that is a class logo you have.. red cross , helping dumb shits protect their code... nice one.. i am learning about all this now... just for own interest... do you protect your code against individual hackers or does it protect against mass viruses... just wondering if the risks are lower if you are a very small company or facebook which is obv a hackers main goal to crack.
×
×
  • 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.