Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2012, 07:17 PM   PM User | #1
greenhat
New Coder

 
Join Date: Sep 2012
Posts: 10
Thanks: 9
Thanked 0 Times in 0 Posts
greenhat is an unknown quantity at this point
Get mysql result.

This may be the most simple thing to do in php. Forgive me, I am from the .net world where all this is simple. all I want is what this query is:
PHP Code:
                session_start();
                include 
"connectTo.php";
                
$link connectTo();
            
$id $_SESSION['email'];
         
$table "users";
                
$query =  "SELECT role FROM $table WHERE username ='$id'";
                
$result mysql_query($query,$link);
                if (!
$result) {
                
$message  'Invalid query: ' mysql_error() . "\n";
                
$message .= 'Whole query: ' $query;
                 die(
$message);
                }
                while (
$row mysql_fetch_assoc($result)) {
                echo 
$row['username'];
               } 
how do i echo or get this comparison so I can set up a switch on the result?

Last edited by greenhat; 10-19-2012 at 07:58 PM..
greenhat is offline   Reply With Quote
Old 10-19-2012, 09:29 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Where do you want to set the switch and which variables/strings do you want to run through it? Expound on that.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 10-19-2012, 11:27 PM   PM User | #3
greenhat
New Coder

 
Join Date: Sep 2012
Posts: 10
Thanks: 9
Thanked 0 Times in 0 Posts
greenhat is an unknown quantity at this point
Get mysql result.

I have a string field in the users table called role. I want to show different forms based on five different role types. The code will get quite lengthy. Rather use a switch than a bunch of if statements. So i want the query result to spit out a string to compare.
greenhat is offline   Reply With Quote
Old 10-19-2012, 11:37 PM   PM User | #4
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Well, for the role field:

PHP Code:
<?php

    $role 
$row['role'];

switch(
$role){

     case 
'actor':
      
//Actor code
          
break;
 case 
'janitor':
      
//janitor code
          
break;
      
//Blah blah as many cases as you want

default:
//Code to be executed if $role does not fall into any of the above

}

?>
Check out more about switches here.

I'm guessing that maybe the problem is the flow of logic from the while statement to the switch statement. If so, don't hesitate to post it here.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 10-20-2012 at 05:14 PM..
Redcoder is offline   Reply With Quote
Users who have thanked Redcoder for this post:
greenhat (10-20-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:18 AM.


Advertisement
Log in to turn off these ads.