Jump to content

MargateSteve

Members
  • Posts

    240
  • Joined

  • Last visited

Everything posted by MargateSteve

  1. I finally cracked this last night so thought I would share it in the unlikely event that someone else would find it useful. In the end, all I had to do was wrap the whole thing in one more query. Select RNKING.WST, RNKING.WND, RNKING.RNK, RNKING.PLYR, RNKING.PPP, RNKING.TOT From (Select SCORES.PLYR, SCORES.PPP, SCORES.WST, SCORES.WND, SCORES.YWK, Case When @currweek != SCORES.YWK Then @rank := 1 Else @rank := @rank + 1 End As rank, @rank As RNK, @currweek := SCORES.YWK As t, @currweek As tt, SCORES.TOT From (Select U.username PLYR, YearWeek(G.date, 1) YWK, Date_Add(G.date, Interval (0 - WeekDay(G.date)) Day) WST, Date_Add(G.date, Interval (6 - WeekDay(G.date)) Day) WND, Week(G.date) WK, Sum(Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) PTS, Sum(Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) TOT, Sum(Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) / Sum(Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) PPP, U.userid From users U Inner Join predictions P On U.userid = P.user Inner Join games G On G.gamesid = P.game Inner Join compgame CG On G.gamesid = CG.game Where CG.comp Not In (1, 3) and G.date < Now() Group By YearWeek(G.date, 1), U.userid Order By YearWeek(G.date, 1),PPP Desc) SCORES) RNKING Having RNK <= 3
  2. I think that the separate stylesheets will be the way to go although it will mean a bit of hassle re-doing them.
  3. That is an issue I kept coming up against. Which viewports do I cater for explicitly and how do I make sure that it still looks correct on a desktop browser that is not opened full width.
  4. Is there a simple way to allow a user to ignore media queries and see the desktop version on any device? Although the intention is to have all the information available at all resolutions, there are a few things, especially tables, that it will be impossible to replicate on smaller devices. I know I could do it by calling a different style sheet if the user requests it or putting all the responsive stuff in a seperate sheet that will only be shown to users who have not chosen to override it but wondered if there was an easy way to fool a browser into thinking it was at a desktop resolution. Thanks Steve
  5. I thought that might be the problem fenway, as none of the usual top n methods I know of will work with these joins. The trouble is, to simplify it would take something away that is vital, however, as I am now close to the solution (thanks to a bit of help elsewhere and some perseverance) the 'missing link' may seem straightforward. The required outcome in a nutshell.... Members predict x amount of games per week. PPP is the average points scored. What I want to do is group all results by week (YearWeek as it will run for more than a year) and show the top 3 users (highest PPP) per week. Where I am now is completely different to the attempt above and the current query is below. Everything is working correctly except showing the top 3 members per week. All PPP's are grouped by week and by member, the highest scoring member is RNK 1, next is RNK 2 so everything works fine until the request to limit it to top 3 per week. The bizarre thing is that it is sort of working, but restricted to only odd number ranks (RNK). So HAVING RNK <=3 returns members with RNK 1 or 3. HAVING RNK <=7 returns members with RNK 1, 3, 5 or 7 and so on. My guess is that the 'HAVING' clause needs to go somewhere different or be replaced completely with another way of restricting the result. Trouble is, I am all out of ideas having got to this point so if anyone can show me the obvious, I would be grateful. Select groupedtable.compuserid, groupedtable.PTS, groupedtable.TOT, groupedtable.PPP, groupedtable.WST, groupedtable.WND, groupedtable.WK, groupedtable.DTE, (Case When @currweek != YWK Then @rank := 1 Else @rank := @rank + 1 End) RNK, @currweek := YWK As t, @currweek As tt From (Select datatable.compuserid, Sum(datatable.PTS) As PTS, Sum(datatable.TOT) As TOT, Sum(datatable.PTS) / Sum(datatable.TOT) As PPP, datatable.WST, datatable.WND, datatable.WK, datatable.YWK, datatable.DTE From (Select CU.compuserid, (Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) PTS, (Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) TOT, (Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) / (Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) PPP, Date_Add(G.date, Interval (0 - WeekDay(G.date)) Day) WST, Date_Add(G.date, Interval (6 - WeekDay(G.date)) Day) WND, Week(G.date) WK, G.date DTE, YearWeek(G.date, 1) YWK From compuser CU Left Join comps C On C.compid = CU.comp Left Join users U On U.userid = CU.user Left Join compgame CG On C.compid = CG.comp Left Join games G On G.gamesid = CG.game Left Join predictions P On CU.user = P.user And CG.game = P.game Where G.date < Now() Order By G.date, (Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) / (Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) Desc) As datatable Group By datatable.compuserid, YearWeek(datatable.DTE, 1) Order By datatable.YWK, Sum(datatable.PTS) / Sum(datatable.TOT) Desc) As groupedtable HAVING RNK <= 3
  6. On the surface, the top n per group query is a fairly common one and I have used a few variations on other projects. However, I really cannot get my head around this one and I think it is due to the number of joins. My query (at the bottom of the post) is trying to find the highest 3 scoring players per week. The score field is PPP. So, in theory, I am looking at grouping by week, then by player (to get the sum of his scores), find the 3 players with the highest PPP per week and them sort them by PPP desc along with, ideally, giving them a rank number. I know I would be able to do something that works with php but as I am sure doing it all in a query would be more server-friendly, I am determined to get this right.! The query below is not the only attempt I have had but it is the closest I have got to it working. The most often found solution LEFT OUTER JOIN table t2 ON (t1.id = t2.id AND t1.date < t2.date) did not come anywhere near working. The parts of the output are correct are the grouping by YearWeek and User and the sum of that users PPP. It also does correctly select 3 users from each week (as long as there are 3 available) but not the highest scoring 3 and not in correct rank order. So, in my head, I feel like I am close to getting it right but obviously may be a mile away! I have attached an SQL dump of the tables and data in case they will help. Thanks in advance for any suggestions. Steve THE QUERY Select x.PLYR, x.PPP, x.WST, x.WND, x.rank, x.YWK From (Select U.username PLYR, Sum(Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) PTS, Sum(Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) TOT, Sum(Case When P.home = G.hgoals And P.away = G.agoals Then 3 When (P.home > P.away And G.hgoals > G.agoals) Or (P.home < P.away And G.hgoals < G.agoals) Or (P.home <> G.hgoals And G.hgoals = G.agoals And P.home = P.away) Then 1 Else 0 End) / Sum(Case When P.home Is Not Null And P.away Is Not Null And G.hgoals Is Not Null And G.agoals Is Not Null Then 1 Else 0 End) PPP, Date_Add(G.date, Interval (0 - WeekDay(G.date)) Day) WST, Date_Add(G.date, Interval (6 - WeekDay(G.date)) Day) WND, Week(G.date) WK, CASE WHEN @currweek != YearWeek(G.date, 1) THEN @rank := 1 ELSE @rank := @rank + 1 END AS rank, @currweek := YearWeek(G.date, 1) YWK From compuser CU Inner Join comps C On C.compid = CU.comp Left Join users U On U.userid = CU.user Inner Join compgame CG On C.compid = CG.comp Inner Join games G On G.gamesid = CG.game Left Join predictions P On CU.user = P.user And CG.game = P.game JOIN (SELECT @rank := NULL, @currweek := '') r Where G.date < Now() Group By YearWeek(G.date, 1), U.userid Order By YearWeek(G.date, 1), PPP Desc) x Where x.rank <= 3 predssql.txt
  7. I have inherited a site which was designed only using 1 browser (I think) as a testing platform. As a result, the site looked completely different in a browsers and there were a lot of issues with elements appearing incorrectly and often covering other elements. Until I find the time to completely redesign it I have implemented a dirty fix in the form of a conditional statement based on browser detection. This has worked everywhere except on Android devices including Opera mini. Is there a way to detect it is an Android device and implement CSS based on that? EDIT: I forgot to mention, the layout is working fine on iPhones both through Safari and Google do am not looking to use any media screen conditions at this time. This is the way I will go eventually but currently it is just Android devices I need to accomodate. Thanks Steve
  8. Well spotted!! Sometimes I look too hard for a complicated problem when it is something straightforward! Thanks Steve
  9. I am having a problem getting an included file to read a session variable. I have done a similar set-up before and never encountered this sort of problem. Any references to it in the main page file work fine (so the session is being created correctly) but references in the included file are ignored. There is probable something simple I am missing but if anyone can spot it I would be grateful!! Steve Top of Main Page <?php session_start(); require_once('inc/cnct.php'); require_once('inc/config.php'); require_once($root.'/inc/constants.php'); $title = 'Home' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include ($includes."/commonhead.php"); ?> <title>Test Site</title> </head> <body> <?php if ($loggedin==1){echo '<b>LOGGED-IN!</b><br /><br />';} ?> <?php include ($includes."/header.php"); ?> <?php include ($includes."/menu.php"); ?> <div id="main"> <span class="tm_bottom"></span> <!-- Start Content --> <?php if ($loggedin==1){echo '<b>LOGGED-IN!</b><br /><br />';} ?> There are two different places on that page where I have put if ($loggedin==1){echo '<b>LOGGED-IN!</b><br /><br />'; (just for testing purposes) and they work correctly. However, when I try to use it in header.php the result is blank. Even echoing $loggedin or $_SESSION['loggedin'] comes up blank. header.php (in full) <div id="header"> <div id="site_title"> <a href="<?php echo $home ?>" target="<">This will be my tag line</a> </div> <!-- end of site_title --> <div id="header_right"> <?php echo 'Logged in: '.$_SESSION['user']; echo 'Logged In = '.$loggedin; ?> <div id="newsletter_box"> <nav> <ul> <li id="login"> <?php if ($loggedin==1) {echo '<b>LOGGED-IN!</b><br /><br />';} if ($loggedin==1) {echo ' Hello (<a href="/inc/logout.php">LOGOUT</a>)';} else {?><a id="login-trigger" href="#" class=""> Log in <span>▼</span> </a> <div id="login-content" style="display: none; "> <form action="/login/loginscript.php" method="post"> <fieldset id="inputs"> <input id="Username" type="" name="Username" placeholder="Your Username" required=""> <input id="Password" type="password" name="Password" placeholder="Password" required=""> </fieldset> <fieldset id="actions"> <input type="submit" id="submit" value="Log in"> <label><input type="checkbox" checked="checked" name="Remember"> Keep me signed in</label> </fieldset> </form> </div> </li> <li id="signup"> <a href="">Register</a> </li> </ul> </nav> <?php } ?> </div> </div> <div class="cleaner"></div> </div> <!-- end of header --> Login Script if(!empty($_POST['Username']) AND !empty($_POST['Password'])) {//Log-in Attempted so check against dbase //Set usable strings $username = mysql_escape_string($_POST['Username']); $password = mysql_escape_string(md5($_POST['Password'])); $remember = $_POST['Remember']; $users = "SELECT userid, username, password, active, level FROM users WHERE username like binary '".$username."' AND password='".$password."' AND active='1'"; $search = mysql_query($users) or die(mysql_error()); $match = mysql_num_rows($search); $level = mysql_fetch_assoc($search); if ($match==1)/*Checks for a match*/ {//Username and Password are correct, Log them in! //START MANUAL LOGIN & SET SESSION VARIABLES $_SESSION['user'] = $username; $_SESSION['level'] = $level['level']; $_SESSION['loggedin'] = '1'; $_SESSION['id'] = $level['userid']; $_SESSION['pass'] = $level['password']; if($remember==1) {//User has asked to be remembered so set cookies setcookie('username', $username, time()+60*60*24*365, "/"); setcookie('password', $password, time()+60*60*24*365, "/"); }//End set Cookies header( 'Location: template.php' ) ; }//End log-In Procedure constants.php <?php if($_SESSION['loggedin']==1){$loggedin='1';} else { if(isset($_COOKIE['username']) AND isset($_COOKIE['password'])) {// Cookies are set so check if they are still active $username = mysql_escape_string($_COOKIE['username']); $password = mysql_escape_string($_COOKIE['password']); $search = mysql_query(" SELECT userid, username, password, active, level FROM users WHERE username='".$username."' AND password='".$password."' AND active='1' ") or die(mysql_error()); $match = mysql_num_rows($search); $level = mysql_fetch_assoc($search); if($match > 0) //There are valid cookies so use that to log the user in {//START AUTO LOGIN & SET SESSION VARIABLES $_SESSION['user'] = $username; $_SESSION['level'] = $level['level']; $_SESSION['pass'] = $level['password']; $_SESSION['loggedin'] = '1'; $loggedin = '1'; $_SESSION['id'] = $level['userid']; }//END AUTO LOGIN } } ?>
  10. Thanks Guys. I have also also tried to design for mobile and then adapt it as the resolution grew but still cannot get it to 'switch' the order. I will have a look at the link Scott posted to see if I can glean anything out of that but given the inconsistency of the various version of ie ( about 8% of our visitors use IE7 ) this may be tougher than I thought without JS. Steve PS. @ignace - I had not seen the Web Developer Toolbar before but have now installed it. What a handy bit of kit!
  11. I am just starting to play around with responsive layouts and have got the hang of most things but one thing is stumping me. If I have a fluid width layout with fixed left and right columns and a fluid center, I am struggling to get it to work the way I want. Firstly the center column needs to fit the gap between left and right. I have no problems doing this if all 3 columns are fixed or all 3 are fluid but cannot get it to work with a mixture. As the layout gets smaller, I want one of the columns to move below the center one. Somtimes I might want the left one to stay in place and the right one to move under the center one but sometimes it might be the other way round. Finally, as the layout gets to mobile size I would want all 3 columns to be stacked. Once again I might way the stack to be left column on top, right column on bottom and center column in the middle but I might also want it so that center column is on top, left is on the bottom and right in the middle. Simply, I am trying to work out how to do every possible combination of 3 columns over all screen sizes! The code below is what I currently have. I have tried all sorts of combination of order of the divs in the html and floats in the css, as well as things like wrapping the center and right columns in their own container div, but never get it quite right. I would be greatful if anyone can point me in the right direction! CSS /* Mobile Layout: 480px and below. */ .gridContainer { margin-left: auto; margin-right: auto; width: 87.36%; padding-left: 1.82%; padding-right: 1.82%; background-color:#CCC; border:#000 1px solid; } #LayoutDiv1 { clear: both; width: 100%; display: block; border: #000 2px solid; width: 87.36%; min-height: 100px; margin: 0 auto; } #LayoutDivInnerLeft { display: none; } #LayoutDivInnerRight { float: right; margin-right: 0; width: 100%; display: block; background-color:#6FC; font-size:14px; } #LayoutDivInnerCenter { margin-left: 0; margin-right: 0; float:left; display: block; background-color:#fff; font-size:14px; } /* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */ @media only screen and (min-width: 481px) and (max-width: 768px) { .gridContainer { width: 90.675%; padding-left: 1.1625%; padding-right: 1.1625%; } #LayoutDiv1 { clear: both; width: 100%; display: block; border: #009 2px solid; background-color:#999; min-height: 100px; width: 90.675%; margin: 0 auto; } #LayoutDivInnerLeft { float: left; margin-left: 0; width: 200px; display: block; background-color:#6FC; font-size:10px; } #LayoutDivInnerRight { float: right; margin-right: 0; width: 200px; display: block; background-color:#6FC; font-size:14px; } #LayoutDivInnerCenter { margin-left: 210px; margin-right: 210px; float:left; display: block; background-color:#fff; font-size:14px; } } /* Desktop Layout: 769px to a max of 1232px. Inherits styles from: Mobile Layout and Tablet Layout. */ @media only screen and (min-width: 769px) { .gridContainer { width: 88.2%; max-width: 1232px; padding-left: 0.9%; padding-right: 0.9%; margin: auto; } #LayoutDiv1 { clear: both; margin-left: 0; width: 100%; display: block; background-color:#999; border: #ccc 2px solid; min-height: 100px; width: 88.2%; margin: 0 auto; overflow:hidden; } #LayoutDivInnerLeft { float: left; margin-left: 0; width: 200px; display: block; background-color:#6FC; font-size:14px; } #LayoutDivInnerRight { float: right; margin-right: 0; width: 200px; background-color:#6FC; font-size:14px; } #LayoutDivInnerCenter { margin-left: 210px; margin-right: 210px; background-color:#fff; font-size:14px; } } HTML <div class="gridContainer"> <div id="LayoutDivInnerLeft"><br /><br />Left<br /><br /></div> <div id="LayoutDivInnerRight"><br /><br />Right<br /><br /></div> <div id="LayoutDivInnerCenter">Center<br /><br /></div> <div style="clear:both"></div> </div> Thanks Steve PS. Do we have to do something different with the code tags these days? They do not seem to be formatting.
  12. Can I just say that when I created my first dynamic site just over two years ago I used Dreamweavers point and click coding for it because I thought I would never be able to learn to do it myself. Very quickly I realised it was full of limitations and over complicated code that taught me some very bad habits. On top of that, the templating system is awful and any changes meant I had to upload all pages again. Now, although by no means an expert, everything I do is hand coded in Notepad++. The end result is I understand the code because I wrote it myself (which has made debugging so much easier) and the way I have set up my template file (using php includes) means 99.9% of sitewide changes only take one file upload. If I can learn to hand code dynamic sites ANYONE CAN!!!
  13. That is actually the way it is working at the moment. It is ok ish that way but I would really like all items to be equal height. Also, as the site evolves, there may be sub menus that have 3/4/5 items that will span over two lines so there is the risk of the menu looking messily long.
  14. I have been banging my head against a brick wall searching to see if what I am trying to achieve is actually possible before I start looking at any code. If anyone can advise I would be gratefull!! I use a php script to pull my navigation items out of a database which gives me the following <ul> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a></li> <li><a href="#">Parent</a> <ul> <li><a href="#">Child 1</a></li> <li><a href="#">Child 2</a> <ul> <li><a href="#">2nd Child 1</a></li> <li><a href="#">2nd Child 2</a></li> <li><a href="#">2nd Child 3</a></li> <li><a href="#">2nd Child 4</a></li> </ul> </li> <li><a href="#">Child 3</a></li> <li><a href="#">Child 4</a></li> </ul> </li> <li><a href="#">Menu 3</a></li> .. </ul> My CSS skills are enough to style it adequately but there are a couple of things I want it to do... Firstly (and probably easiestly) all sub menu items are fixed with. I would like the width to adjust to the longest item in that sub-menu. I have no idea, over time, how long the longest item is going to be so any fixed-width I use may eventually not be large enough. Also, if a sub-menu only has items of 4 characters, it looks stupid having them in a 200px <li>. I have tried a few combinations of setting the width to auto and text to nowrap on both the <ul> and <li> but nothing has worked. The second thing I want to do is to have the menu's open with one tap on mobile devices. Once again I had found some examples of this but I also want the parent items to be links, activated by a second tap. I am pretty sure I stumbled across a CSS only method for this a while back (when I wasn't actually looking for it!) but all I can find now are JavaScript solutions. Thanks in advance for any advice. Steve
  15. Thanks guys. That is exactly the sort of thing I was after.
  16. Well, that opened an unexpectedly large can of worms!! When posting, I thought the response would be a unanimous 'this is the correct way to do it....'! I have read through and although a lot of it has gone over my head, it has given me food for thought for the future and different ways of doing things. However, for this moment I just wanted to clarify what I am trying to achieve as I think the actual purpose of the post has got lost or mis-understood at times, why I am trying to do it as one of the responses appeared question why I would offer 3 styles and finally, what I have done so far. I haven't changed anything to my original code so everything is what I had before my original post. So......... The suggestion of 3 styles isn't the definite number that I will offer. I just used that as it would give an idea to the complexity (in my head) of offering 3. Having said that, I do not think it would be unusual to offer 3. A survey of site users has suggested that some would like a feature-rich and graphically-enhanced landing page, featuring snippets of as much of the different parts of the site as possible, much like a portal page. This could include a slide show at the top or a section with scrolling content. It may also be that the navigation used on this version is more advanced. On the flip side, some people would want the landing page to be no more than a list of the latest news, leaving them to navigate to the other pages if they want to see any other content. The people who preferred this, also prefer a simpler looking page with clear content and no frills. Also, this version would be more suitable for anyone accessing the site on the move. This is no different to the HI-FI and LO-FI versions seen on many forums and CMS's. The 3rd version is one designed to be viewed on mobile devices and may have vastly stripped down versions of the content. The actual switching between styles is not a problem and I already have that working. Basically I have an xxx/styles folder. In that, currently is 3 more folders, 'V1', 'V2' and 'V3'. In each of these there are 4 different files.... base.css - the main css file for that style head.php - this is to hold and scripts or other <head> elements that are specific to that style only. I do have a separate shared head file for code that is common for all versions. top.php and bottom.php - these are to wrap the style around the content and will mean that any changes to the template will only need one file changed and uploaded rather than every page. A dumbed down version of the page code is... <?php ob_start();session_start(); require_once('xxxxx/constants.php'); $title = "MySite | Welcome"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <?php include($style.'/shared/sharedhead.php'); include($style.$this_style."/head.php");?> </head> <body><?php include($top); ?> <div class="page_title">Welcome to My Page</div> <!--START CONTENT--> CONTENT GOES HERE <!--END CONTENT--> <?php include($bottom); ?></body> </html> <? ob_flush(); ?> This means that the only code edited in the actual page is the code relevant to that page. In the constants.php file I have $style = path.to.'styles/'; #CHECK FOR STYLE COOKIES if (isset($_COOKIE["style"])) {$this_style = ''.$_COOKIE["style"].'';} else {$this_style = 'v1';} #FIND THE CORRECT TOP AND BOTTOM PAGES $top = $style.$this_style."/top.php"; $bottom = $style.$this_style."/bottom.php"; In the pages (not shown in my code above) I have a style chooser which on submits accesses a page with the following code <?php $goback=$_GET['ref']; //$_GET['ref'] is sent with the form as $_SERVER['PHP_SELF'] $choice=$_POST['stylechoice']; $yr =31536000 + time(); setcookie ('style', $choice, $yr, '/'); header("Location: ".$_GET['ref'].""); ?> This is where I am up to and at this point everything works as well as I had hoped. The switch is literally a split second (albeit with no content on the page) even on my phone's mobile network and as far as the styles are concerned, my css is adequate enough to make something that appears on the left in one style appear on the right in another and manipulate the way everything looks in each different one. The actual switching of styles was not part of my original question but as that is where a lot of the discussion has been focused I thought I would include it now. However, I am happy with the way it is working and unless anyone can convince me that there is a more efficient way using php and css, I am more than happy to leave this part as it is. My question is how to handle the fact that there would be both shared and unique content in each style and I want to know how best to do that. For example (and these are unlikely but just using as examples) there may be a twitter feed showing on the first two but not on the mobile one, a featured content slider that only features on the first one and a latest news section that appears on all three. Similarly, if I am pulling data into a html table with 10 columns, I might want to show all columns on the desktop version but only 5 on the mobile one. The approaches I thought of were (in psuedo code)... PUT THE ENTIRE CODE FOR EACH VERSION IN AN IF...ELSEIF STATEMENT if ($style=V1) {SHOW CONTENT SLIDER SHOW LATEST NEWS SHOW TWITTER FEED} else if ($style=V2) {SHOW LATEST NEWS SHOW TWITTER FEED} else if ($style=V3) {SHOW LATEST NEWS} //and so on The downside I see with this is that the code for the Twitter feed is shown twice and the latest news is shown 3 times. However someone did mention using functions for the duplicated code. USE SEPARATE IF STATEMENTS IN THE PAGE <?php if($style=V1){SHOW CONTENT SLIDER} ?> SHOW LATEST NEWS <?php if($style=V1 or V2){SHOW TWITTER FEED} ?> this would mean all the code is included in the page once and only called if it is the correct style USE CSS TO SHOW HIDE CONTENT Once again, this has all the code in there once but instead if using if statements to decide whether or not to show it, it will be decided by using the relevant style sheet to show or hide a particular container. In my head they all seem adequate solutions, although I think the CSS only one might be harder for me to implement. What I would like to know is which of these methods would be the best option. Or if there is a better option using php/css/html feel free to point me in the right direction. That was a mission and time for bed!! Thanks for all the thought that has been put in to the discussion so far. I have got this thread bookmarked so when, in the future, I find time to learn Javascript (I would love to be at a stage to be able to utilise Ajax/jQuery but that is a long way off) I have got an interesting starting point for the pro's and cons. Thanks again Steve
  17. Thanks for the responses. I will rule out the JavaScript approach for now, simply because I am still on my php learning curve and really haven't got the spare time to start learning another language. It is something I want to explore at sometime, mainly to add additional rows to tables that populate form dropdowns on the fly. I think the suggestion of the multiple if....elseif using functions for the shared code will be the route I go down at this moment, unless anyone can convince me that there is a better/faster/more server friendly way using php/CSS. Thanks again Steve
  18. I had seen that before and had a browse through but I don't think it covers what I am trying to do. Say for example I want 3 designs... 1. Desktop version which contains the title and content for 10 news items. 2. Desktop version which has a slideshow at the top and the title only for 5 news items 3. Mobile version which has the title for 10 news items Obviously this is not a great example but it is the best way I can explain at the moment. Each of these pages will also have shared elements. The way I see it there are 3 options... Have all elements for all 3 designs only once in the code and use CSS to either show or hide them depending on the style chosen. Use an if...elseif statement and have all the required code (including shared parts) at each step. This would obviously mean shared code is in the page 3 times. Use individual if.. Statements in the relevant parts of the page to only show that part of the content if you are in the correct style. This is only going to affect the front page so I don't have any concerns at this moment about it causing any long-term complications. Thanks
  19. I am currently redesigning a site and am looking at introducing a style switcher to offer two or three varieties. This in itself is not a problem and I already have a script which will call the correct css, top and bottom files depending on selection. The front page is intended to vary greatly between styles and each style will have something the other doesn't. With this in mind my thought is to have all the variations coded into the one page and only show the content relevant to that style using a series of if...else's with the HTML in between each. Obviously this will mean the actual code on the page is quite heavy but am I correct in thinking that only the relevant section would be pulled so it would not have any impact on speed or performance? Thanks Steve
  20. The way I do it is if home_goals = null, it is still classed as a fixture. However, I was recently told on phpfreaks that I should have the goals in a separate table. Steve
  21. Hi shedcade Purely out of curiosity, what is '== $imageleader['LINK']' referencing? The only reason I ask is I created a Current Form table (http://www.margate-fc.com/content/1st_team/cform.php?season_id=105), as well as standard, home and away tables and a stack of other football stats, for a site a couple of years back and am just about to start a rewrite of the entire code, so wondered if it is anything that I can use to improve my functionality. If there is anything else football stat related that you are looking to do, I might, be able to help. I am no php genius but as a lot of what I have done has come from advice on here, it can't be too bad!!! Thanks Steve
  22. Personally I use sessions but also offer the user the chance have the site log them in automatically on each visit using cookies. There have been a few rules come in in the UK recently about the use of cookies but I am not sure how far down the developer chain they apply. Steve
  23. My understanding was that was self-generated from the data passed to the page (the form field upload[]). This was how I was told to do it ages ago, when I first started out and it has worked that way since so hadn't questioned it. However, looking at it afresh, it is clear that it is redundant as the form would not be defining $i so I have had a bit more of a read up and could see where I think was going wrong. I have rewritten the first part of the code and $i is replaced by $key which, I believe is defined in the foreach statement. However, I must still have it wrong as I am getting exactly the same result..files upload fine until one errors and then all error. if (isset($_FILES['upload'])) { //Convert the files into an info array $files=array(); $filedata=$_FILES['upload']; if(is_array($filedata['tmp_name'])){ foreach ($filedata['name'] as $key => $file){ $files[$key]=array( 'name' =>$filedata['name'][$key], 'type' => $filedata['type'][$key], 'tmp_name'=>$filedata['tmp_name'][$key], 'error' => $filedata['error'][$key], 'size' => $filedata['size'][$key] ); $errormsg = ''; list($width, $height, $type, $attr) = getimagesize($_FILES['upload']['tmp_name'][$key]); //from this point code is unchanged
  24. Oops. That is my novice incompetence showing through! I believe it should be if(is_array($filedata['name'])){ $files[$i]=array( which I have now change. However, the outcome is still the same. As it goes through the files, it uploads each one but as soon as it finds an error, everything else fails to upload. Thanks Steve
  25. I have worked out what the problem is but am not sure if there is a solution. The images are being selected via a multipart form so the checks are being made during the upload to the temp folder. So as soon as one fails, the entire upload stops. Is there a way to carry on with the rest of the uploads if any of them fail? Thanks Steve
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.