Im really really stuck ....

Reply

Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Im really really stuck ....

 
0
  #1
Oct 13th, 2008
Hello,

I am really really stuck on a small project im working on and have been at it now for the past 12 hours. lol

I am trying to set up a restrcited page for my admins and have the following:

  1.  
  2. $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'");
  3. $find_job = fetch ("SELECT * FROM job_positions WHERE name = '$find_access[job_title]'");
  4.  
  5. print "$openHTML";
  6.  
  7. if ($find_job) {
  8.  
  9.  
  10.  
  11.  
  12. if ( $find_job[lobby]== 1) {
  13.  
  14. echo "show page content gere for access level 1";
  15. }
  16. if ( $find_job[lobby]== 2) {
  17. echo "show page content gere for access level 2";
  18. }
  19. if ( $find_job[lobby]== 3) {
  20. echo "show page content gere for access level 3 ";
  21. }
  22. if ( $find_job[lobby]== 4) {
  23. echo "show page content gere for access level 4";
  24. }
  25.  
  26. if ( $find_job[lobby]== 0) {
  27. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  28. }
  29. }
  30.  
  31.  
  32.  
  33.  
  34. if (!$find_job) {
  35. echo "<p><br><p><p><center>This page is a restrcited area. You do not have access!";
  36. }
  37.  
  38.  
  39. print "$closeHTML";
  40.  
  41. ?>


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!

Does this make sense?

I know that the while statement selects all rows where the command is positive but I gave it a quick go and it didnt work.

Can anyone tell me why it will only return and check against one result and not compare these variables against all rows that are true???? And if there is a way around this?

Thanks

Justin
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Im really really stuck ....

 
0
  #2
Oct 13th, 2008
fetch() is not in the manual, can you post that function?
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Im really really stuck ....

 
0
  #3
Oct 13th, 2008
huh? lol

It seems to work for my website? What do you mean post that function? :>/ Sorry im still only learning PHP and MySQL.

I got a script that was very badly coded and have been trying to improve it so this is a typical case. lol
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Im really really stuck ....

 
0
  #4
Oct 13th, 2008
Ah ... I do have this is a file that is included :

  1.  
  2. function fetch($query)
  3. {
  4. // echo $query;
  5. return mysql_fetch_array(mysql_query($query));

From what I understand this is used for fecth querys to the database!
:>/
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Im really really stuck ....

 
0
  #5
Oct 13th, 2008
Originally Posted by justted View Post
Ah ... I do have this is a file that is included :

  1.  
  2. function fetch($query)
  3. {
  4. // echo $query;
  5. return mysql_fetch_array(mysql_query($query));

From what I understand this is used for fecth querys to the database!
:>/
The way this function is being used, it will only return one row. What you should do for any query you want more than just the first row from is the following:
  1. $find_access = mysql_query("SELECT * FROM job_roles WHERE user_id = '$username'");
  2. while($row = mysqsl_fetch_array($find_access))
  3. {
  4. //loop through each row here with $row['column_name']
  5. }
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Im really really stuck ....

 
0
  #6
Oct 13th, 2008
Hello,

Thanks for your help.

I have tried the following code but get an error!

Parse error: syntax error, unexpected T_IF on line 24

Obviously this means that IF statements are not allowed within the WHILE statement. Am I correct in saying that?

  1.  
  2. $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'");
  3. $find_job = fetch ("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
  4.  
  5. print "$openHTML";
  6.  
  7. if ($find_job) {
  8. $find_access = mysql_query("SELECT * FROM job_roles WHERE user_id = '$username'");
  9. while($row = mysqsl_fetch_array($find_job))
  10. {
  11. //loop through each row here with $row['column_name']
  12. $row[id]
  13.  
  14. }
  15.  
  16. if ( $row[lobby]== 1) {
  17. echo "show content gere for access level 1";
  18. }
  19. if ( $row[lobby]== 2) {
  20. echo "show content gere for access level 2";
  21. }
  22. if ( $row[lobby]== 3) {
  23. echo "show content gere for access level 3 ";
  24. }
  25. if ( $row[lobby]== 4) {
  26. echo "show content gere for access level 4";
  27. }
  28.  
  29. if ( $row[lobby]== 0) {
  30. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  31. }
  32.  
  33.  
  34. if (!$find_job) {
  35. echo "<p><br><p><p><center>This page is a restrcited area. You do not have access!";
  36. }
  37.  
  38. }
  39. print "$closeHTML";
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Im really really stuck ....

 
0
  #7
Oct 13th, 2008
try this:
  1. <?php
  2. $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'");
  3.  
  4. print "$openHTML";
  5.  
  6. $find_job = mysql_query("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
  7. $counter = 0;
  8. while($row = mysqsl_fetch_array($find_job))
  9. {
  10. if ( $row[lobby]== 1)
  11. {
  12. echo "show content gere for access level 1";
  13. $counter++;
  14. }
  15. if ( $row[lobby]== 2)
  16. {
  17. echo "show content gere for access level 2";
  18. $counter++;
  19. }
  20. if ( $row[lobby]== 3)
  21. {
  22. echo "show content gere for access level 3 ";
  23. $counter++;
  24. }
  25. if ( $row[lobby]== 4)
  26. {
  27. echo "show content gere for access level 4";
  28. $counter++;
  29. }
  30.  
  31. if ( $row[lobby]== 0)
  32. {
  33. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  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";
  39.  
  40. ?>

[just edited] to iterate the counter in all cases except "0"
Last edited by R0bb0b; Oct 13th, 2008 at 6:44 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Im really really stuck ....

 
0
  #8
Oct 13th, 2008
Hi again,

I see what youve done and what I didnt do. lol I forgot the ++.

Now it seems to have included the config files and shows the following error which ive seen before and is related to that fetch command I was using and the while statement. :>/

Fatal error: Call to undefined function mysqsl_fetch_array() in /access_rights.php on line 15

Line 15 is :
  1. while($row = mysqsl_fetch_array($find_job))
Im not so familiar with while statements so am a little stuck. I tried changing the fetch to mysql_query for the $find_access but that didnt work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Im really really stuck ....

 
0
  #9
Oct 13th, 2008
oops, misspelled it, its not suppose to be mysqsl_fetch_array but mysql_fetch_array

try this:
  1. <?php
  2. $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'");
  3.  
  4. print "$openHTML";
  5.  
  6. $find_job = mysql_query("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
  7. $counter = 0;
  8. while($row = mysql_fetch_array($find_job))
  9. {
  10. if ( $row[lobby]== 1)
  11. {
  12. echo "show content gere for access level 1";
  13. $counter++;
  14. }
  15. if ( $row[lobby]== 2)
  16. {
  17. echo "show content gere for access level 2";
  18. $counter++;
  19. }
  20. if ( $row[lobby]== 3)
  21. {
  22. echo "show content gere for access level 3 ";
  23. $counter++;
  24. }
  25. if ( $row[lobby]== 4)
  26. {
  27. echo "show content gere for access level 4";
  28. $counter++;
  29. }
  30.  
  31. if ( $row[lobby]== 0)
  32. {
  33. echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!";
  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";
  39.  
  40. ?>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Im really really stuck ....

 
0
  #10
Oct 13th, 2008
Wow blimey! My eyes totally passed that! Amazing how one little typo can cause the script not to work. lol

Now its working although its still only picking up the access set for one job position.



My two tables are as follows:

job_positions
id
name
daily_exp
lobby


and the job_roles are
id
job_id
user_id
job_title


I have made 2 job positions Founder and Test

I have allocated myself to these 2 positions and when I set test to level 1 and founder to level 2 it will only show the level 2 as founder must be the first one it comes to!!

I want it to look at all the job roles allocated to the member and if one of them is say level 1 then it will show level 1 access.

I just cant see why it wont work. LOL

I did notice a slight error in my variables but have fixed that!



My varaibles are
So the following:
  1. $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'");
  2.  
  3. print "$openHTML";
  4.  
  5. $find_job = mysql_query("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");


So it should make the following commands:

$find_access selects all field info from job_roles where the user_id equals the username of the member. (for me this is founder and test)

The the $find_job should take all jobs that have the id number equal to the job_id of the job_roles table. (for me this would again be founder and test)

The the IF statement should say collect all rows (job_positions) that has a number equal to ==1,2,3 or 4 and then allow access to the page content within that particular IF statement.

Hmm ... I cant see anything wrong with that! I guess its just making it so it checks against all job posiitons for that member. Maybe I will have to reorganise the tables or database and set it up another way! :>/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 1348 | Replies: 25
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC