Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. No. $is_wholesale = get_user_meta( 153, 'wholesale_customer', true );
  2. As the purpose of the function is to return "true" if the specified user is a wholesale customer, how do see that working?
  3. It looks like get_user_meta() alway returns "false". You need to have a close look at that function's code to determine why.
  4. Of course, it could be that the code is correct but the data says all your user are "wholesale"
  5. Instead of $is_wholesale = get_user_meta( get_current_user_id(), 'wholesale_customer', true ); hard code the id values instead of "get_current_user_id()", so you use $is_wholesale = get_user_meta( 'A_USER_ID', 'wholesale_customer', true ); Test it substituting different ids.
  6. Log in as different users and echo get_current_user_id() to see if outputs the correct ids for the logged in users * * * "no effect"??? Are you saying that no matter what id you specify, it always returns the same value? If that is the case then it would appear your problem is with the get_user_meta() function.
  7. Me too. I think a small but important operator like that gets lost without the whitespace.
  8. Some questions for you Why is $package being passed to the function when it isn't used? Have you checked that get_current_user_id() is doing what its name suggests? Have you tested get_user_meta() with different existing ids to see if returns the correct is_wholesale value for them? Can you show us the contents of your $rates array ( echo '<pre>' . print_r($rates, 1) . '</pre>'; )
  9. I don't think that is the case, but the method seems convoluted. If I got it right, it could be rewritten as function shipping_methods_based_on_wholesale_customer( $rates, $package ){ $is_wholesale = get_user_meta( get_current_user_id(), 'wholesale_customer', true ); if( $is_wholesale ) { unset($rates['flat_rate:10'], $rates['flat_rate:7']); // To be removed for NON Wholesale users } else { unset($rates['flat_rate:13'], $rates['flat_rate:15']); // To be removed for Wholesale users } return $rates; }
  10. Time to do some reading here
  11. Look up sprintf in the manual to see how to use it properly. EDIT: I agree with @ginerjm - you should use a prepared query - it's easier than sprintf. $db->prepare("INSERT INTO info (name, surname) VALUES ( ?, ? ); $db->execute( [ $name, $surname ] );
  12. select a.saint, b.url from the tables joined on a.saint = b.nom PS if you always want the a.saint value even if there is no matching b records, use a LEFT JOIN b
  13. or $arr = [ 21, 12, 3 , 4, 25, 26, 14 ]; for ($i=0, $k = count($arr); $i<$k; $i++) { $left = array_sum(array_slice($arr, 0, $i)); $right = array_sum(array_slice($arr, 1+$i-$k)); if ($left == $right) $arr[$i] = "<sub>$left</sub><span style='font-weight: 600; color: red;'>$arr[$i]</span><sub>$right</sub>"; } echo join(', ', $arr); // show solution
  14. If that colour does exist it should probably be included with the other w3- classes and not out there on its own.
  15. To use mysqli_query () you would need to have a mysqli connection, but that will only work with mysql databases (clue is in the name) and not with SQLite. You need to use the equivalent PDO method. $stmt = $db->prepare("INSERT into info(name,surname) values(?, ?)"); $stmt->execute( [ $firstname, $lastname ] );
  16. My older version of TCPDF just collapsed like a house of cards when I tried and example page with PHPv8 throwing out errors everywhere - so that goes in the bin. As far as I know the newer versions use composer for installation. I did manage a sample using TFPDF Code <?php const ROOT = 'c:/inetpub/wwwroot'; require(ROOT.'/tfpdf/tfpdf.php'); include('db_inc.php'); $db = pdoConnect('exams'); $res = $db->query("SELECT name_en as en , name_ar as ar FROM staff ORDER BY RAND() LIMIT 10 "); $rows = $res->fetchAll(); class testpdf extends TFPDF { public function makePage($rows) { $this->AddPage(); $this->setFont('', '', 10); foreach ($rows as $r) { $this->SetFont('arial','',10); $this->Cell(60, 10, $r['en'], 'TB', 0, 'L'); $this->SetFont('calibri','',10); $this->Cell(60, 10, rtl($r['ar']), 'TB', 1, 'R'); } } } $test = new testpdf(); $test->AddFont('calibri','','calibri.ttf',true); $test->makePage($rows); $test->output(); function rtl($str) { $k = mb_strlen($str); for ($i=0; $i<$k; $i++) $a[] = mb_substr($str, $i, 1); $a = array_reverse($a); return join('', $a); } ?>
  17. Then where are you holding the current value that you want to show as selected?
  18. Something like this <select name="category"> <?php while ($category = mysqli_fetch_assoc($categories)) : $sel = $_GET['category']==$category['id'] ? 'selected' : ''; echo "<option $sel value='{$category['id']}'>{$category['title']}</option>"; endwhile; ?> </select>
  19. FYI - my preferred method is not to use links with query strings but to add a hidden "page" field to the search form. When the pagination buttons are clicked they update the hdiden field with their page number and resubmit the form. Example (The table used is "pupil" table from my sql tutorial) <?php include 'db_inc.php'; // creates pdo connection $pdo = pdoConnect('jointute'); // use your own $searches_per_page = 5; $search = $_GET['search'] ?? ''; // set defaukt values $page = $_GET['page'] ?? 1; // // // Record count // $res = $pdo->prepare("SELECT COUNT(*) FROM pupil WHERE lname LIKE ? "); $res->execute(["%{$search}%"]); $number_of_pages = ceil($res->fetchColumn()/$searches_per_page); $prev = $page > 1 ? $page - 1 : 1; $next = $page < $number_of_pages ? $page + 1 : $number_of_pages; $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); // // Get data for display // $res = $pdo->prepare("SELECT fname , lname , classid , dob , timestampdiff(YEAR, dob, CURDATE()) as age FROM pupil WHERE lname LIKE ? ORDER BY lname, fname LIMIT ?,? "); $res->execute(["%{$search}%", ($page-1)*$searches_per_page, $searches_per_page ]); $pupils = ''; foreach ($res as $row) { $pupils .= "<tr><td>" . join("</td><td>", $row) . "</td></tr>" ; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Search example</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready (function() { $(".paging").click( function() { let page = $(this).val() $("#page").val(page) // set page no in hidden form field $("#searchform").submit() // resubmit the form }) }) </script> <style type='text/css'> body { background-color: black; color: white; } td , th { padding: 4px; } </style> </head> <body> <form id='searchform'> Search for <input type='text' name='search' value="<?=$search?>"> <input type='hidden' name='page' id='page' value='<?=$page?>'> <input type='submit' value='Search'> </form> <?php if ($number_of_pages > 1) { echo "<br><br><button class='paging' value='$prev'>&lt;</button> "; for ($p = $start; $p <= $end; $p++) { echo "<button class='paging' value='$p'>$p</button> "; } echo "<button class='paging' value='$next'>&gt;</button>"; } ?> <br><br> <table border='1'> <tr><th>First Name</th><th>Last Name</th><th>Class</th><th>DOB</th><th>Student Age</th></tr> <?=$pupils?> </table> </body> </html>
  20. Firstly, you need corectly formatted query stringd (you have another "?" before page= instead of a "&") Secondly you need to pass the search value (urlencodeed) and a submit value (1) echo '<a class="paging" href="?search='.urlencode($_GET['search']).'&submit=1&page=' . ($page + 1) . '">Forward</a>';
  21. Try TCPDF. It's FPDF with lots of extras. I haven't tried it with Farsi but it handles Arabic well, unlike FPDF.
  22. When you get to page 2, are $_GET['search'] and $_GET['submit'] both set?
  23. $res is NOT an array, it is a result object. Therefore your loop never executes. Don't post pictures of code, post code.
  24. mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $connection = mysqli_connect('localhost', '****', '****', '****'); $result = $connection->query("SELECT c.title , COUNT(p.category_id) as total FROM categories c LEFT JOIN posts p ON c.id = p.category_id GROUP BY c.id "); foreach ($result as $row) { echo "{$row['title']} : {$row['title']}<br>"; } Have you got error display on? If not, check your error log.
×
×
  • 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.