Jump to content

AP81

Members
  • Posts

    100
  • Joined

  • Last visited

Everything posted by AP81

  1. My bad, sorry I did this off the top of my head. Should be: return ($num_rowe >= 1);
  2. There's multiple ways to do it, but a good start is wrapping that code in a function. function hasSlotTime($slotTime) { $queuen = mysql_query("SELECT * FROM put_exam WHERE sess_id ='".$t_slot_time."'") or die(mysql_error()); $arrDatasa= array(); while($rowsa = mysql_fetch_array($queuen)) { $arrDatasa[]=$rowsa['course_code']. '|'; $docam = array_filter($arrDatasa); } foreach($arrDatasa as $a=> $rowsa){ $docama.=$docam[$a]; } //Store current coursecode to assisgn into currentass $currentass = $e_course_code; //Check for common student between the last assigned course and current course to be as $chkcomms = mysql_query("SELECT student.matric, student.std_name FROM student JOIN course_reg e1 ON e1.matric=student.matric JOIN course c1 ON c1.course_code=e1.course_code JOIN course_reg e2 ON e2.matric=student.matric JOIN course c2 on c2.course_code = e2.course_code WHERE c1.course_code = '".$currentass."' AND c2.course_code RLIKE '%$docama%' GROUP BY student.matric") or die(mysql_error()); // Count number of rows $num_rowe = mysql_num_rows($chkcomms); return ($num_rowe >= 1) { } Then you can do something like this: while (hasSlotTime($t_slot_time)) { $t_slot_times = $t_slot_time + 2; } Ideally, you shouldn't be doing queries in a loop, and if possible you should write some better code rather than using the array filter in the loop. I don't know the nature of your application and how to use it, but that is essentially what you'd do. So: Create function which does the query The function should return true if the result is >=1, otherwise false Loop until false Hopefully that is a push in the right direction.
  3. Have you tried just echoing out the variables to see what the actual values are? i.e. echo "tmp = $tmp <br />"; echo "month = $month <br />"; if($tmp !== $month){
  4. You're going to need to provide more information, such as the HTML and JavaScript, etc.
  5. http://php.net/manual/en/function.debug-backtrace.php
  6. Hi, I'm working on some old code (someone else wrote) and have to replace old the old 'ereg' functions to preg_match. As we are moving to PHP 5.3 the ereg functions are deprecated. The funny thing is that these two pieces of code produce different output. One uses ereg and the other preg_match. Any reasons as to why? The code below produces a different size array of matches for $amt3 and $amt4. I can write a work around but am just wondering why the output is different, as all documentation I have read state that ereg and preg_match are almost identical in the result they produce. $amt1 = '$100.00'; $amt2 = '100.00'; $amt3 = '$100'; $amt4 = '100'; function parseFromString($amount) { if (!preg_match('/^([A-Z]{1,3})?(\$)?([0-9]+)((\.)([0-9]+))?$/', $amount, $regs)) { return null; } var_dump($regs); } function parseFromString1($amount) { if (!ereg('^([A-Z]{1,3})?(\$)?([0-9]+)((\.)([0-9]+))?$', $amount, $regs)) { return null; } var_dump($regs); } parseFromString($amt1); parseFromString($amt2); parseFromString($amt3); parseFromString($amt4); echo "\n\n==============================\n\n"; parseFromString1($amt1); parseFromString1($amt2); parseFromString1($amt3); parseFromString1($amt4); Output: array(7) { [0]=> string(7) "$100.00" [1]=> string(0) "" [2]=> string(1) "$" [3]=> string(3) "100" [4]=> string(3) ".00" [5]=> string(1) "." [6]=> string(2) "00" } array(7) { [0]=> string(6) "100.00" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(3) "100" [4]=> string(3) ".00" [5]=> string(1) "." [6]=> string(2) "00" } array(4) { [0]=> string(4) "$100" [1]=> string(0) "" [2]=> string(1) "$" [3]=> string(3) "100" } array(4) { [0]=> string(3) "100" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(3) "100" } ============================== array(7) { [0]=> string(7) "$100.00" [1]=> bool(false) [2]=> string(1) "$" [3]=> string(3) "100" [4]=> string(3) ".00" [5]=> string(1) "." [6]=> string(2) "00" } array(7) { [0]=> string(6) "100.00" [1]=> bool(false) [2]=> bool(false) [3]=> string(3) "100" [4]=> string(3) ".00" [5]=> string(1) "." [6]=> string(2) "00" } array(7) { [0]=> string(4) "$100" [1]=> bool(false) [2]=> string(1) "$" [3]=> string(3) "100" [4]=> bool(false) [5]=> bool(false) [6]=> bool(false) } array(7) { [0]=> string(3) "100" [1]=> bool(false) [2]=> bool(false) [3]=> string(3) "100" [4]=> bool(false) [5]=> bool(false) [6]=> bool(false) }
  7. Hi guys, Having a strange problem on our Production server (running Apache/PHP/Postgres). If you leave a page idle for a while (after being logged in), you end up with a session timing out. We can't replicate it on our dev our staging servers, only production. We have 5 production servers in our web farm, so we are inspecting them one-by-one to find the problem. Just wondering whether anyone has any ideas as we haven't got very far. We pulled one server out the of the farm and ran an strace (see below). Any pointers? We haven't changed any Apache/PHP settings recently either. 20:59:57.304232 open("/home/ecom/tmp/auth_8t1sj72ui98k2qnl81f42hgau5", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 129 20:59:57.304374 fstat64(129, {st_dev=makedev(104, 3), st_ino=854283, st_mode=S_IFREG|0664, st_nlink=1, st_uid=30, st_gid=1000, st_blksize=4096, st_blocks=0, st_size=0, st_atime=2011/03/30-20:44:57, st_mtime=2011/03/30-20:59:57, st_ctime=2011/03/30-20:59:57}) = 0 20:59:57.304520 lseek(129, 0, SEEK_CUR) = 0 20:59:57.304591 write(129, "O:13:\"Ires_Web_Auth\":9:{s:22:\"\0I"..., 1642) = 1642 20:59:57.304698 close(129) = 0 20:59:57.304776 chmod("/home/ecom/tmp/auth_8t1sj72ui98k2qnl81f42hgau5", 0664) = 0 20:59:55.929294 lstat64("/home/ecom/lib", {st_dev=makedev(104, 3), st_ino=953750, st_mode=S_IFDIR|0755, st_nlink=31, st_uid=1003, st_gid=1000, st_blksize=409 6, st_blocks=8, st_size=4096, st_atime=2011/03/30-18:49:03, st_mtime=2011/03/25-23:33:26, st_ctime=2011/03/25-23:33:51}) = 0 20:59:55.929539 lstat64("/home/ecom/lib/Sdk", {st_dev=makedev(104, 3), st_ino=953877, st_mode=S_IFDIR|0755, st_nlink=8, st_uid=1003, st_gid=1000, st_blksize= 4096, st_blocks=8, st_size=4096, st_atime=2011/03/30-18:49:03, st_mtime=2011/03/21-16:54:24, st_ctime=2011/03/23-16:08:29}) = 0 20:59:55.929785 lstat64("/home/ecom/lib/Sdk/Util", {st_dev=makedev(104, 3), st_ino=953900, st_mode=S_IFDIR|0755, st_nlink=3, st_uid=1003, st_gid=1000, st_blk size=4096, st_blocks=8, st_size=4096, st_atime=2011/03/30-18:49:03, st_mtime=2011/03/21-16:54:23, st_ctime=2011/03/23-16:08:29}) = 0 20:59:55.930035 lstat64("/home/ecom/lib/Sdk/Util/Url.php", {st_dev=makedev(104, 3), st_ino=953122, st_mode=S_IFREG|0755, st_nlink=1, st_uid=1003, st_gid=1000 , st_blksize=4096, st_blocks=24, st_size=10515, st_atime=2011/03/30-20:59:55, st_mtime=2011/03/21-16:54:23, st_ctime=2011/03/23-16:08:29}) = 0 20:59:55.930251 open("/home/ecom/lib/Sdk/Util/Url.php", O_RDONLY) = 127 20:59:55.930358 fstat64(127, {st_dev=makedev(104, 3), st_ino=953122, st_mode=S_IFREG|0755, st_nlink=1, st_uid=1003, st_gid=1000, st_blksize=4096, st_blocks=2 4, st_size=10515, st_atime=2011/03/30-20:59:55, st_mtime=2011/03/21-16:54:23, st_ctime=2011/03/23-16:08:29}) = 0 20:59:55.930523 read(127, "<?php\n/**\n * @package Sdk\n * @co"..., 8192) = 8192 20:59:55.931479 read(127, "path>][?<query>][#<fragment>]]\n "..., 8192) = 2323 20:59:55.931669 read(127, "", 8192) = 0 20:59:55.932040 read(127, "", 8192) = 0 20:59:55.932202 close(127) = 0 20:59:55.932471 stat64("/home/ecom/www/xxxxx/htdocs/accommodation/Melbourne/The-Hotel-Charsfield-2CHAMEL.html", 0xbfb550dc) = -1 ENOENT (No such file o r directory) 20:59:55.932691 stat64("/home/ecom/www/xxxxx/htdocs/accommodation/Melbourne/The-Hotel-Charsfield-2CHAMEL.php", 0xbfb5587c) = -1 ENOENT (No such file or directory) 20:59:55.932904 stat64("/home/ecom/www/xxxxx/htdocs/accommodation/Melbourne/The-Hotel-Charsfield-2CHAMEL.php", 0xbfb5587c) = -1 ENOENT (No such file or directory) 20:59:55.933239 getcwd("/home/ecom/www/xxxxx/htdocs", 4096) = 34 20:59:55.933427 time(NULL) = 1301482795
  8. I think the way you're generating the table rows is incorrect. Try this: <?php $columns_counter=0; $body .= "<table>"; while($row_p = mysql_fetch_array($result_p)) { if ($columns_counter == 0) { $body .= "<tr>"; } $body .= "<td width=140 align=center height=137>" ."<img style='border:2px solid #a2a2a2' alt='mobile phones' src='http://domain/graphics/thumbs/" . $row_p['prod_thumb'] . "'/></td> <td width='235'>".$row_p['product_name'] ."</td>"; $columns_counter++; if($columns_counter==2){ $body .= "</tr>"; $columns_counter=0; } } ?>
  9. That's strange, getimagesize is a standard PHP function, so it should be supported on PHP4 & PHP5. Just a thought, try using the file_exists function of getimagesize...
  10. Hi, What I want to do seems a bit far-fetched, but I thought I'd ask anyway... What I want to do is re-define the PHP foreach loop. The reason why I want to this is: We have an SDK which has taken 5 years to develop (a very complex but well written SDK) and all the previous developers have used foreach loops everywhere. This has a high overhead, especially that alot of these are looping through arrays of complex objects. I did tests on a number of pages (converting them to for loops) and noticed a reasonable improvement. What I like to do is apply this globally without having to re-do the entire SDK (which is well over 500,000 lines of code). I was thinking maybe I could stick something in the prepend and re-declare the foreach loop method. Is this possible?
  11. Hi, I am working on a *big* project with lots of classes,interfaces and inheritance. I'd ideally like to be able to view an inheritance hierarchy without having to go through reams of PHPdoc. I am running in a Linux box (Ubuntu) by the way. For example, lets say I open the class file for class Three. I'd like to be able to see something like below: abstract class One + +- class Two extends One +- class Three extends One +-- class Three_One extends Three Does anyone know if any IDE has this functionality? I'd even be happy if you can highlight a class name and search open files for the parent class... Thanks
  12. Hi, I am working on a *big* project with lots of classes,interfaces and inheritance. I'd ideally like to be able to view an inheritance hierarchy without having to go through reams of PHPdoc. I am running in a Linux box (Ubuntu) by the way. For example, lets say I open the class file for class Three. I'd like to be able to see something like below: abstract class One + +- class Two extends One +- class Three extends One +-- class Three_One extends Three Does anyone know if any IDE has this functionality? I'd even be happy if you can highlight a class name and search open files for the parent class... Thanks
  13. Yep, I would do that using boolean values. But if they were strings it would be different.
  14. Hi, Take a look at the following code below: <?php $test = true; if ($test == true) { echo "true"; } else { echo "false"; } ?> Now that looks fine to me. I was reading a book which suggests to always put the constant on the left hand side of an equality/inequality comparison. So the above would become: <?php $test = true; if (true == $test) { echo "true"; } else { echo "false"; } ?> The reason is that if you leave out one of the = signs, the parser will find the error for you. So this script still runs: <?php $test = true; if ($test = true) { // removed one equals sign echo "true"; } else { echo "false"; } ?> And the following fails: <?php $test = true; if (true = $test) { // removed one equals sign echo "true"; } else { echo "false"; } ?> So I can see some merit in this, but it just doesn't look right to me. Most people I know would put the constant on the right hand side, as it seems more logical. What are your thoughts on this?
  15. Hi, I needed to compare strings to see if they contain all the same characters, but aren't identical. For example, comparing 2345 and 3245. These strings aren't identical, but contain the same characters. The reason why I needed to do this was to cross check some numbers from two different databases (a couple of previous employees were dyslexic). I am porting over all this information from one DB to another, thus I am cleaning the data to make sure it is accurate. Anyway, I've written my own solution to this (see strings_contain_same_chars function below) as I couldn't find a PHP function which does this. Although it works fine, there is a fair amount of overhead by creating arrays to store the data, then sort, then implode. I was wondering if there is a neater way to do this. <?php $string1 = '2345'; $string2 = '3245'; function strings_contain_same_chars($string1, $string2) { $lenStr1 = strlen($string1); $lenStr2 = strlen($string2); if ($lenStr1 != $lenStr2) { // invalid if not the same length return false; } else { for ($i=0; $i<$lenStr1; $i++) { $str1[$i] = substr($string1, $i, 1); } for ($i=0; $i<$lenStr2; $i++) { $str2[$i] = substr($string2, $i, 1); } sort($str1); sort($str2); $str1 = implode('', $str1); $str2 = implode('', $str2); if ($str1 == $str2) { return true; } return false; } } ?>
  16. Hi guys, Just wondering if most of you use fixed pixel widths for your layout containers, for example a basic layout consisting of: a container which has a header section, main content section and footer section Given the above I would set the container, header, main content & footer sections to a fixed width. Any div column layouts in the header/main/footer I would then use percentages. Is this the best way for browser compatibility? (I am more a back-end developer and haven't done any solid HTML for a while)
  17. How have you defined your functions? If you use a class you can have the constructor set the $DBHOST, $RRPASS, $SVRUR, i.e. <?php Class remoteReg() { private $DBHOST; private $RRPASS; private $SVRURL; public function __construct($host, $pass, $url) { $this->DBHOST = $host; $this->RRPASS = $pass; $this->SVRURL = $url; } public function Connect() { // connection code here } public function remotereg($var1, $KEYCAT, $KEYNAME, $var2, $var3) { //do the remote reg, sorry don't know what your variable names are } } // now create the class $host = 'xxxx'; $pass = 'yyyy'; $url = 'testserver'; $reg = new remoteReg($host,$pass,$url); $reg->remotereg("W", 'keycat1', 'keyname1', 0, NULL); ?> Obviously you need to modify this so it reflects your code.
  18. Use an Ajax request. You can then send the request to a PHP page via a URL, for example: actions.php?action=setcookie&option=en Your PHP page would look something like this: <?php $action = $_GET["action"]; switch ($action) { case "setcookie": if (setcookie("language","en")) $result = "OK"; else $result = "FAIL"; break; } echo $result; ?> Rather than get into the nitty-gritty of Ajax, you can use a JavaScript framework to make your life easier, for example: jQuery or mootools (there are many more frameworks than this). Your other option is to set a cookie using JavaScript. Just as easy.
  19. SELECT username, high FROM `users` ORDER BY `high` ASC LIMIT 10
  20. You'd have to run a Linux command to merge the two videos (you can run bash commands in PHP). So the trick here is to find a Linux application that can do the joining. I know that avimerge can join .avi files (i.e. avimerge - o output.avi input1.avi input2.avi) and it is part of the transcode package (apt-get install transcode). If you need to merge mpeg, etc you may need to dig deeper. Your best bet is to post a question in a Linux forum about joining videos. Once you have figured out how to do that via command line the rest is easy.
  21. Do you have Postfix or sendmail installed? Does typing "man mail" on command line give you a manual page? Postfix or Sendmail are required in order for the mail function to work.
  22. Just one tip: Replace var with private. var is PHP4 and is redundant (but still supported in PHP5). So you should protected/private/public in place of var. Other than that it looks good. I generally include a couple more functions: GetRowCount and GetRowsAffected. It makes it handy to get the number of rows a query returns and to be able to find how many rows have been affected by a delete/insert. Also there isn't a need to typecast all the variables to strings in the constructor. They are all strings anyway. No harm leaving it there though.
  23. What exactly are you sending the client? Plain text? Here is an example of what you need to send. You will need to link to images on your server. Put all your CSS and HTML together in a string then mail it. <html> <head> <style type="text/css"> .boldText { font-weight:bold; font-size:16px } </style> </head> <body> <img src="http://www.youserver.com/header.jpg" /> <p class="boldText">This is a test email blah blah blah</p> <img src="http://www.youserver.com/footer.jpg" /> </body> </html>
  24. The whole email has to be html, and you'd have to: a) include the header and footer images as attachments with the email or b) link the images to your site remotely (recommended)
×
×
  • 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.