winuser2003 Posted February 16, 2020 Share Posted February 16, 2020 (edited) Hi, I am working on a project that involves mobile (android) and the application being designed connects to the database within PHPMYADMIN storing some table data entries. The language on the app being used is Flutter / DART and I do apologize, I am not familar at all with this language and my collegue has been writing his mobile code in this. I am the one who is going in and writing the PHP code that tells the data from the mobile app to be stored in a table. Hopefully this makes sense to you all still... Now... as shown below a diagram of how we have this app kicking and talking. Thank for whom all can assist with this, but this is really the last piece of the puzzle then the app is finally done. php output code: <!DOCTYPE html> <html> <head> <title>Test</title> <style> table { border-collapse: collapse; width: 100%; color: #588c7e; font-family: monospace; font-size: 25px; text-align: left; } th { background-color: #588c7e; color: white; } tr:nth-child(even) {background-color: #f2f2f2} </style> </head> <body> <table> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> <th>Image</th> </tr> <?php $conn = mysqli_connect("localhost", "****", "****", "pmapp"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT id, first_name, last_name FROM pmvisit"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id"]. "</td><td>" . $row["first_name"] . "</td><td>" . $row["last_name"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> </html> Edited February 16, 2020 by Barand obscuring pwd Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/ Share on other sites More sharing options...
Barand Posted February 16, 2020 Share Posted February 16, 2020 (edited) OK, I'm going to stick my neck out and assume I know what you are talking about. I am guessing that the columns sign_x and sign_y contain coordinates and that you want to put them into (x,y) pairs and join the dots. If I'm right, here's an example. If I'm wrong, well, it was fun but you need to explain a little more.. $db->exec("CREATE TABLE IF NOT EXISTS `winuser_demo` ( `userid` int(11) NOT NULL AUTO_INCREMENT, `fname` varchar(20) DEFAULT NULL, `lname` varchar(20) DEFAULT NULL, `sign_x` varchar(500) DEFAULT NULL, `sign_y` varchar(500) DEFAULT NULL, PRIMARY KEY (`userid`) ) "); $db->exec("INSERT IGNORE INTO winuser_demo (userid,fname,lname,sign_x,sign_y) VALUES (1, 'Tom', 'Di Canari', '0,0,100,100,0,50,100,0', '100,20,20,100,20,0,20,100'); "); $tdata = ''; $res = $db->query("SELECT userid , fname , lname , sign_x , sign_y FROM winuser_demo "); foreach ($res as $r) { $tdata .= "<tr><td>{$r['userid']}</td> <td>{$r['fname']}</td> <td>{$r['lname']}</td> <td>" . drawImage($r['sign_x'], $r['sign_y']) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$w' height='$h' > <path d='$path' stroke='#000' fill='none'/> </svg>"; return $im; } ?> <!DOCTYPE html> <html> <head> <style type="text/css"> table { border-collapse: collapse; width: 60%; } th { background-color: black; color: white; padding: 8px; text-align: left; } td { padding: 4px 8px;; } </style> </head> <body> <table border="1" style="width: 60%;"> <tr><th>ID</th> <th>First name</th> <th>Last name</th> <th>Image</th> <tr> <?=$tdata?> </table> </body> </html> Edited February 16, 2020 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574334 Share on other sites More sharing options...
winuser2003 Posted February 16, 2020 Author Share Posted February 16, 2020 That is correct, because whats happening is at the very end of the phone application process, I take my finger and sign into a input field, which basically is my signature. Once submitted the signature is translated into coordinates in the database table as you can tell. All I want is the signature to show up on the php page itself like you have in your example. Definitely on the right track, I will try this. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574337 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 I got the DB and the entry to go in, as shown... will I need to create something in regards like a connectdb.php? cause the output on the php page is giving an error when I run this script and I know its just showing part of the code... maybe I am missing something in the obvious here... error I get $tdata = ''; foreach ($res as $r) { $tdata .= "{$r['userid']} {$r['fname']} {$r['lname']} " . drawImage($r['sign_x'], $r['sign_y']) . "\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = maybe a version conflict? just trying to replicate your demo... Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574369 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 8 minutes ago, winuser2003 said: ...is giving an error What is the error message? Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574370 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Again, I am sure this is something obvious I am missing here... Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574371 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 I think the issue is doesn't PDO use the DB-> exec command? thinking this is a versioning problem because I am using sqlite, and not sure at this point if that matters or not. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574372 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 The first parts of the code, which use ->exec(), can be thrown away once you have your data table. (I just used those to create the db table and test data) You will need to set up your own connection to SQLite and use that. Meanwhile here is a DB-less version that generates sign_x and sign_y data for random squiggles. <?php $tdata = ''; for ($i=1; $i<=10; $i++) { $tdata .= randomSignature($i) ; } function randomSignature($i) { $n1 = mt_rand(1, 15); $n2 = mt_rand(1, 15); $x = $y = []; for ($a = 1; $a < 360; $a++) { $x[] = $a; $y[] = round(35 + sin(deg2rad($n1 * $a)) * 15 - cos(deg2rad($n2 * $a)) * 15); } $sx = join(',',$x); $sy = join(',',$y); return "<tr><td>$i</td><td>$n1</td><td>$n2</td><td>" . drawImage($sx, $sy) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+1; $h = max($ya)+1; $scaled_h = 50; $scaled_w = $scaled_h * $w / $h; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$scaled_w' height='$scaled_h' viewBox='0 0 $w $h'> <path d='$path' stroke='#000' stroke-width='1' fill='none'/> </svg>"; return $im; } ?> <!DOCTYPE html> <html> <head> <style type="text/css"> table { border-collapse: collapse; width: 60%; } th { background-color: black; color: white; padding: 8px; text-align: left; } td { padding: 4px 8px;; } </style> </head> <body> <table border="1" style="width: 60%;"> <tr><th>ID</th> <th>N1</th> <th>N2</th> <th>Image</th> <tr> <?=$tdata?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574373 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Your DB version is exactly what I am looking for, just for some reason when I apply the sample code for testing on my side... I get this... I am trying to figure out why and it maybe due to versioning? maybe a newer version of sql? cause really all it could be is the DB is created, copy and paste the script into a test .php file and see if you see the output.... am I wrong? I do apologize for my ignorance here... it gets frustrating at times. If you look at the first post you will see I am using sqli $conn = mysqli_connect("localhost", "****", "****", "pmapp"); creating my connection. Maybe I can modify the first example you gave me to do that? I do apologize I meant mysqli NOT mysqlite.. .. poorly chosen words. Your first example though is right on what I am looking for. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574393 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 maybe I need to do something like this --- <?php $conn = mysqli_connect("localhost", "****", "****", "pmapp"); $tdata = ''; $res = $db->query("SELECT userid , fname , lname , sign_x , sign_y FROM winuser_demo "); foreach ($res as $r) { $tdata .= "<tr><td>{$r['userid']}</td> <td>{$r['fname']}</td> <td>{$r['lname']}</td> <td>" . drawImage($r['sign_x'], $r['sign_y']) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$w' height='$h' > <path d='$path' stroke='#000' fill='none'/> </svg>"; return $im; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574395 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 A little progress... since I added that line I get the following error Notice: Undefined variable: db in C:\xampp\htdocs\testtest001.php on line 4 Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\testtest001.php on line 4 --( Not sure why this would error though ) -- there is only 1 member and its calling all the values correctly <?php $conn = mysqli_connect("localhost", "winuser2003", "homer123", "pmapptest"); $tdata = ''; $res = $db->query("SELECT userid , fname , lname , sign_x , sign_y FROM winuser_demo "); foreach ($res as $r) { $tdata .= "<tr><td>{$r['userid']}</td> <td>{$r['fname']}</td> <td>{$r['lname']}</td> <td>" . drawImage($r['sign_x'], $r['sign_y']) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$w' height='$h' > <path d='$path' stroke='#000' fill='none'/> </svg>"; return $im; } ?> <!DOCTYPE html> <html> <head> <style type="text/css"> table { border-collapse: collapse; width: 60%; } th { background-color: black; color: white; padding: 8px; text-align: left; } td { padding: 4px 8px;; } </style> </head> <body> <table border="1" style="width: 60%;"> <tr><th>ID</th> <th>First name</th> <th>Last name</th> <th>Image</th> <tr> <?=$tdata?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574397 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 When you use mysqli, call mysqli_report() before you connect. You will then be notified automatically of any errors encountered in your mysqli code. Your connection is "$conn" so you need to use that and not "$db" in the query call. mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect('localhost', '???', '???', 'pmapp'); $conn->query("SELECT .... Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574398 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 I got ya... yep makes sense now... when update that though I get this Latest Modification --- <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect("localhost", "winuser2003", "homer123", "pmapptest"); $tdata = ''; $res = ""; $conn->query("SELECT userid, fname, lname, sign_x, sign_y FROM winuser_demo"); foreach ($res as $r) { $tdata .= "<tr><td>{$r['userid']}</td> <td>{$r['fname']}</td> <td>{$r['lname']}</td> <td>" . drawImage($r['sign_x'], $r['sign_y']) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$w' height='$h' > <path d='$path' stroke='#000' fill='none'/> </svg>"; return $im; } //////NOTES//// The $res is whats confusing me the original shows $res = $db->query("SELECT userid , fname , lname , sign_x , sign_y FROM winuser_demo "); I removed the DB query and reformatted it like shown, but I know that will not effect it... however I am wondering about the invalid argument error its throwing now. I bet I broke that $res statement .... didn't I... Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574399 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 2 minutes ago, winuser2003 said: $res = ""; $conn->query("SELECT userid, fname, lname, sign_x, sign_y FROM winuser_demo"); should be $res = $conn->query("SELECT userid, fname, lname, sign_x, sign_y FROM winuser_demo"); Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574400 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Yep I knew it... now its working as expected.... Time for a cigarette thanks so much for your help... if you have PP I be glad to donate for your time. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574401 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 1 minute ago, winuser2003 said: if you have PP I be glad to donate for your time. There are links to PP in all my posts if you insist. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574402 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Might if I pick your brain a little more?? its not much... Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574404 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 I had just received the notification from PP. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574405 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 1 minute ago, winuser2003 said: Might if I pick your brain a little more?? its not much... Go Ahead. If it is a different problem then you should start a new topic. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574406 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 question 1 : is there a set limit to these coordinates? example signatures will have about 1000 points that it will need to graph out this is sign_x [44, 44, 44, 45, 45, 45, 45, 45, 45, 43, 42, 41, 40, 39, 39, 39, 37, 37, 37, 37, 37, 37, 37, 39, 40, 43, 47, 47, 49, 51, 52, 52, 53, 54, 55, 57, 58, 59, 64, 68, 73, 80, 85, 89, 93, 94, 94, 95, 95, 95, 93, 91, 89, 87, 85, 83, 81, 79, 75, 75, 72, 69, 66, 63, 60, 57, 55, 52, 50, 47, 45, 43, 41, 41, 41, 123, 124, 124, 123, 122, 119, 117, 111, 105, 100, 94, 89, 85, 82, 78, 76, 75, 73, 73, 72, 72, 72, 72, 75, 77, 79, 81, 83, 83, 87, 91, 95, 101, 109, 118, 127, 137, 144, 150, 153, 155, 155, 155, 155, 155, 155, 154, 154, 153, 150, 147, 147, 145, 144, 144, 144, 144, 144, 149, 152, 155, 158, 163, 167, 170, 176, 184, 191, 197, 201, 203, 204, 205, 206, 206, 206, 205, 203, 203, 202, 202, 202, 202, 202, 202, 202, 204, 207, 210, 213, 219, 220, 222, 223, 224, 226, 228, 230, 234, 237, 242, 246, 252, 259, 269, 278, 287, 293, 301, 309, 316, 325, 333, 340, 345, 345, 343, 341, 341, 339, 335, 332, 329, 327, 327, 327, 327, 328, 328, 329, 329, 332, 332, 335, 336, 338, 339, 343, 343, 346, 346] this is sign_y [39, 45, 50, 58, 72, 86, 91, 97, 102, 106, 108, 111, 112, 114, 114, 112, 108, 102, 98, 92, 86, 81, 75, 69, 65, 60, 56, 55, 53, 50, 50, 48, 48, 48, 48, 48, 46, 46, 47, 48, 51, 53, 55, 58, 60, 61, 62, 66, 70, 76, 80, 84, 86, 89, 93, 94, 97, 99, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 72, 72, 71, 69, 68, 65, 64, 62, 61, 61, 61, 61, 61, 61, 62, 64, 64, 66, 68, 71, 76, 81, 86, 92, 94, 96, 100, 102, 102, 104, 104, 104, 104, 104, 101, 98, 94, 91, 86, 84, 80, 78, 76, 74, 73, 72, 71, 70, 69, 71, 75, 76, 82, 86, 92, 95, 98, 102, 105, 108, 108, 110, 111, 111, 111, 110, 106, 102, 98, 94, 91, 88, 84, 82, 79, 77, 74, 71, 70, 68, 68, 66, 66, 65, 64, 63, 62, 62, 59, 58, 57, 57, 56, 56, 56, 56, 58, 58, 60, 61, 63, 64, 66, 68, 68, 68, 68, 68, 65, 63, 59, 55, 51, 50, 47, 47, 48, 50, 51, 52, 55, 57, 58, 60, 59, 58, 57, 56, 55, 55, 54, 53, 52, 51, 50, 50, 48, 47, 47, 46, 46] Problem is if I plot these I get this --> Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574407 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 1 minute ago, Barand said: Go Ahead. If it is a different problem then you should start a new topic. its related to the same project Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574408 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 FYI the more in depth we go with the assistance, the more payment I push out. Being a dev myself, I understand how much time and work it takes.... so I always pay for the help and assistance. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574409 Share on other sites More sharing options...
Barand Posted February 17, 2020 Share Posted February 17, 2020 Change the column type of the sign_x and sign_y columns to TEXT instead of varchar(N). That should give sufficient capacity. Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574410 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Did that this is the result Can you try entering these coordinates in? Sign_X [44, 44, 44, 45, 45, 45, 45, 45, 45, 43, 42, 41, 40, 39, 39, 39, 37, 37, 37, 37, 37, 37, 37, 39, 40, 43, 47, 47, 49, 51, 52, 52, 53, 54, 55, 57, 58, 59, 64, 68, 73, 80, 85, 89, 93, 94, 94, 95, 95, 95, 93, 91, 89, 87, 85, 83, 81, 79, 75, 75, 72, 69, 66, 63, 60, 57, 55, 52, 50, 47, 45, 43, 41, 41, 41, 123, 124, 124, 123, 122, 119, 117, 111, 105, 100, 94, 89, 85, 82, 78, 76, 75, 73, 73, 72, 72, 72, 72, 75, 77, 79, 81, 83, 83, 87, 91, 95, 101, 109, 118, 127, 137, 144, 150, 153, 155, 155, 155, 155, 155, 155, 154, 154, 153, 150, 147, 147, 145, 144, 144, 144, 144, 144, 149, 152, 155, 158, 163, 167, 170, 176, 184, 191, 197, 201, 203, 204, 205, 206, 206, 206, 205, 203, 203, 202, 202, 202, 202, 202, 202, 202, 204, 207, 210, 213, 219, 220, 222, 223, 224, 226, 228, 230, 234, 237, 242, 246, 252, 259, 269, 278, 287, 293, 301, 309, 316, 325, 333, 340, 345, 345, 343, 341, 341, 339, 335, 332, 329, 327, 327, 327, 327, 328, 328, 329, 329, 332, 332, 335, 336, 338, 339, 343, 343, 346, 346] Sign_Y [39, 45, 50, 58, 72, 86, 91, 97, 102, 106, 108, 111, 112, 114, 114, 112, 108, 102, 98, 92, 86, 81, 75, 69, 65, 60, 56, 55, 53, 50, 50, 48, 48, 48, 48, 48, 46, 46, 47, 48, 51, 53, 55, 58, 60, 61, 62, 66, 70, 76, 80, 84, 86, 89, 93, 94, 97, 99, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 72, 72, 71, 69, 68, 65, 64, 62, 61, 61, 61, 61, 61, 61, 62, 64, 64, 66, 68, 71, 76, 81, 86, 92, 94, 96, 100, 102, 102, 104, 104, 104, 104, 104, 101, 98, 94, 91, 86, 84, 80, 78, 76, 74, 73, 72, 71, 70, 69, 71, 75, 76, 82, 86, 92, 95, 98, 102, 105, 108, 108, 110, 111, 111, 111, 110, 106, 102, 98, 94, 91, 88, 84, 82, 79, 77, 74, 71, 70, 68, 68, 66, 66, 65, 64, 63, 62, 62, 59, 58, 57, 57, 56, 56, 56, 56, 58, 58, 60, 61, 63, 64, 66, 68, 68, 68, 68, 68, 65, 63, 59, 55, 51, 50, 47, 47, 48, 50, 51, 52, 55, 57, 58, 60, 59, 58, 57, 56, 55, 55, 54, 53, 52, 51, 50, 50, 48, 47, 47, 46, 46] Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574412 Share on other sites More sharing options...
winuser2003 Posted February 17, 2020 Author Share Posted February 17, 2020 Updated working code -- other than the coordinate error we are getting now- --- : <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect("localhost", "winuser2003", "homer123", "pmapptest"); $tdata = ''; $res = $conn->query("SELECT userid, fname, lname, sign_x, sign_y FROM winuser_demo"); $conn->query("SELECT userid, fname, lname, sign_x, sign_y FROM winuser_demo"); foreach ($res as $r) { $tdata .= "<tr><td>{$r['userid']}</td> <td>{$r['fname']}</td> <td>{$r['lname']}</td> <td>" . drawImage($r['sign_x'], $r['sign_y']) . "</td>\n"; } function drawImage($xcoords, $ycoords) { $xa = explode(',', $xcoords); $ya = explode(',', $ycoords); $w = max($xa)+10; $h = max($ya)+10; $path = "M $xa[0] $ya[0] "; unset($xa[0], $ya[0]); foreach ($xa as $i => $x) { $y = $ya[$i]; $path .= "L $x $y "; } $im = "<svg width='$w' height='$h' > <path d='$path' stroke='#000' fill='none'/> </svg>"; return $im; } ?> <!DOCTYPE html> <html> <head> <style type="text/css"> table { border-collapse: collapse; width: 60%; } th { background-color: black; color: white; padding: 8px; text-align: left; } td { padding: 4px 8px;; } </style> </head> <body> <table border="1" style="width: 60%;"> <tr><th>ID</th> <th>First name</th> <th>Last name</th> <th>Image</th> <tr> <?=$tdata?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/#findComment-1574413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.