mdemetri2 Posted February 17, 2014 Share Posted February 17, 2014 Hi I expect this is possible. If I have three recordsets but one table. Is it possible to alter the results displayed in the table dependent on a variable e.g. returned from the person logged in. Or maybe its case of have the three tables but only displaying them when the variable is to x, y or z? So currently, I have one table that displays content, code extract. <table width="593" border="0" class="TableContent"> <?php do { ?> <tr> <td width="575" class="TableContent2"><a href="R/zzedit.php?id=<?php echo $row_retail['id'];?>&ref=<?php echo $row_retail['property'];?>"><?php echo $row_retail['id']; ?></a><?php echo $row_retail['item']; ?><?php echo $row_retait['route']; ?><?php echo $row_retail['class']; ?></td> </tr> <?php } while ($row_retail = mysql_fetch_assoc($retail)); ?> </table> Would be great for anyone to point me in the right direction on this or provide some assistance. Appreciated. mdemetri2 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 17, 2014 Share Posted February 17, 2014 Is it possible to alter the results displayed in the table dependent on a variable e.g. returned from the person logged in. Absolutely. You can retrieve the result from database and write it down on the HTML markup, only, for instance if the user_ID = 1, or something similar. If you have more than one result you need to use some looping constructs in php. Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 17, 2014 Author Share Posted February 17, 2014 Ok, so it is possible as I was thinking. I'm just not clear on how to achieve it at the moment. Easy bit is setting a variable based on a return from the user logged in. Its then doing an if else scenario on the table to display the corresponding result set or having the three tables visibility altered depending on the variable returned.....the latter requiring java script I believe. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 17, 2014 Share Posted February 17, 2014 (edited) Are you only want to display the table if they are logged in? You'd wrap the whole table in a if statement, example pseudo code if( user is logged in ) { // display table } Edited February 17, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 17, 2014 Author Share Posted February 17, 2014 Thanks for the replies. The idea is, depending on the type of user logged in (identified by a variable brought back once the user is logged in) then a different table is displayed - as the query to populate the table is different for each table. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 17, 2014 Share Posted February 17, 2014 depending on the type of user logged in (identified by a variable brought back once the user is logged in) What is that? then a different table is displayed - as the query to populate the table is different for each table. What are these tables? Can we see example queries for each table Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 17, 2014 Author Share Posted February 17, 2014 (edited) Well, the variable would be $usertype = $row_user['type'] , essentially the result of a query based on '$_SESSION[MM_Username]'. Result would be numeric so user type 1,2 or 3 Example code for one table in my first post. The other two would be the same, but use different recordset / queries to populate. Hope this makes sense. Edited February 17, 2014 by mdemetri2 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 17, 2014 Share Posted February 17, 2014 I don't get something very well. Why do you want one user to have with 3 different types? For example, one user would have at same time - type = 1 (regularUser), type=2(advancedUser) or type=3 (admin). What the purpose of this type column is? Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 17, 2014 Author Share Posted February 17, 2014 jazzman1 - One user can only be associated with one type....so type 1 sees table 1, type 2 sees table 2 etc. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 17, 2014 Share Posted February 17, 2014 jazzman1 - One user can only be associated with one type....so type 1 sees table 1, type 2 sees table 2 etc. Then, you have a horrible database design. Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 17, 2014 Author Share Posted February 17, 2014 jazzman1 - I'm not sure you understand. When I say table, I mean html table populated with query results..... Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 17, 2014 Share Posted February 17, 2014 You still didn't tell us what the role of this type in your application is? Quote Link to comment Share on other sites More sharing options...
mdemetri2 Posted February 18, 2014 Author Share Posted February 18, 2014 jazzman1 - I don't see why I need to. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 18, 2014 Share Posted February 18, 2014 what you are asking to do is simple conditional logic (if/else or switch) or even just a lookup (key/value) array to get values/content based on the user type. however, you haven't shown what exactly changes for each different type so no one has been able to show you anything. we don't know if a database query just returns different values, or if you produce different amounts of links,... in fact, you might not need to do anything in your php code and everything would just be handled in the database query statement. Quote Link to comment Share on other sites More sharing options...
Solution mdemetri2 Posted February 20, 2014 Author Solution Share Posted February 20, 2014 Ok so in the end I managed to figure this out myself. Thanks for the replies from those who made suggestions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.