
SergeiSS
Members-
Posts
239 -
Joined
-
Last visited
Everything posted by SergeiSS
-
Read help more careful!!! This is correct code: $time=date('Y-m-d',time());
-
Implode, I was correct. The only thing - I used one extra (unnecessary) apostrophe in the beginning of the string, before INSERT.
-
phpinfo() function http://www.php.net/manual/en/function.phpinfo.php will help you to find correct answer.
-
Not sure It could be that some information is stored in a session in order to allow such behavior. It's up to you - check your code. Or show it here, we can check it together. Otherwise it's impossible to give you correct answer.
-
Just one remark about your code. You are trying to create the whole string during while() loop. Do it in another way. I'll show the scheme that could be useful in many situations: $query_parts=array(); while( ...any condition...) { ... // some code $query_parts[]="($qval1, $qval2)"; // or any other code to do it } $querytestquery='"INSERT INTO test(qval1, qval2) VALUES ". implode( ' , ' , $query_parts); echo $querytestquery; // if you need it, of course
-
It depends on 'ignore_user_abort' setting in php.ini. If it's set to TRUE your script would work until processing is finished. If set to FALSE processing is terminated. You may change default behavior via function ignore_user_abort() http://www.php.net/manual/en/function.ignore-user-abort.php In your case when you noticed that "the program continued from where it stopped"... Maybe your browser took it from the cash?
-
First iteration of foreach much slower than rest
SergeiSS replied to lonewolf217's topic in PHP Coding Help
You may think anything that you like... OK, let's stop this discussion. In any case your personal opinion will not interfere my programming But, in any case, read help about foreach() once more and once more. It tells many words about internal pointer of original array, how is it changed during a loop. -
First iteration of foreach much slower than rest
SergeiSS replied to lonewolf217's topic in PHP Coding Help
No. I don't agree with you. The only thing that is copied - values of every array's element, but not the whole array!!! Have a look at this loop: $arr = array('a', 'b', 'c', 'd', 'e', 'f'); foreach ( $arr as $k => $value ) { if( $k == 1 ) $arr[1] = 'newval'; } echo '<pre>'. print_r($arr, true). '</pre>'; What do we get? This array: Array ( [0] => a [1] => newval [2] => c [3] => d [4] => e [5] => f ) It means that we change an original array, but not any ghost "local copy". Yes, $value represents a copy of one array's element at every iteration. If you break a loop we will see it (BTW according PHP help). Just an example $arr = array('a', 'b', 'c', 'd', 'e', 'f'); foreach ( $arr as $k => $value ) { // if( $k == 1 ) $arr[1] = 'newval'; if( $k == 3 ) break; } echo $value; The result is letter 'd'. It means that letters a, b, c and d were copied to $value at different iteration. But (AGAIN!) $arr is still the same array. An once more. In your article you sometimes break some rules concerning PHP arrays. Then you interpret it and make a wrong decision. In short - it's wrong because based on a wrong suggestions. When you send an array into function - yes, local copy is made! You may change an array inside your function but an original array is not changed. But here, in foreach loop, we see quite another situation. PS. You may still believe to your article... It can't prevent somebody to make PHP scripts But you'd better understand it and re-write your article for your better self-esteem. -
You mean you don't know how to read values from the selection that you performed? Do it in this way: $nesto="SELECT * FROM projekat WHERE naziv= '$value' "; $res=mysql_query($nesto); $num_rows = mysql_num_rows($res); if (num_rows>0) { while( $row=mysql_fetch_assoc( $res ) ) { // all values from every row is here, in an array $row, that have associative keys .... } }
-
Well... You'd better start just one request. And also you need COUNT() function. $sql="select ( "SELECT count(*) FROM projekat WHERE naziv= '$value' ) as count_1, (SELECT * FROM zadatak WHERE naziv= '$value' ) as count_2"; Start this request and check values of count_1 and count_2. count_1 shows the number of rows in one table, satisfied your condition, count_2 shows the same in the second table. I hope you'll find what you need.
-
What is the variable $resultat? Where do you assign it? It seems that you must write here $res, but not $resultat $res=mysql_query($nesto); $num_rows = mysql_num_rows($res); Только так будет правильно.
-
It seems that you have a problem in a logic... Have a look. I don't change your code. I just change a style of you code <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $favorites = clean($_GET['favorites']); $username = clean($_GET['user']); if($favorites == '' && $username == '') { // both are empty $errmsg_arr[] = 'Favorites are missing.'; $errflag = true; if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['favorites'])) { $insert[] = 'favorites = \'' . clean($_GET['favorites']) . '\''; } if(isset($_GET['username'])) { $insert[] = 'username = \'' . clean($_GET['username']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if($favorites && $username) { mysql_query("DELETE valuedata FROM favorites WHERE username='$username'"); $deleted = mysql_affected_rows(); if($deleted > 0) { echo("The value in favorites are deleted"); } else { echo("failed"); } } else { echo("failed"); } } } mysql_close($link); ?> You put brackets in a very random positions. I put them in correct places. I mean 'correct places' == 'correct distance from the line beginning'. Now it's clear that if this condition ($favorites == '' && $username == '') is not true you don't have a code to process it!!! Also it looks funny : $errflag = true; if($errflag) {....
-
What is the word 'cheack'? Do you mean 'check'? I suggest that you mean 'check' Could you show the PHP code and SQL requests that you used?
-
First iteration of foreach much slower than rest
SergeiSS replied to lonewolf217's topic in PHP Coding Help
Did you read in the help "As foreach relies on the internal array pointer changing it within the loop may lead to unexpected behavior." and "In order to be able to directly modify array elements within the loop precede $value with &. In that case the value will be assigned by reference."? In the article you talked about this rule is broken. It means that all your research is based on a broken rule and so can't be true Sorry, I believe PHP developers but not you. They say that foreach() makes a copy of every element at each iteration but not a copy of the whole array - as you say. You've written an article (it's nice that you've done it!!!) - but it based on a broken rule. You'd better rewrite it. -
First iteration of foreach much slower than rest
SergeiSS replied to lonewolf217's topic in PHP Coding Help
You are wrong. Read it http://ru2.php.net/manual/en/control-structures.foreach.php Pay attention on "When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array." and other words. Foreach is iterating through an original array, it just change an internal pointer (current position) of that array. -
Getting data from DB then selecting the next row
SergeiSS replied to LeeMC1989's topic in PHP Coding Help
You'd better try to explain once more, in short. What do you like to have and what do you have. PS. Maybe you understand better what do you need really while trying to explain -
You need cookie. When you are generating form, you have to write that code to a cookie. Then you create a form. Your code that generate a picture also can read the same cookie. When you receive a POST array, compare the code from user with the code from cookie.
-
Do you solve you problem or not?
-
Do you initially have an array or you have just a string that is representing an array info?
-
I'm quite sure that it's your problem!!! You have some millions of lines and you open-close files some millions of times.... That's very-very bad! Because opening-closing procedures takes a time. Many millions... You have to open files in the beginning, before your loop is started and close them when loop is finished. Just try it - preparation time might be changed from hours to minutes or tens of minutes.
-
OK. Could you show a code that is used for file processing? Maybe you something is wrong. You see... I also load a lot of information every day, it's statistics information. One part is loaded automatically in the night, I don't know it's volume. Another part is loaded under my control in the morning. The second part has a volume appr. 400-500 MB and it takes appr. 15-20 minutes to prepare it (C++ program is working) and then appr. 10-15 minutes to load it into DB, in some tables. DB is PostgreSQL. You see - the time is not so big. I'm talking about it in order to show you that I know something about it .
-
I think, that you may try to load it directly to Data Base. Every DB has a command that allow to do it. Your file is well-structured and it's read to be loaded. You may to do the next actions while loading: 1. Assign automatic, auto-incremented ids. 2. Analyze information and mark some records as start/stop of a block - you may do it inside trigger. You may skip recording of some lines. You may save some additional info into some other tables, on the base of information from some lines... In other words you may do whatever you wish. 500 MB/80 chars =~ 6.25 mln records. It's not too much for a good server and good SQL-server Now you need a lot of additional time to process via CSV.
-
Highlight a Cell (or text) when hovering on another Cell
SergeiSS replied to marz's topic in Javascript Help
Yes 1. You may use shorter function names and ids. 2. In addition to p.1 you may save the cells' names when call highlight_cell() function and then you may call unhighliht_cell() without parameters. 3. Change style of A cells via CSS. 4. You may put these events into <tr> tag. Then you have to detect which element call this event... 5... Maybe more possibilities are possible. In your case 1-st (or second) possibility is IMHO prefered because they are more simple. Why wasn't it success? How did you call this function? Show your code. I tried - it works in my hands -
Highlight a Cell (or text) when hovering on another Cell
SergeiSS replied to marz's topic in Javascript Help
Sorry, I misinform you a little Here it might be 'className=', not 'style='. Also pay attention: I changed ids!!! Because you did it incorrectly. Correct code is <style> .special_cell_style { background-color:#0F6; } .initial_cell_style { background-color:#FF0; } </style> <script> function highlight_cell( cell ) { document.getElementById( cell ).className='special_cell_style';} function unhighlight_cell( cell ) { document.getElementById( cell ).className='initial_cell_style';} </script> </head> <body> <table border="1" > <tr> <td onmouseover="highlight_cell('b1')" onmouseout="unhighlight_cell('b1')" id='a1' > A1 </td> <td onmouseover="highlight_cell('b2')" onmouseout="unhighlight_cell('b2')" id='a2' > A2 </td> <td onmouseover="highlight_cell('b3')" onmouseout="unhighlight_cell('b3')" id='a3' > A3 </td> </tr> </table> <br /> <table border="1" > <tr> <td class="initial_cell_style" id='b1' > B1 </td> <td class="initial_cell_style" id='b2' > B2 </td> <td class="initial_cell_style" id='b3' > B3 </td> </tr> </table> PS. You don't need 'td' in the names of styles. -
Highlight a Cell (or text) when hovering on another Cell
SergeiSS replied to marz's topic in Javascript Help
Let me add one thing. In the beginning it was sad "I need a smart tip to highlight a Cell in table B when the mouse is hovered over a link (or cell) in table A". That's why this code <td onmouseover="highlight_cell( 'cell_id' )" onmouseout="unhighlight_cell( 'cell_id')" id='cell_id'> B1 </td> might be changed. This id 'cell_id' must be set for another cell, in another table!!! Cell in table A: <td onmouseover="highlight_cell( 'cell_id' )" onmouseout="unhighlight_cell( 'cell_id')"> A-cell </td> Cell in table B: <td id='cell_id'> B1 </td> I told about it in the very beginning "In that events you have to call one special function (you create it) and pass to that function a parameter, showing the cell to be highlighted." - according to the first task. But it seems that TC didn't understand it.