-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Can a person belong to more than one group?
-
Easiest is to use a function to which you pass the users current level function auth_level_options ($db, $user_level) { $sql = "SELECT auth_level , descrip FROM Auth ORDER BY auth_level"; $res = $db->query($sql); $opts = "<select name='flag>" while (list($level,$desc) = $res->fetch_row()) { $sel = $level == $user_level ? 'selected="selected"' : ''; $opts .= "<option value='$level' $sel>$desc</option>"; } $opts .= "</select>\n"; return $opts; } then where you want the dropdown echo auth_level_options($dbconn, $current_user_level);
-
Is this what you are trying to do blake.html <!DOCTYPE HTML > <html> <head> <meta name="author" content="Barand"> <meta name="creation-date" content="11/05/2014"> <title>Example</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#button").click(function() { var name = "test"; $.get( "blake.php", {"name":name}, function(data) { $.each(data, function(k,v){ $("#click").append(k + " : " + v + "\n"); }) $("#click").append("--------------------\n"); }, "json" ) }) $("#clear").click(function() { $("#click").html(""); }) }) </script> </head> <body> <textarea cols='20' rows='15' id='click'></textarea> <input type="button" name="button" id="button" value="Click me"> <input type="button" name="clear" id="clear" value="Clear"> </body> </html> blake.php (called via ajax) <?php session_start(); if (isset($_GET['name'])) { $userAnswer = $_GET['name']; if (isset($_SESSION['test'][$userAnswer])) { $_SESSION['test'][$userAnswer]['var1']++; } else { $_SESSION['test'][$userAnswer] = array('var1'=>1, 'var2'=>2); } echo json_encode($_SESSION['test'][$userAnswer]); } else echo ''; ?>
-
Depends on the volume exported 1000 or less read from server1 table store in array connect to second server insert from the array more than 1000 read from server1 table write to a csv file connect to second server use LOAD DATA INFILE to insert records
-
I don't see why you need a cron job. Make the writing of the "search" record part of the acceptance process. You just need a one-off process to create the table from your existing video records. Also you don't have to merge the fields into one to have a full text index. You can index multiple fields.
-
One table will suffice if you use NULL to represent no parent as Jaques stated CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `col1` int(11) DEFAULT NULL, `parent_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk1` (`parent_id`), CONSTRAINT `fk1` FOREIGN KEY (`parent_id`) REFERENCES `test` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) mysql> select * from test; +----+------+-----------+ | id | col1 | parent_id | +----+------+-----------+ | 1 | 222 | NULL | (top level, no parent) | 2 | 333 | 1 | | 3 | 44 | NULL | (top level, no parent) | 4 | 22 | 1 | | 5 | 32 | 2 | | 6 | 21 | 3 | | 7 | 43 | 3 | +----+------+-----------+ 7 rows in set (0.00 sec) mysql> DELETE FROM test WHERE id = 1; Query OK, 1 row affected (0.00 sec) mysql> select * from test; +----+------+-----------+ | id | col1 | parent_id | +----+------+-----------+ | 3 | 44 | NULL | | 6 | 21 | 3 | | 7 | 43 | 3 | +----+------+-----------+ 3 rows in set (0.00 sec)
-
You don't seem to be returning a json encoded array, rather a list of json encoded variables instead, which is just a list of those variable values So you are return something like "12"; To return a json encoded array use echo json_encode($_SESSION['test'][$username]) which will return {"var1":2,"var2":3} Alternatively, change the ajax request to expect plain "text", which is what you are returning.
-
Yes but, unfortunately, mine wasn't as ambitious as yours I restricted them to items in the database
-
You obviously like typing if(isset($_POST['name']) && isset($_POST['name2'])) { echo json_encode(array($_POST['name'], $_POST['name2']) ); }
-
you could change +----------------+ | video (innodb) | +----------------+ | video_id | | title | | description | | author | | duration | | etc | +----------------+ to +----------------+ +----------------+ | video (innodb) | | search (myisam)| +----------------+ +----------------+ | video_id |--------| video_id | | | | title | (fulltext) | | | description | (fulltext) | author | +----------------+ | duration | | etc | +----------------+ then SELECT .... FROM video INNER JOIN search USING (video_id) WHERE MATCH ... AGAINST ...
-
Disregard that last post. I ran it few more times and the WHERE made no difference, in fact it was slower on occasions
-
This is from the code you posted Why don't you just use the same method to center or right-align your other fields?
-
Here's an example of how your first two queries would be combined. SELECT * FROM tblOperators o LEFT JOIN tblUserPayments p ON p.OperatorID = 0.OperatorID AND PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%' WHERE OperatorLocale = 'USA' and OperatorStatus = 'ACTIVE' and Team = 'RENEWALS' Do not use SELECT * in your queries, specify the columns you need. You could combine the others too, probably, but that would mean my reverse engineering your table structures and all I know is that all your tables contain " * ".
-
I could not see any value in using a join. You would need either two queries or conditional statements as now. I created a table with 1000 rows of random values and nulls and ran your query. I also ran your query a second time on the same data with an added "WHERE col_1 IS NULL OR col_2 is NULL". Here are the the two run times 0.05800 0.02900
-
Might have been officially deprecated in 5.3 but warnings against their use were around over 10 years ago
-
Try using "AND" instead of "||"
-
If you get your tail command to write the selected lines to a file, say "log.txt" for example Wed Oct 29 18:35:25 MDT 2014 1001 : ERROR -- speh1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-102 Thu Oct 30 18:35:25 MDT 2014 1201 : WARNING -- abcd1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-103 Fri Oct 31 18:35:25 MDT 2014 1302 : NOTICE -- mamc1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-104 Then the processing would look like this <?php function split_row($str) { $date = substr($str,0,28); $str = substr($str,29); $arr = explode(' -- ', $str); $err = $arr[0]; $words = explode(' ', $arr[1]); $code = array_shift($words); $msg = join(' ', $words); return "<tr><td>$date</td><td>$code</td><td>$msg</td><td>$err</td></tr>\n"; } $lines = file('log.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $logdata = ''; foreach ($lines as $line) { $logdata .= split_row($line); } ?> <html> <head> <title>Log sample</title> </head> <body> <table border='1' cellpadding='3'> <tr><th>Date</th><th>Code</th><th>Message</th><th>Error</th></tr> <?=$logdata?> </table> </body> </html>
-
Have you considered something like the calc() function in the second user note at http://php.net/manual/en/function.eval.php?
-
Getting absolute filepath from image resource
Barand replied to arbitrageur's topic in PHP Coding Help
http://php.net/manual/en/features.file-upload.multiple.php -
Transfering data over different servers.
Barand replied to OsirisElKeleni's topic in PHP Coding Help
If, as I suggested in reply #7, your data is stored in an array the data will not be lost. Only data in any unsaved result sets will be lost when the connection closes. There is no problem with two connections. I have done it many times when I needed to connect to a development and production server in the same script or when a script required connections to MySql server and an MS SQL server -
Transfering data over different servers.
Barand replied to OsirisElKeleni's topic in PHP Coding Help
Rather than have a loop running the inserts a multiple insert would be fare more efficient, eg INSERT INTO table2 (username) VALUES ('CosmonautBob'), ('ooglebrain'),('JamieKG'),('Quinnter16') So your code would be $names = array(); while($row = mysqli_fetch_assoc($result)) { $name = $row['username']; $names[] = "('$name')"; } $conn->close(); //// now connect to the second server $conn2 = new mysqli(HOST2,USERNAME,PASSWORD,DATABASE); $sql = "INSERT INTO table2 (username) VALUES\n" . join(',', $names); $conn2->query($sql); -
Transfering data over different servers.
Barand replied to OsirisElKeleni's topic in PHP Coding Help
Store the data in an array then connect to the second server and write the data -
What does the prices array contain at this point in the code? var_export($prices);
-
With a single line of code without context, and no knowledge of the contents of the variables, all we can do is play guessing games.
-
Revision with reset button <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+chosen+"]").hide(); } }) }) $("#btnReset").click(function() { $("option").show(); this.form.reset(); }) }) </script> </head> <body> <form> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> <input type='button' name='btnReset' id='btnReset' value='Reset'> </form> </body> </html>