943,793 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1730
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Oct 13th, 2008
0

Re: Im really really stuck ....

Click to Expand / Collapse  Quote originally posted by justted ...
Ah ok thanks.

Ive never done that query database manager thing and gave it a go. It showed me the job_roles table with all rows.

:>/
So are you looking to loop through all the rows from the only the second query and the first as well? And did the script actually loop through all the data as you were expecting, probably not huh?
Last edited by R0bb0b; Oct 13th, 2008 at 8:47 pm.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Oct 13th, 2008
0

Re: Im really really stuck ....

nope!
lol it didnt.

I dunno what im doing now. Got myself all confused.

I thought using the IF statement with else if for each level.

So it would check IF job position equals to 1 in the lobby field then show this ....

elseif the job position equals to 2 in the lobby field then show this .... and so on. That way it would have first checked to see if that member has a level one job then if not to see if they have a level 2 job and so on.

Arrghh ... lol
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Oct 13th, 2008
0

Re: Im really really stuck ....

run it with the $debug on and post the results.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Oct 14th, 2008
0

positions allocated to that member and

The problem is that for some reason it will only return 1 result of jobs for the user. I want to be able to allocate more than one position to my admins and therefore have the code find all job positions allocated to that member and then allow the highest level.

.... so say for example ... one admin has the job position of technical support and moderator! Tech support is level 1 (highest) and moderator is level 4! By using this method the code only seems to pick up the first job allocated to that member in the database and wont check all job positions!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gamn44 is offline Offline
3 posts
since Oct 2008
Oct 14th, 2008
0

Re: Im really really stuck ....

I think what you are saying is you want to loop through all database results from both queries, try this:
php Syntax (Toggle Plain Text)
  1. <?php
  2. $debug = false; //set to false if not debugging script
  3.  
  4. echo $debug?$query . "<br />":""; //if in debug, display query
  5.  
  6. print "$openHTML";
  7.  
  8. $query = "SELECT * FROM job_roles WHERE user_id = '$username'";
  9. $findresult = mysql_query($query);
  10. while($find_access = mysql_fetch_assoc($findresult))
  11. {
  12. $query = "SELECT * FROM job_positions WHERE name = '".$find_access['job_id']."'";
  13. $find_job = mysql_query($query);
  14. echo $debug?$query . "<br />":""; //if in debug, display query
  15.  
  16. $counter = 0;
  17. while($row = mysql_fetch_array($find_job))
  18. {
  19. if($debug) //if in debug, dump array content to browser
  20. {
  21. var_dump($row);
  22. echo "<br />";
  23. }
  24.  
  25. if((int)$row[lobby] > 0)
  26. {
  27. $counter++;
  28. }
  29.  
  30. switch((int)$row['lobby'])
  31. {
  32. case 1:
  33. echo "show content gere for access level 1";
  34. break;
  35. case 2:
  36. echo "show content gere for access level 2";
  37. break;
  38. case 3:
  39. echo "show content gere for access level 3";
  40. break;
  41. case 4:
  42. echo "show content gere for access level 4";
  43. break;
  44. case 0:
  45. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  46. break;
  47. default:
  48. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  49. break;
  50. }
  51. }
  52. }
  53.  
  54. echo $counter == 0?"<p><br><p><p><center>This page is a restrcited area. You do not have access!":"";
  55. print "$closeHTML";
  56.  
  57. ?>
Last edited by R0bb0b; Oct 14th, 2008 at 6:38 am.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Oct 14th, 2008
0

Re: Im really really stuck ....

Heya .... sorry for the dealy. I have got somewhere but still have a slight issue!

The code is now working but is of course showing results for all access levels when all I want is one result!

I had a think about it all and worked out the problem was with the initial variables. Because I have the 2 tables that I need to retrieve info from and need to create a variable for that...it was still only getting one result.

So I have searched and found out you can create a JOIN to select the information from 2 tables and basically make it one variable.

So now the code works but returns all results for each access level. This would obviusly look a mess and so I need to work out how to make it so it only returns the results for level 1 access first ... then if no level 1 access check and return results for level 2....and if none then to continue!

:>/ Any Ideas? im just going to have a play and see what i can come up with! :O)

Thanks for all your help. :O)

PHP Syntax (Toggle Plain Text)
  1.  
  2. $find_access = mysql_query("SELECT user_id,lobby,shops FROM job_roles,job_positions WHERE job_roles.job_id = job_positions.id");
  3.  
  4. print "$openHTML";
  5.  
  6. $find_job = fetch("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
  7. $counter = 0;
  8. while($row = mysql_fetch_array($find_access))
  9. {
  10. if ( ($row[lobby]== 1) AND ($row[user_id] == $username))
  11. {
  12. echo "show content gere for access level 1";
  13. $counter++;
  14. }
  15. if ( ($row[lobby]== 2) AND ($row[user_id] == $username))
  16. {
  17. echo "show content gere for access level 2";
  18. $counter++;
  19. }
  20. if ( ($row[lobby]== 3) AND ($row[user_id] == $username))
  21. {
  22. echo "show content gere for access level 3 ";
  23. $counter++;
  24. }
  25. if ( ($row[lobby]== 4) AND ($row[user_id] == $username))
  26. {
  27. echo "show content gere for access level 4";
  28. $counter++;
  29. }
  30.  
  31. if ( ($row[lobby]== 0) AND ($row[user_id] == $username))
  32. {
  33. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!"; $counter++;
  34. }
  35. }
  36.  
  37. echo $counter == 0?"<p><br><p><p><center>This page is a restrcited area. You do not have access!":"";
  38. print "$closeHTML";
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem with auto profile generator
Next Thread in PHP Forum Timeline: Empty a table?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC