| | |
Im really really stuck ....
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
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:
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
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:
PHP Syntax (Toggle Plain Text)
$find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'"); $find_job = fetch ("SELECT * FROM job_positions WHERE name = '$find_access[job_title]'"); print "$openHTML"; if ($find_job) { if ( $find_job[lobby]== 1) { echo "show page content gere for access level 1"; } if ( $find_job[lobby]== 2) { echo "show page content gere for access level 2"; } if ( $find_job[lobby]== 3) { echo "show page content gere for access level 3 "; } if ( $find_job[lobby]== 4) { echo "show page content gere for access level 4"; } if ( $find_job[lobby]== 0) { echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!"; } } if (!$find_job) { echo "<p><br><p><p><center>This page is a restrcited area. You do not have access!"; } print "$closeHTML"; ?>
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
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.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
Ah ... I do have this is a file that is included :
From what I understand this is used for fecth querys to the database!
:>/
PHP Syntax (Toggle Plain Text)
function fetch($query) { // echo $query; return mysql_fetch_array(mysql_query($query));
From what I understand this is used for fecth querys to the database!
:>/
•
•
•
•
Ah ... I do have this is a file that is included :
PHP Syntax (Toggle Plain Text)
function fetch($query) { // echo $query; return mysql_fetch_array(mysql_query($query));
From what I understand this is used for fecth querys to the database!
:>/
php Syntax (Toggle Plain Text)
$find_access = mysql_query("SELECT * FROM job_roles WHERE user_id = '$username'"); while($row = mysqsl_fetch_array($find_access)) { //loop through each row here with $row['column_name'] }
“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.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
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?
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?
PHP Syntax (Toggle Plain Text)
$find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'"); $find_job = fetch ("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'"); print "$openHTML"; if ($find_job) { $find_access = mysql_query("SELECT * FROM job_roles WHERE user_id = '$username'"); while($row = mysqsl_fetch_array($find_job)) { //loop through each row here with $row['column_name'] $row[id] } if ( $row[lobby]== 1) { echo "show content gere for access level 1"; } if ( $row[lobby]== 2) { echo "show content gere for access level 2"; } if ( $row[lobby]== 3) { echo "show content gere for access level 3 "; } if ( $row[lobby]== 4) { echo "show content gere for access level 4"; } if ( $row[lobby]== 0) { echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!"; } if (!$find_job) { echo "<p><br><p><p><center>This page is a restrcited area. You do not have access!"; } } print "$closeHTML";
try this:
[just edited] to iterate the counter in all cases except "0"
php Syntax (Toggle Plain Text)
<?php $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'"); print "$openHTML"; $find_job = mysql_query("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'"); $counter = 0; while($row = mysqsl_fetch_array($find_job)) { if ( $row[lobby]== 1) { echo "show content gere for access level 1"; $counter++; } if ( $row[lobby]== 2) { echo "show content gere for access level 2"; $counter++; } if ( $row[lobby]== 3) { echo "show content gere for access level 3 "; $counter++; } if ( $row[lobby]== 4) { echo "show content gere for access level 4"; $counter++; } if ( $row[lobby]== 0) { echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!"; } } echo $counter == 0?"<p><br><p><p><center>This page is a restrcited area. You do not have access!":""; print "$closeHTML"; ?>
[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.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
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 :
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.
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 :
PHP Syntax (Toggle Plain Text)
while($row = mysqsl_fetch_array($find_job))
oops, misspelled it, its not suppose to be mysqsl_fetch_array but mysql_fetch_array
try this:
try this:
php Syntax (Toggle Plain Text)
<?php $find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'"); print "$openHTML"; $find_job = mysql_query("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'"); $counter = 0; while($row = mysql_fetch_array($find_job)) { if ( $row[lobby]== 1) { echo "show content gere for access level 1"; $counter++; } if ( $row[lobby]== 2) { echo "show content gere for access level 2"; $counter++; } if ( $row[lobby]== 3) { echo "show content gere for access level 3 "; $counter++; } if ( $row[lobby]== 4) { echo "show content gere for access level 4"; $counter++; } if ( $row[lobby]== 0) { echo "<p><br><p><p><center>Sorry but your Access Level is not permitted for this page!"; } } echo $counter == 0?"<p><br><p><p><center>This page is a restrcited area. You do not have access!":""; print "$closeHTML"; ?>
“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.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
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:
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! :>/
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:
PHP Syntax (Toggle Plain Text)
$find_access = fetch ("SELECT * FROM job_roles WHERE user_id = '$username'"); print "$openHTML"; $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! :>/
![]() |
Similar Threads
- Windows XP is stuck! (Windows NT / 2000 / XP)
- Advertisment icons stuck to my desktop!!! (Viruses, Spyware and other Nasties)
- Stuck writing a Function (C++)
- error message when shutting down, startup page stuck to http://dr-search4u.com/ind... (Viruses, Spyware and other Nasties)
- Stuck In Restart Loop (Windows NT / 2000 / XP)
- Help with Class, stuck. (C++)
- CPU use stuck at 100% (Viruses, Spyware and other Nasties)
- Stuck on start up (Windows NT / 2000 / XP)
- Internet explorer 5 gets stuck (Web Browsers)
- stuck in lower case, lost functions (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: Problem with auto profile generator
- Next Thread: Empty a table?
Views: 1348 | Replies: 25
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





