-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Have you tried looking in the phpMyAdmin folder in that list?
-
I downloaded the class and gave it a try. This creates a pdf doc with a separate page (image and name) for each person. <?php require '../tcpdf/tcpdf.php'; $names = [ "ماشوت محمد علي علام" , "منى طه أبو العلا شعلان" , "وليد عبد العزيز السيد الشيخ" , "ابراهيم عبد السلام خلف" , "احمد حمدى نوار" ]; $pdf = new tcpdf(); $pdf->SetFont('aefurat', '', 30); $pdf->SetTextColor(255); foreach ($names as $name) { $pdf->AddPage(); $pdf->Image('images/snowman.png',15,15,180,180); $pdf->setY(40); $pdf->cell(0,15,$name,0,1,'C'); } $pdf->output('Sample.pdf', 'I'); ?> Output (greatly reduced)
-
MySQL / PHP - IF/AND/OR Statements - Getting Confused
Barand replied to djb2002's topic in PHP Coding Help
When mixing AND and OR in expressions, use parentheses to make the logic explicit. For example, instead of if (A AND B OR C) use one of these, depending on what you mean if ( (A AND B) OR C ) or if ( A AND ( B OR C ) ) -
If you want to print then I would take the pdf route, placing the png image in the output then, again, overwriting the text. TCPDF appears to support Arabic
-
Plan C - Embed the png image in the svg image and overlay with the name <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='500'> <image x='0' y='0' width='500' height='500' xlink:href='images/snowman.png' /> <text x='250' y='110' text-anchor='middle' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?>
-
Plan B - vector graphics <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='100'> <rect x='1' y='1' width='499' height='99' style='fill:#000; stroke:#000' /> <text x='20' y='60' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?>
-
Try a change of font. It works with "calibri" <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = imagecreatetruecolor(500,100); $tcolor = imagecolorallocate($im,255,255,255); imagettftext($im, 20, 0, 20, 60, $tcolor, 'c:/windows/fonts/calibri.ttf', $name); header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> result
-
I guess it's true: "Test data is that data for which the query works", so mine only has the one overlap I put in deliberately to see if I could find it.
-
-
Use SQL Query to Get Revised & New Orders
Barand replied to mongoose00318's topic in PHP Coding Help
I would recommend you split the order number in that case. Put the location (digits 1 and 2) in a location code column and the rest in the order number column. Aside from it being a poor design decision to have "structured" numbers in a single column, your users will have to use search expressions "LIKE '%x%' ". That will prevent any indexes from being used and greatly slow down any searches. -
Use SQL Query to Get Revised & New Orders
Barand replied to mongoose00318's topic in PHP Coding Help
Why? There is very little data in your query results that is LIKEable. LIKE is for matching string type columns against partial string values using wildcards E.G. Find all users with last name beginning with "J" who live in a location ending with "ham" SELECT … FROM user WHERE lastname LIKE 'j%' AND location LIKE '%ham'; Jones, Oldham Johnstone, Birmingham Joker, Gotham -
Combobox show information selected from database
Barand replied to ciresuark's topic in PHP Coding Help
The value should be the country code (which is what is in your customer table) -
Combobox show information selected from database
Barand replied to ciresuark's topic in PHP Coding Help
Is line 94 this one.. <option value="<?php echo $country['customerID']; ?> where you are trying to use "customer_id" as the value for your country, instead of the country_id/code? -
Combobox show information selected from database
Barand replied to ciresuark's topic in PHP Coding Help
Of course - all the options are in the combo but the relevant one is displayed. -
Combobox show information selected from database
Barand replied to ciresuark's topic in PHP Coding Help
Build you country combo options from the country table. The value for each option should be the id/code for the country Here's an example <?php $res = $db->query("SELECT customer_id , fname , lname , country FROM customer LIMIT 10 "); $tdata = ''; foreach ($res as $row) { $tdata .= "<tr> <td>{$row['fname']} {$row['lname']}</td> <td style='text-align: center;'><select name='country'>" . countryOptions($db, $row['country']) . "</select><td> </tr>"; } function countryOptions(PDO $db, $current) { $opts = "<option value=''>- select country -</option>\n"; $res = $db->query("SELECT country_id as id , country_name as name FROM country ORDER BY name "); foreach ($res as $row) { $sel = $row['id'] == $current ? 'selected' : ''; $opts .= "<option $sel value='{$row['id']}'>{$row['name']}</option>\n"; } return $opts; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> </head> <body> <table style='width: 600px;'> <tr><th>Name</th><th>Country</th></tr> <?=$tdata?> </table> </body> </html> Example data and ouput Table: customer Table: country +-------------+----------+-----------+---------+ +------------+--------------+ | customer_id | fname | lname | country | | country_id | country_name | +-------------+----------+-----------+---------+ +------------+--------------+ | 1 | Wanda | Denning | 1 | | 1 | England | | 2 | Tom | Westbrook | 2 | | 2 | Scotland | | 3 | Georgina | Jones | 3 | | 3 | Wales | | 4 | Hannah | Wentworth | 1 | | 4 | N. Ireland | | 5 | Roy | Egon | 4 | +------------+--------------+ | 6 | Len | Elridge | 1 | | 7 | Sam | Patterson | 2 | | 8 | Charles | Knight | 1 | | 9 | Gerald | Watts | 1 | | 10 | Tom | Bowles | 4 | +-------------+----------+-----------+---------+ -
At the risk of stating the bleedin' obvious, the first set of code above uses a placeholder (:userId) and passes the user id value in the execute() call. This is the correct way to use prepare(). The second puts the user id value directly into the query string. BTW, you stored the user id in $_SESSION[''user_login'] and not in $_SESSION['user_login']['user_id'].
-
I had to check my table in 2 halves (id < 3,000,000 and id > 3,000,000) otherwise it timed out. mysql> SELECT count(*) FROM ip_lookup; +----------+ | count(*) | +----------+ | 5852250 | +----------+ 1 row in set (10.15 sec) mysql> SELECT * -> FROM ( -> SELECT CASE WHEN start <= @xend AND end >= @xstart -> THEN id -> ELSE NULL -> END as found -> , @xstart := start as start -> , @xend := end as end -> FROM ip_lookup -> JOIN (select @xstart := null, @xend := null) init -> WHERE id > 3000000 -> ) search -> WHERE found IS NOT NULL; +---------+-------+------+ | found | start | end | +---------+-------+------+ | 5000003 | ┌ 0n | ┌ 0ê | +---------+-------+------+ 1 row in set (27.00 sec) SELECT id , inet6_ntoa(start) as startA , inet6_ntoa(end) as endA FROM ip_lookup a WHERE id BETWEEN 5000001 AND 5000005; +---------+----------------+----------------+ | id | startA | endA | +---------+----------------+----------------+ | 5000001 | 218.255.48.86 | 218.255.48.102 | | 5000002 | 218.255.48.103 | 218.255.48.119 | << overlapping | 5000003 | 218.255.48.110 | 218.255.48.136 | << | 5000004 | 218.255.48.137 | 218.255.48.153 | | 5000005 | 218.255.48.154 | 218.255.48.170 | +---------+----------------+----------------+
-
1 ) That isn't how you did it in the first query. 2 ) It's wrong. 3 ) Never put variables into a query. That's why "prepare" is used.
-
The same way that you did with the username and email in the first query.
-
That will treat the symptom but the cure would be to fix the ip_lookup records that have the overlapping start and end values.
-
That is one of the prime reasons why many developers prefer PDO to mysqli. With PDO it doesn't matter whether you use query() or prepare(). The resulting objects in both cases have exactly the same methods. With mysqli there are two distinct sets of methods that you must use to process results depending on whether you used query (which gives a result object) or prepare (which gives a statement object).
-
You seem to be confusing your types. The string version of an IPv6 address ( xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx )requires varchar(40). Well, 39 to be precise. When converted to a numeric value with inet6_aton() then the output is varbinary(16).
-
I suspect it may be your use of inet_aton() and trying to match that against varbinary(16) but I don't know how your tables are currently defined or how the llokup start and end values were set (Mine were set using inet6_aton() to handlw both IPv4 and IPv6). My tables: CREATE TABLE `download` ( `id` int(16) NOT NULL AUTO_INCREMENT, `address` varchar(40) DEFAULT NULL, `ip_address` varbinary(16) DEFAULT NULL, `ref` int(25) unsigned DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; (No data yet) CREATE TABLE `ip_lookup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `start` varbinary(16) DEFAULT NULL, `end` varbinary(16) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +----+----------+----------+--------------+--------------+ | id | start | end | ip_start | ip_end | +----+----------+----------+--------------+--------------+ | 1 | FF010101 | FF320117 | 255.1.1.1 | 255.50.1.23 | | 2 | FF320118 | FF320164 | 255.50.1.24 | 255.50.1.100 | | 3 | FF320165 | FF3201C8 | 255.50.1.101 | 255.50.1.200 | | 4 | FF3201C9 | FF3204FF | 255.50.1.201 | 255.50.4.255 | +----+----------+----------+--------------+--------------+ My trigger: CREATE TRIGGER `download_BEFORE_INSERT` BEFORE INSERT ON `download` FOR EACH ROW BEGIN SET NEW.ip_address = inet6_aton(NEW.address), NEW.ref = (SELECT id FROM ip_lookup i WHERE NEW.ip_address BETWEEN i.start AND i.end ); END Add download data INSERT INTO download (address) VALUES ('255.50.1.20'), ('255.50.1.165'), ('255.50.1.100'), ('255.50.1.222'); View results: (as you can see - the trigger worked) SELECT d.id , d.address , hex(d.ip_address) as hex_address , d.ref , inet6_ntoa(i.start) as lookup_start , inet6_ntoa(i.end) as look_up_end FROM download d JOIN ip_lookup i ON d.ref = i.id; +----+--------------+-------------+------+--------------+--------------+ | id | address | hex_address | ref | lookup_start | look_up_end | +----+--------------+-------------+------+--------------+--------------+ | 1 | 255.50.1.20 | FF320114 | 1 | 255.1.1.1 | 255.50.1.23 | | 3 | 255.50.1.100 | FF320164 | 2 | 255.50.1.24 | 255.50.1.100 | | 2 | 255.50.1.165 | FF3201A5 | 3 | 255.50.1.101 | 255.50.1.200 | | 4 | 255.50.1.222 | FF3201DE | 4 | 255.50.1.201 | 255.50.4.255 | +----+--------------+-------------+------+--------------+--------------+
-
How to get results of two players stats (home and away)
Barand replied to Newbeeeee's topic in MySQL Help
Whereas that may be a suitable format for a spreadsheet table it is not fit for purpose in a relational database. Further, your choices of column type are totally unsuitable for the data in them. But as you won't be here much longer, that's all you'll get. -
Build your query string with http_build_query() $vals = [ 'id' => 123, 'name' => "Don't do that!" ]; $qstr = http_build_query($vals);