Jump to content

samtwilliams

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by samtwilliams

  1. thanks, solved by if($valid_file) { //move it to where we want it to be $target_path = "/home/sites/xxxxxx.co.uk/public_html/yourphotos/uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); move_uploaded_file($_FILES['photo']['tmp_name'], $target_path); $message = 'Congratulations! Your file was accepted.'; }
  2. Hi All, I have this issue when upload a file using an uploader i made. For the life of me I cant figure out why it won't write the file. Error: [Sat Jun 21 20:45:40 2014] [error] [client xxxxxxx] AH01215: PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpUsCyXG' to '/home/sites/xxxxxx.co.uk/public_html/yourphotos/uploads/' in /home/sites/xxxxxxx.co.uk/public_html/yourphotos/index.php on line 31 My PHP <?php //if they DID upload a file... $message = ''; if($_FILES['photo']['name']) { $valid_file = true; //if no errors... if(!$_FILES['photo']['error']) { //now is the time to modify the future file name and validate the file $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file if($_FILES['photo']['size'] > (26214400)) //can't be larger than 25MB { $valid_file = false; $message = 'Oops! Your file\'s size is to large.'; echo $_FILES['photo']['size']; } if($_FILES['photo']['size'] < (1572864)) //can't be smaller than 1.5MB { $valid_file = false; $message = 'Oops! Your file\'s size is to small.'; echo $_FILES['photo']['size']; } //if the file has passed the test if($valid_file) { //move it to where we want it to be move_uploaded_file($_FILES['photo']['tmp_name'], '/home/sites/xxxxxxxx.co.uk/public_html/yourphotos/uploads/'); $message = 'Congratulations! Your file was accepted.'; } } //if there is an error... else { //set that to be the returned message $message = 'Ooops! Your upload triggered the following error: '.$_FILES['photo']['error']; } } ?> <html> <body> <form action="index.php" method="post" enctype="multipart/form-data"> Your Photo: <input type="file" name="photo" size="25" /> <input type="submit" name="submit" value="Submit" /> <?PHP echo $message; ?> </form> </body> </html> I have set the uploads file to have write permissions as well. Sam
  3. I need to use tables, still can't get it to work, my table just looks a mess.
  4. I am trying to draw a table dynamically, I need a table that is 5 x 5, i know i'm close quite my code by just can't quite fathom it out. My sql returns 25 results which i want to return 25 cells in a square table. <?PHP $i = 0; while($row = mysql_fetch_assoc($result)) { $i++; ?> <?PHP if($i== 5) { echo '<tr>'; } ?> <td class="right bottom"><?PHP echo $row['GridID']; ?></td> <td class="right bottom"> </td> <td class="right bottom"> </td> <td class="right bottom"> </td> <td class="bottom"> </td> <?PHP if($i== 5) { echo '</tr>'; $i=0; } ?>
  5. I need to selected the subscriber_Id from another tabled based on an email address, can't seem to work out why this nested select won't work. Can someone help Thanks Sam INSERT INTO `pommo_subscriber_data` ( `data_id` , `field_id` , `subscriber_id` , `value` ) VALUES ( NULL , '1', (SELECT `pommo_subscribers`.`subscriber_id` FROM `pommo_subscribers` WHERE `pommo_subscribers`.`email` = 'samtwilliams23'ORDER BY `pommo_subscribers`.`subscriber_id` DESC), 'SamTEST');
  6. Hello All, Just working with PHP's snap v1 functions I can use snmpget fine but snmpset produces the following error; Warning: snmpset() [function.snmpset]: No response from 192..... Code <?PHP echo 'File started <br />'; $ip = '192.168.1.100'; echo 'Read:<br />'; $sysdescr = snmpget($ip, 'public', '.1.3.6.1.4.1.17095.3.4.0', 300); echo $sysdescr; echo 'Write Started:<br />'; snmpset("$ip", 'public', '.1.3.6.1.4.1.17095.4.7.2.0', 's', 'sam@samtwilliams.co.uk', 300); ?> Like i said the get works fine just the set does not. Does anyone have any ideas? Sam
  7. Sorry thats not meant to be there its where i tried to highlight it for forum users. Sam
  8. Hi All, I am currently developing a PHP serial application and require some help with a serial read problem on windows. I am using the following class which has been developed by someone else but provides a fantastic base in which to start, i have made some modifications already and i can send data to a serial(com) port fine with no problems, the problem comes when trying to read data. It seems that when I call the function it does not obtain any data at all. My Call for reading data; $read = $serial->readPort(); echo $read; The whole code; <?php define ("SERIAL_DEVICE_NOTSET", 0); define ("SERIAL_DEVICE_SET", 1); define ("SERIAL_DEVICE_OPENED", 2); /** * Serial port control class * * THIS PROGRAM COMES WITH ABSOLUTELY NO WARANTIES ! * USE IT AT YOUR OWN RISKS ! * * Changes added by Rizwan Kassim <rizwank@uwink.com> for OSX functionality * default serial device for osx devices is /dev/tty.serial for machines with a built in serial device * * @author Rémy Sanchez <thenux@gmail.com> * @thanks Aurélien Derouineau for finding how to open serial ports with windows * @thanks Alec Avedisyan for help and testing with reading * @copyright under GPL 2 licence */ class phpSerial { var $_device = null; var $_windevice = null; var $_dHandle = null; var $_dState = SERIAL_DEVICE_NOTSET; var $_buffer = ""; var $_os = ""; /** * This var says if buffer should be flushed by sendMessage (true) or manualy (false) * * @var bool */ var $autoflush = true; /** * Constructor. Perform some checks about the OS and setserial * * @return phpSerial */ function phpSerial () { setlocale(LC_ALL, "en_US"); $sysname = php_uname(); if (substr($sysname, 0, 5) === "Linux") { $this->_os = "linux"; if($this->_exec("stty --version") === 0) { register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("No stty availible, unable to run.", E_USER_ERROR); } } elseif (substr($sysname, 0, 6) === "Darwin") { $this->_os = "osx"; // We know stty is available in Darwin. // stty returns 1 when run from php, because "stty: stdin isn't a // terminal" // skip this check // if($this->_exec("stty") === 0) // { register_shutdown_function(array($this, "deviceClose")); // } // else // { // trigger_error("No stty availible, unable to run.", E_USER_ERROR); // } } elseif(substr($sysname, 0, 7) === "Windows") { $this->_os = "windows"; register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("Host OS is neither osx, linux nor windows, unable tu run.", E_USER_ERROR); exit(); } } // // OPEN/CLOSE DEVICE SECTION -- {START} // /** * Device set function : used to set the device name/address. * -> linux : use the device address, like /dev/ttyS0 * -> osx : use the device address, like /dev/tty.serial * -> windows : use the COMxx device name, like COM1 (can also be used * with linux) * * @param string $device the name of the device to be used * @return bool */ function deviceSet ($device) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { if ($this->_os === "linux") { if (preg_match("@^COM(\d+):?$@i", $device, $matches)) { $device = "/dev/ttyS" . ($matches[1] - 1); } if ($this->_exec("stty -F " . $device) === 0) { $this->_device = $device; $this->_dState = SERIAL_DEVICE_SET; return true; } } elseif ($this->_os === "osx") { if ($this->_exec("stty -f " . $device) === 0) { $this->_device = $device; $this->_dState = SERIAL_DEVICE_SET; return true; } } elseif ($this->_os === "windows") { if (preg_match("@^COM(\d+):?$@i", $device, $matches) and $this->_exec(exec("mode " . $device . " xon=on BAUD=9600")) === 0) { $this->_windevice = "COM" . $matches[1]; $this->_device = "\\.\com" . $matches[1]; $this->_dState = SERIAL_DEVICE_SET; return true; } } trigger_error("Specified serial port is not valid", E_USER_WARNING); return false; } else { trigger_error("You must close your device before to set an other one", E_USER_WARNING); return false; } } /** * Opens the device for reading and/or writing. * * @param string $mode Opening mode : same parameter as fopen() * @return bool */ function deviceOpen ($mode = "r+b") { if ($this->_dState === SERIAL_DEVICE_OPENED) { trigger_error("The device is already opened", E_USER_NOTICE); return true; } if ($this->_dState === SERIAL_DEVICE_NOTSET) { trigger_error("The device must be set before to be open", E_USER_WARNING); return false; } if (!preg_match("@^[raw]\+?b?$@", $mode)) { trigger_error("Invalid opening mode : ".$mode.". Use fopen() modes.", E_USER_WARNING); return false; } $this->_dHandle = @fopen($this->_device, $mode); if ($this->_dHandle !== false) { stream_set_blocking($this->_dHandle, 0); $this->_dState = SERIAL_DEVICE_OPENED; return true; } $this->_dHandle = null; trigger_error("Unable to open the device", E_USER_WARNING); return false; } /** * Closes the device * * @return bool */ function deviceClose () { if ($this->_dState !== SERIAL_DEVICE_OPENED) { return true; } if (fclose($this->_dHandle)) { $this->_dHandle = null; $this->_dState = SERIAL_DEVICE_SET; return true; } trigger_error("Unable to close the device", E_USER_ERROR); return false; } // // OPEN/CLOSE DEVICE SECTION -- {STOP} // // // CONFIGURE SECTION -- {START} // /** * Configure the Baud Rate * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400, * 57600 and 115200. * * @param int $rate the rate to set the port in * @return bool */ function confBaudRate ($rate) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the baud rate : the device is either not set or opened", E_USER_WARNING); return false; } $validBauds = array ( 110 => 11, 150 => 15, 300 => 30, 600 => 60, 1200 => 12, 2400 => 24, 4800 => 48, 9600 => 96, 19200 => 19, 38400 => 38400, 57600 => 57600, 115200 => 115200 ); if (isset($validBauds[$rate])) { if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (int) $rate, $out); } if ($this->_os === "darwin") { $ret = $this->_exec("stty -f " . $this->_device . " " . (int) $rate, $out); } elseif ($this->_os === "windows") { $ret = $this->_exec("mode " . $this->_windevice . " BAUD=" . $validBauds[$rate], $out); } else return false; if ($ret !== 0) { trigger_error ("Unable to set baud rate: " . $out[1], E_USER_WARNING); return false; } } } /** * Configure parity. * Modes : odd, even, none * * @param string $parity one of the modes * @return bool */ function confParity ($parity) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set parity : the device is either not set or opened", E_USER_WARNING); return false; } $args = array( "none" => "-parenb", "odd" => "parenb parodd", "even" => "parenb -parodd", ); if (!isset($args[$parity])) { trigger_error("Parity mode not supported", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . $args[$parity], $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " PARITY=" . $parity{0}, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set parity : " . $out[1], E_USER_WARNING); return false; } /** * Sets the length of a character. * * @param int $int length of a character (5 <= length <= * @return bool */ function confCharacterLength ($int) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set length of a character : the device is either not set or opened", E_USER_WARNING); return false; } $int = (int) $int; if ($int < 5) $int = 5; elseif ($int > $int = 8; if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " cs" . $int, $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " DATA=" . $int, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set character length : " .$out[1], E_USER_WARNING); return false; } /** * Sets the length of stop bits. * * @param float $length the length of a stop bit. It must be either 1, * 1.5 or 2. 1.5 is not supported under linux and on some computers. * @return bool */ function confStopBits ($length) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the length of a stop bit : the device is either not set or opened", E_USER_WARNING); return false; } if ($length != 1 and $length != 2 and $length != 1.5 and !($length == 1.5 and $this->_os === "linux")) { trigger_error("Specified stop bit length is invalid", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (($length == 1) ? "-" : "") . "cstopb", $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " STOP=" . $length, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set stop bit length : " . $out[1], E_USER_WARNING); return false; } /** * Configures the flow control * * @param string $mode Set the flow control mode. Availible modes : * -> "none" : no flow control * -> "rts/cts" : use RTS/CTS handshaking * -> "xon/xoff" : use XON/XOFF protocol * @return bool */ function confFlowControl ($mode) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set flow control mode : the device is either not set or opened", E_USER_WARNING); return false; } $linuxModes = array( "none" => "clocal -crtscts -ixon -ixoff", "rts/cts" => "-clocal crtscts -ixon -ixoff", "xon/xoff" => "-clocal -crtscts ixon ixoff" ); $windowsModes = array( "none" => "xon=off octs=off rts=on", "rts/cts" => "xon=off octs=on rts=hs", "xon/xoff" => "xon=on octs=off rts=on", ); if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff") { trigger_error("Invalid flow control mode specified", E_USER_ERROR); return false; } if ($this->_os === "linux") $ret = $this->_exec("stty -F " . $this->_device . " " . $linuxModes[$mode], $out); else $ret = $this->_exec("mode " . $this->_windevice . " " . $windowsModes[$mode], $out); if ($ret === 0) return true; else { trigger_error("Unable to set flow control : " . $out[1], E_USER_ERROR); return false; } } /** * Sets a setserial parameter (cf man setserial) * NO MORE USEFUL ! * -> No longer supported * -> Only use it if you need it * * @param string $param parameter name * @param string $arg parameter value * @return bool */ function setSetserialFlag ($param, $arg = "") { if (!$this->_ckOpened()) return false; $return = exec ("setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1"); if ($return{0} === "I") { trigger_error("setserial: Invalid flag", E_USER_WARNING); return false; } elseif ($return{0} === "/") { trigger_error("setserial: Error with device file", E_USER_WARNING); return false; } else { return true; } } // // CONFIGURE SECTION -- {STOP} // // // I/O SECTION -- {START} // /** * Sends a string to the device * * @param string $str string to be sent to the device * @param float $waitForReply time to wait for the reply (in seconds) */ function sendMessage ($str, $waitForReply = 0.1) { $this->_buffer .= $str; if ($this->autoflush === true) $this->serialflush(); usleep((int) ($waitForReply * 1000000)); } /** * Reads the port until no new datas are availible, then return the content. * * @pararm int $count number of characters to be read (will stop before * if less characters are in the buffer) * @return string */ function readPort ($count = 0) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened to read it", E_USER_WARNING); return false; } if ($this->_os === "linux" || $this->_os === "osx") { // Behavior in OSX isn't to wait for new data to recover, but just grabs what's there! // Doesn't always work perfectly for me in OSX $content = ""; $i = 0; if ($count !== 0) { do { if ($i > $count) $content .= fread($this->_dHandle, ($count - $i)); else $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } else { do { $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } return $content; } [color=gred]elseif ($this->_os === "windows") { $content = ""; if ($count > 0) { $content = fread($this->_dHandle, $count); } return $content; }[/color] return false; } /** * Flushes the output buffer * Renamed from flush for osx compat. issues * * @return bool */ function serialflush () { if (!$this->_ckOpened()) return false; if (fwrite($this->_dHandle, $this->_buffer) !== false) { $this->_buffer = ""; return true; } else { $this->_buffer = ""; trigger_error("Error while sending message", E_USER_WARNING); return false; } } // // I/O SECTION -- {STOP} // // // INTERNAL TOOLKIT -- {START} // function _ckOpened() { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened", E_USER_WARNING); return false; } return true; } function _ckClosed() { if ($this->_dState !== SERIAL_DEVICE_CLOSED) { trigger_error("Device must be closed", E_USER_WARNING); return false; } return true; } function _exec($cmd, &$out = null) { $desc = array( 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $proc = proc_open($cmd, $desc, $pipes); $ret = stream_get_contents($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $retVal = proc_close($proc); if (func_num_args() == 2) $out = array($ret, $err); return $retVal; } // // INTERNAL TOOLKIT -- {STOP} // } ?> Problem area;
  9. Hi all, Does anyone know of an effective way of find out whether a user is still logged in and they haven't left? Sam
  10. Maybe one way would be to reset the session_save path and parse the contents of those files?
  11. Morning(at least for me anyway) All, I am currently integrating a facebook/style chat system into my webpage. I am going to build the active user list myself but need a little guidance on how to list my users which are online and how to detect when the have gone. When my users login i store only their userid in a session like many login systems. When they login i could simply add their name to a active_users table, but how would i detect whether they are still alive? Any help would be great. Thanks Sam
  12. Afternoon All, I can't seem to work this problem out; I have a form that is generated from a sql list and have two inputs as follows; <input type="text" name="suppliernumber[]" id="suppliernumber[]" /> <input name="snomed[]" type="checkbox" id="snomed[]" value="<?php echo $row['VPPID']; ?>" /> Both are fed to my processing files as arrays, i then run the following foreach which uses the VPPID from the post to search in a database using a where clause. The problem comes when i also need to obtain the data from the suppliernumber $_POST if any has been supplied. My php code; foreach ($_POST['snomed'] as $value) { $getRecord_sql = "SELECT vmps.NM AS NM, vmpps.QTYVAL AS QTYVAL, bnf_lookup_subcatagory.BNF_SUBCAT AS BNF_SUBCAT, bnf_lookup_catagory.BNF_CAT AS BNF_CAT FROM bnf_lookup_catagory INNER JOIN bnf_vmp ON bnf_lookup_catagory.BNF_CAT = bnf_vmp.BNF_CAT INNER JOIN bnf_lookup_subcatagory ON bnf_vmp.BNF_SUBCAT = bnf_lookup_subcatagory.BNF_SUBCAT RIGHT OUTER JOIN vmps INNER JOIN vmpps ON vmps.VPID = vmpps.VPID ON bnf_vmp.VPID = vmpps.VPID WHERE VMPPS.VPPID = '$value'"; $getRecord = mssql_query($getRecord_sql); $row = mssql_fetch_array($getRecord); $nm = $row['NM']; $qtyval = $row['QTYVAL']; $BNF_SUBCAT = $row['BNF_SUBCAT']; $BNF_CAT = $row['BNF_CAT']; $SUPPLIER = $_POST['suppliernumber']; array_push($data_array, array($value, $nm, $BNF_CAT, $BNF_SUBCAT, '', $SUPPLIER, '', '1', '', '', '', '', '', '', '', '1', '', '', $qtyval)); } I can't work out how to add the suppliernumber, i know i need another foreach but can't work out how to do it. Hope someone can help. Sam
  13. Sorted, additional AND. Thanks Keith. Sam
  14. Hi Keith, Thanks for your reply, have had a tinker but can not get rid of this error.
  15. Build your table on your localhost and then use the export function to grab the SQL code then just simply execute it on your new server. I suggest you have a read on the basics of mysql first, heres a great resource: http://www.tizag.com/mysqlTutorial/ Sam
  16. Hi All, I have a problem that i can't solve with a right join. I have a members access system which comprises of two tables PageLevels and UserPages. My PageLevels consists of all possible pages in my site and the other lists the ones a particular user has access too. I am now creating my user editing page and need to list ALL pages in my site and apply a checkbox for those the member has access to. The problem comes when I join my tables and apply my WHERE clause (WHERE UserPages.uid = 1) which causes it to show only those pages a member has access to rather than all. My tables: My Query Now if i run my query on this i expect it to show result set like I know it has something to do with running the WHERE on the JOINED table but I am now at a loss on how to get this to work. Anyone have any ideas? Thanks Sam
  17. Try this; <?PHP if ($_POST['user'] == 'admin' && $_POST['pass'] == '1234') { echo "fail"; } else { echo "win"; }?>
  18. Hi All, I have written the following to validate my dynamic includes, one question is i will be using sessions to control user access to certain pages. Obviously the session_start() has to go into my index.php file. Can anyone see any problems with this or my dynamic include validation code. My page varilable is populated using the mod_rewirte function in appache. <?PHP include('inc/settings.inc.php'); if(isset($_GET['page'])) { //remove slashes $page = stripslashes($_GET['page']); //rebuild the extension and file name $filename = 'lib/'.$page.'.php'; //Check to see if the file exists in lib if (file_exists($filename)) { //Dynamic Switch $allowed = array( array("test", "New Customers"), array("home", "Home Page"), ); $iffed = false; $get_section = $_GET['page']; //Create a dynamic switch to check for files being in my allowed array foreach($allowed as $rd) { if($get_section == $rd[0]) { $iffed = $rd; $content = $filename; foreach($rd as $value) { $page_title = $value; } } } if($iffed === false) { //File is not in my include list. die( "Page does not pass the validated inclusion list." ); } } else { //Page does not exist in my lib folder. die('Page does not exist, please contact the administrator.'); } } else { // If no page is requested then default home. $filename = 'lib/home.php'; $content = '1'; $page_title = 'Home'; } ?> Thanks in advance. Sam
  19. Thanks for your reply phpchamps, I have looked at this example already, the only difference is that i am not summing or counting anything, i just want to list the result under each week. I now have this which i think is close but still only returning the first result when a lot of players have played in all weeks it just lists the first result in the first week. select winter_league_rnds.wl_id AS WLID, winter_league.forename, winter_league.surname, CASE WHEN week=1 THEN (SELECT result FROM winter_league_rnds WHERE week = 1 AND winter_league_rnds.wl_id = WLID) ELSE ' ' END AS WEEK1, CASE WHEN week=2 THEN (SELECT result FROM winter_league_rnds WHERE week = 2 AND winter_league_rnds.wl_id = WLID) ELSE ' ' END AS WEEK2, CASE WHEN week=3 THEN (SELECT result FROM winter_league_rnds WHERE week = 3 AND winter_league_rnds.wl_id = WLID) ELSE ' ' END AS WEEK3 from winter_league_rnds LEFT JOIN (winter_league) ON (winter_league.wl_id = winter_league_rnds.wl_id) group by WLID ORDER BY surname ASC LIMIT 155 Sam
  20. Hi Zanus, It has to stay as two decimal places as prizes are awarded to joints (strange I know as i originally coded it to perform that way). Percentages are stored in the table as they are calculated monthly rather than on the fly. Table structure as follows; wl_id forename surname win draw loss played percentage note datetime_created percentage is a float to two decimal places. Sam
  21. I have now got a little further except in the pivot it only displays one result when it should be displaying a result under each week; select winter_league_rnds.wl_id, winter_league.forename, winter_league.surname, case when week='1' then result else ' ' end as WEEK1, case when week='2' then result else ' ' end as WEEK2, case when week='3' then result else ' ' end as WEEK3, case when week='4' then result else ' ' end as WEEK4, case when week='5' then result else ' ' end as WEEK5, case when week='6' then result else ' ' end as WEEK6, case when week='7' then result else ' ' end as WEEK7, case when week='8' then result else ' ' end as WEEK8, case when week='9' then result else ' ' end as WEEK9, case when week='10' then result else ' ' end as WEEK10, case when week='11' then result else ' ' end as WEEK11, case when week='12' then result else ' ' end as WEEK12, case when week='13' then result else ' ' end as WEEK13, case when week='14' then result else ' ' end as WEEK14, case when week='15' then result else ' ' end as WEEK15, case when week='16' then result else ' ' end as WEEK16, case when week='17' then result else ' ' end as WEEK17, case when week='18' then result else ' ' end as WEEK18, case when week='19' then result else ' ' end as WEEK19, case when week='20' then result else ' ' end as WEEK20 from winter_league_rnds LEFT JOIN (winter_league) ON (winter_league.wl_id = winter_league_rnds.wl_id) group by wl_id ORDER BY surname ASC
  22. Hi All, Some assistance required if possible , i have designed a database in which results of golf are kept. The position in which people appear within the table depend on a percentage of games won, lost or drawn. I then display the results ordered by % which gives me a leader table. The problem comes when I am ranking each players position. It's easy to do if each player has a different percentage but when more than one player is exactly the same I want to rank them the same. Example below. The question is how i achieve a ranking like that which will rank duplicates the same and then carry on after in numbered order. My results a retrieved from my database using this query; $query_board = "SELECT * FROM winter_league WHERE played >= $to_qualify ORDER BY winter_league.percentage DESC, played DESC, win DESC, draw DESC, loss DESC, surname ASC"; $result_board = mysql_query($query_board); then displayed in a table like this; <?PHP while ($row_board = mysql_fetch_assoc($result_board)){ ?> <tr> <td height="25"><?PHP echo $row_board['forename'].' '.$row_board['surname']; ?></td> <td class="align_columns"><?PHP echo $row_board['played']; ?></td> <td class="align_columns"><?PHP echo $row_board['win']; ?></td> <td class="align_columns"><?PHP echo $row_board['draw']; ?></td> <td class="align_columns"><?PHP echo $row_board['loss']; ?></td> <td align="right" class="align_columns"><?PHP echo $row_board['percentage']; ?>%</td> </tr> <?PHP } ?> Any Help would be most appreciated. Thanks in advance. Sam
  23. Hi all, I have two tables which i have joined but i want to pivot the data in one table, example below. Current table1; wl_id|forename|surname 7|Sam|Williams Current table2 (the one i need to pivot); wl_id|result|week_number 7|win|1 7|win|2 7|loss|3 7|half|4 7|win|5 I would like to display all the data like this wl_id|forename|surname|1|2|3|4|5 7|Sam|Williams|win|win|loss|half|win The number being the week_number. Can anyone provide me an example? Sam
  24. Hi, Sorry i forgot to say i am storing the win data as decimal already, i plan to use the order by clause but i want the php to add the rank numbers on as the page is generated. but i want it to show liek the example dataset above. Sam
  25. Hello All, I am trying to plan a project in which a leader board will be generated from a set of results within a SQL database. The only thing that I am unsure about is when I list the results I want them in order of win rate (which will be a percentage) and if more than one person has the same percentage it will show something like this; Rank Name Percentage 1 Bob 100% 2 Sam 98% James 98% Jamie 98% 5 Tom 26% As you can see i want it to identify draws like this. My percentage is also to two decimals but that should make much difference, on results which have the same percentage i will list them in order of name. Can anyone provide any examples or point me in the right direction. Thanks Sam
×
×
  • 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.