Jump to content

AP81

Members
  • Posts

    100
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

AP81's Achievements

Member

Member (2/5)

0

Reputation

  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. Sweet, thanks!
×
×
  • 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.