mikosiko
Members-
Posts
1,327 -
Joined
-
Last visited
-
Days Won
1
Everything posted by mikosiko
-
other alternative could be use str_replace() $str2 = str_replace(",390961CPK_100",",'39091CPK_100'", $str);
-
possible... depending on your MySql Version you could have available Mysql EVENTS (5.1.6 and up) http://dev.mysql.com/tech-resources/articles/mysql-events.html
-
group_concat_max_len reached. (default is 1024 bytes) http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_group_concat_max_len
-
+1 to Ken's advice... you always should check for errors.... you will see that you have an error in your query syntax... remove the first "(" from this line: (VALUES (1,'food',0), and remove "; )" from the end of this line (leave the rest) (4,'in a bin or box under the sink',0)";
-
2 Tables A & B :: Search Value in B, Find Match & Update in A
mikosiko replied to OldWest's topic in MySQL Help
an answer for your question in your first post (using 2 tables and a JOIN): UPDATE tableA AS a JOIN tableB AS b ON concat(a.field1, a.field2) = concat(b.field1, b.field2) SET a.field1 = b.field3, a.field2 = b.field4 // Replace table names and fields names accordingly the 2 new intents that you posted doesn't make to much sense... , but with a little effort and considering that now you have all in one table your intent 2 is easy to fix and make it work... -
2 Tables A & B :: Search Value in B, Find Match & Update in A
mikosiko replied to OldWest's topic in MySQL Help
few minutes is too much time for that why not?.... what have you tried so far? -
I wrote this quick example to give you the idea of one way to do it: <?php $mysqli = new mysqli("localhost", "youusername", "youpassword", "yourdatabase"); /* Check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // Define Multi-Query $query = "SELECT * FROM table1;"; $query .= "SELECT * FROM table2"; // Execute Multi-Query if ($mysqli->multi_query($query)) { // Use (or Store) and Process the first result set if it exists // NOTE: Replace "field1"... "field4" with the fieldnames from table1 if ($result = $mysqli->use_result()) { while ($row = $result->fetch_assoc()) { echo $row['field1'] . " - " . $row['field2'] . " - " . $row['field3'] . " - " . $row['field4'] . "<br />"; } // Close and release first result set $result->close(); } // Check if the query generated more results if ($mysqli->more_results()) { if ($mysqli->next_result()) { // I wrote 2 if's only for demo purposes.. obviously can be done in only one if printf("-- Now Printing Records from Second Table --<br />"); // Use (or Store) and Process the second result set if it exists // NOTE: Replace "field1"... "field4" with the fieldnames from table2 if ($result = $mysqli->use_result()) { while ($row = $result->fetch_assoc()) { echo $row['field1'] . " - " . $row['field2'] . " - " . $row['field3'] . " - " . $row['field4'] . "<br />"; } // Close and release the second result set $result->close(); } } } } // Close connection $mysqli->close(); ?>
-
compare this lines that you have : switch ($_GET['id']) { $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from news WHERE $id = id"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)) { $id = $_GET['id']; case '$id'; echo ("NEWS POST $row['id']"); break; default: with the first switch in your code and try to catch the differences... if not... read about the switch proper format here http://php.net/manual/en/control-structures.switch.php
-
first... you have 2 incorrect placed }'s in the first and second echo... if I understood correctly your question you want to implement a nested switch ... in that case it could look like this: <?php switch ($_GET['page']) { case 'news': echo ("NEWS HERE"); switch ($_GET['id']) { case 1: echo "ID is 1"; break; case 2: echo 'ID is 2'; break; default: echo 'ID is unknown'; break; } break; case 'schedule'; echo ("SCHEDULE HERE"); break; default: echo ("MAIN PAGE HERE"); break; }
-
Any proper methods for multiple INSERT command?
mikosiko replied to genzedu777's topic in PHP Coding Help
as you are using mysqli you could consider implement your multiples Insert with mysqli_multi_query examples here: http://php.net/manual/en/mysqli.multi-query.php -
this should help you to figure out the ean's that aren't in db http://php.net/manual/en/function.mysql-affected-rows.php only problem with this could be: evaluate if the last is a certain possibility (quantity = '$quantity') before decide to use mysql_affected_rows()... your alternatives then could be: - Do a select for each element in your file before the update (I don't like this) or - Store your file ean's in an array - Use the generated array to construct an INSERT and insert those file ean's in a temporary table (memory) and JOIN it with your real table to obtain the missing ean's... (means 1 INSERT and 1 SELECT no multiples as in the first case) - generate the mail from this result.
-
thanks... just typing too fast
-
comment this line mysql_query($query) ; and take a look what are you getting in your $query variable... your print($query) will show you.
-
I will do it in this way: $words = array('the', 'wood', 'host'); // Replace or add all the words that you wantif (in_array($q, $words) { echo " his $q?</p>";{ else { echo " her $q?</p>";}
-
I just try to access for first time the IRC channels and seems that it is down... I did try to access using the web client as this page point out: (all the links fail with "Page not found") this is the exact error:
-
What you are trying to produce as the final value for your $sql variable is this: $sql = INSERT INTO `data` (`info`, `write`, `date`) VALUES ('data99','n','2010-10-05') , ('data101','y','2010-10-05') , ('data876','n','2010-10-05')"; therefore using concatenation from the beginning in your $sql variable is not going to work in the first code that you showed. Now that you now what is the final goal just adjust your code to produce the sentence in the right way.
-
I'm using Chrome (don't know if some of the problems are exclusively noticeable on it) but all those ads screw up almost every screen... out-of-margins, double ads, etc, etc... very annoying... regarding to the decision to include those ads... well.... old-timer already said all
-
try : select a.employeeDept, a.deptEmployeeRef, a.name, a.wage - SUM(IFNULL(b.deduction,0)) AS wages FROM employees AS a LEFT JOIN deductions AS b ON a.employeeDept = b.employeeDept AND a.deptEmployeeRef = b.deptEmployeeRef AND b.monthNo = 32 GROUP BY a.employeeDept, a.deptEmployeeRef;
-
again.... read the Notes in my answer to you first post... and in this thread my first answer to you have this paragraph too : "....GROUP_CONCAT even when you can use the DISTINCT, in the way that I suggested in my Notes in the original post, for specific columns (you have to decide in which ones make sense)."
-
I don't want to sound harsh or anything similar, but the original question that you posted here: http://www.phpfreaks.com/forums/index.php/topic,311121.0.html was clearly incomplete ...you asked for a solution considering one table and later you showed 7 tables... likewise in this post you are showing the same lack of information and showing just 3 tables instead of 7, therefore the solution that you got originally was based in your original question... somebody here has the signature " The quality of the answer is directly proportional to the quality of the question" and that apply perfectly to this case. With the right information I wouldn't have suggested the usage of GROUP_CONCAT even when you can use the DISTINCT, in the way that I suggested in my Notes in the original post, for specific columns (you have to decide in which ones make sense). My suggestion now for you is to re-think your problem and how you are displaying the information... a screen like the one that you showed originally will look very cluttered with information of 7 tables.... you should think in a different way to show that information and maybe in that case get first all the relevant records/fields in an array and post-process it could make sense.
-
echo $loggedin and compare the result with what are you doing in your if($loggedin == "1")
-
a simple way to see what is happening... change this: die("Verification Error A"); // or the other to this die("Verification Error A <br />" . $queryA . "<br />" . mysql_error()); it should allow you to see the query that you are trying to execute and the associated error... after that you should be able to fix it
-
I'm sure that you realize that a SELECT and further display of the results are merely a snapshot/picture of the status of what has been selected in that specific instant ... and that snapshot could be absolutely invalid a millisecond (for quantify in some way) after it was taken in a multi-user environment right?... that scenario can be managed in part with help of atomic operations (updates in particular) which implement automatic locks (default in MYISAM engine), or TRANSACTIONS and different (table/rows) locking mechanisms in addition to the standard internal lockings provided by MYSQL. if you want to know more about: http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html http://dev.mysql.com/doc/refman/5.0/en/locking-issues.html and this, even when is kind of old contain some basic and interesting examples that could help you http://www.databasejournal.com/features/mysql/article.php/3382171/Transactions-in-MySQL.htm
-
Picachu's answer gave you a different approach to solve your problem, but just to give you an exact answer to your original problem and question: what is wrong with your code? and why you are getting duplicated results? What you are seeing is the result of use mysql_fetch_array() in your code... this is what mysql_fetch_array() does: and this is the format where $result_type can be MYSQL_BOTH (the default), MYSQL_NUM or MYSQL_ASSOC therefore if you don't specify $result_type mysql_fetch_array() will always return the fetched row twice, once with numeric array indexes and once with associative array indexes notice how Picachu changed the mysql_fetch_array() for the alternate form mysql_fetch_assoc() the equivalent to mylsq_fetch_array($result, MYSQL_ASSOC) hope this help you for the future
-
the famous (or infamous) ORDER BY RAND() again.... in the "The MySQL Sticky" fenway posted some alternatives (google will show some of them too, and explanations about why/how you can/cannot use it)