Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. You don't show what you finally do with $text. However, at the start $text = ''; Then, inside the for() loop, ... $text .= sprintf( ^ ... might help.
  2. Alternatively ... WHERE server NOT IN ('gmail.com', 'yahoo.com')
  3. Simple boolean algebra NOT (A OR B) = NOT A AND NOT B As you have it, if the server=yahoo then it is not equal to gmail - so that condition is satisfied and therefore set to NULL if the server=gmail then it is not equal to yahoo- so that condition is satisfied and therefore set to NULL
  4. These are the results I get (wordlist contains 351,100 records) $t1 = microtime(1); $res = $db->query("SELECT word FROM wordlist WHERE MATCH (word) AGAINST ('sang*' IN BOOLEAN MODE)"); $t2 = microtime(1); printf('Query 1 : %0.4f seconds<br>', $t2 - $t1); $t1 = microtime(1); $res = $db->query("SELECT word FROM wordlist WHERE word LIKE 'sang%'"); $t2 = microtime(1); printf('Query 2 : %0.4f seconds<br>', $t2 - $t1); results (74 words found) Query 1 : 0.0026 seconds Query 2 : 0.0005 seconds
  5. You are calling a new query each time through the loop. Call the query then loop throught the results. Stop trying to do everything in a single line.
  6. foreach ($array[1] as $k => $code) { $price = $array[2][$k]; echo "$code is $price<br>"; }
  7. Put the echo inside the loop to list all of them otherwise you'll only list the last one. You will need to restructure your code.
  8. Step 3 - after the file_get_contents() is there a loop like this { read record insert record into db } while not end of file and are there 100's/1000's of records?
  9. You can't set display startup errors in the code. If you get a startup error, the code to tell them to display can't be executed.
  10. Where is $dates defined? If you are "adding to basket now..." then you only need the current date $ordered = new DateTime(); echo deliveryDate($ordered, $hols)->format('D jS M');
  11. You really make hard work of defining strings with all that concatenation and adding empty strings between everything. You could have just written $Schema_Insert ="$A\t$Ac\t$p\t$s\t$k\t$la"; eg $A = 'xyz'; $Ac = 'abc'; $p = 'mno'; $s = 123; $k = 456; $la = 'LA'; $Schema_Insert ="$A\t$Ac\t$p\t$s\t$k\t$la"; echo '<pre>'; echo $Schema_Insert; //--> xyz abc mno 123 456 LA echo '</pre>';
  12. No. If you run a query that returns several rows (eg all users older than 25), fetchAll() gives an array of all the returned rows. Fetch() will return a single row 1 ) When you use print_r() it is better to use it between <pre>..</pre> tags. It makes it much easier to see the array structure. EG echo '<pre>' . print_r($array, true) . '</pre>'; 2 ) Use that code to see the contents of $this->user_data returned with fetchAll() and then try it after using fetch() and see the difference. You should see that with fetchAll() you have an extra array level, so using $this->user_data['username'] fails. You need $this->user_data[0]['username'] to get the username from the first row in the array.
  13. fetchAll() returns an array of records. You want just the single record. Use fetch(); The reason for using prepared statements is to separate the date (like $username) from the query. Doing it like you are is as much use as a chocolate teapot. You should use placeholders for the data values. $query = "SELECT * FROM users WHERE username = ?"; $statement = $this->conn->prepare($query); $statement->execute( [$username] ); $this->user_data = $statement->fetch(PDO::FETCH_ASSOC);
  14. I don't see any PHP in there. I'm tempted to issue a warning for use of foul language 😀 Please use code button when posting code.
  15. How would you code this sequence? Create Database object Create User object passing the database connection and username.
  16. Getting better!. Change to $match[] = array( 'p1' => $related_user_1[ 0 ][ 'ID' ], 'p2' => $related_user_2[ 0 ][ 'ID' ], 's1p1' => $set_1_player_1[0] ?? '', 's1p2' => $set_1_player_2[0] ?? '', 's2p1' => $set_2_player_1[0] ?? '', 's2p2' => $set_2_player_2[0] ?? '', 's3p1' => $set_3_player_1[0] ?? '', 's3p2' => $set_3_player_2[0] ?? '', ); That should change the array from [11] => Array ( [p1] => Sam Bina [p2] => Frank Molino [s1p1] => Array ( [0] => 6 ) [s1p2] => Array ( [0] => 4 ) [s2p1] => Array ( [0] => 6 ) [s2p2] => Array ( [0] => 4 ) [s3p1] => Array ( ) [s3p2] => Array ( ) ) to [11] => Array ( [p1] => Sam Bina [p2] => Frank Molino [s1p1] => 6 [s1p2] => 4 [s2p1] => 6 [s2p2] => 4 [s3p1] => [s3p2] => )
  17. The question was about how you instantiate the user object
  18. It looks like get_post_meta always returns an array. Third and final time... var_export() ???
  19. You can't use a mysqli_xxx() call with a PDO connection. What are you passing to new User()? the $db_obj or the $db_obj->conn. (it would need to be public for that to work BTW)
  20. I can't. I haven't a clue what those WP functions are doing. Is a var_export() of that array imminent? I'm not going to waste time editing it to make it usable again.
  21. You don't explain why the scores are in arrays
  22. You might want to check again. Your code works fine when all in one file, EG class Database { private $dbhost = "localhost"; private $dbuser = "*****"; private $dbpassword = "*****"; private $dbname = "test"; private $conn; public function __construct() { try { $dsn = "mysql:host=" . $this->dbhost . ";dbname=" . $this->dbname; $this->conn = new PDO($dsn, $this->dbuser, $this->dbpassword); } catch(PDOException $exception) { die("DB connection failed: " . $exception->getMessage()); } } } $db_obj = new Database();
  23. Too many ambiguities for me. Where you say you want outputting, I assume s1p1 is the value from the subarray with that key. Am I correct? If I am, do you want s1p1 minus s1p2 or do you want them displaying as game results (eg 10 - 12)? The values for s1p1 etc are all arrays which suggests there could be multiple values. If there are multiple values, how should they be procesed? If there aren't multiple values (as your sample only ever shows 0 or 1 values) why is it an array? Finally, in your topic you posted earlier I showed you the technique to get to the output. This is only an extension of that, so what exactly are you having a problem with? PS If you are posting a large array with the expectation of some else testing with it, use var_export($array), not print_r()
  24. Me neither.
  25. Rinse and repeat - exchanging u1 and u2 $new = []; foreach ($array as $a) { if (!isset($new[$a['u1']])) { $new[$a['u1']] = []; } $new[$a['u1']][] = $a['u2']; //repeat exchanging u1 and u2 if (!isset($new[$a['u2']])) { $new[$a['u2']] = []; } $new[$a['u2']][] = $a['u1']; } // // Output $new array // echo '<pre>'; foreach ($new as $u1 => $u2s) { printf('<br><b>%4d</b> | ', $u1); foreach ($u2s as $u) { printf('%4d &vellip;', $u); } }
×
×
  • 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.