Jump to content

Recommended Posts

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.

image.thumb.png.f9eafc5e41bdfd5ee0ffbf82cb0b6560.pngimage.png.f0038dd46db48e63bf6ced6ffe0aa4e2.png  

 

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 by Barand
obscuring pwd
Link to comment
https://forums.phpfreaks.com/topic/310043-confused-about-graphing-coordinates/
Share on other sites

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>

image.png.e57cdb55ac51405c54827649e9cb50dc.png

Edited by Barand

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.

I got the DB and the entry to go in, as shown...

image.png.3528ade30e8c70f2f069e231e7adc97d.png

 

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... 

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>

image.png.ffa1ddf4db8106d219b6e50cc10c1361.png

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...

image.thumb.png.14c5af46435d727f59739017d4b270d7.png

 

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.

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;  
}     
?>

 

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>

 

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 ....

 

I got ya... yep makes sense now... when update that though I get this

image.thumb.png.00aeba92113306176817c3b7d83a7652.png

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...

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");

 

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 -->

image.thumb.png.c60693406e59623b2249c774f82c3ad7.png

Did that this is the result

image.thumb.png.94e81a7a7c0d076df1766f5b62780c3d.png

 

image.thumb.png.50b83b694f728051e241bfabc4eab489.png

 

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]

 

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>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.