QRcode after scan redirect to custom link - php

I'm working with QRcode at the moment so far it's so good i can scan it and get a result back from the database.
Im getting the data as follow :
$qrcode = QRcode::png('
number:' . $number. '
Name: ' . $name. '
Lastdate : ' . $lastdate . '
check: ' . $check. '');
My question is how can i scan the QRcode and redirect it to an custom link and display it on the website
Thanks,
Kevin

Recently i have made one application like your requirement only. what you need to do is, what ever data displaying through QR code that data insert into database then you will get one record id and using that record id you can make custom URL with creating new php page.
your code:
$qrcode = QRcode::png('
number:' . $number. '
Name: ' . $name. '
Lastdate : ' . $lastdate . '
check: ' . $check. '');
my suggested code:
array('number' => $number,
'Name '=>$name,
'Lastdate '=> $lastdate,
'check '=> $check);
Insert this array into your database
grab inserted recored id.
$custome_URL = "www.yourwebsitename.com/qrcode_scanneddata.php?id=$record_id";
$qrcode = QRcode::png("$custome_URL");
when ever you scan the URL automatically it will open in web browser.

You can redirect by code like this
header('Location: '.$qrcode->url);

Related

Trying to load/execute two table values at the same time

I'm trying to create a page that displays content from database when specific title is selected, and all the comments added to it (only comments for the selected title should be visible) by other users. I want make the id and review_id to work together on the same line. I cant create two separate echo's as it creates two separate titles.
I've tried to link the values together but cant make it work.
echo '<li>' . $comment['name'] . ' - ' . $comment['date'] . '</li>';
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
echo '<li>' . $comment['name'] . ' - ' . $comment['date'] . '</li>';
Is there a way to make "id" and "review_id" work at the same line ?

Inserting wrong data in to the database with $wpdb->insert

So hey guys!
I currently have a code that gets data from a custom table called wp_refundrequests, and prints them as a table to the page. On the page the admin can either Accept, or Deny the request by pressing a button on the side of each order. Denying the request just deletes the request from the table, but accepting should delete it from the current table and insert the information to the next table called "accepted requests".
The wp_refundrequests table contains customer's order that they want to refund.
The code that gets the info and prints it:
global $wpdb;
$requests = $wpdb->get_results("SELECT * FROM wp_refundrequests", ARRAY_A);
foreach ($requests as $row) {
echo "<div class='requests'>" . "<li class='refunds'>" . "Palauttajan nimi: ".
$row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
$row['product_qty'] . " "
. "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
"<br>" . "Päivämäärä: " . $row['request_date'] . " " .
"<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Deny</a></li>" .
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
. "'>Accept</a></li>" . "</div>";
$_SESSION['custname'] = $row['customer_name'];
$_SESSION['prodname'] = $row['product_name'];
}
With my current code, the "Accept" button deletes it, and inserts information in to the new table, BUT the information that is inserted is wrong. It seems like it wants to either insert the latest data that had been inserted in to the wp_refundrequests table to the wp_acceptedrequests, or it keeps the data from the latest refund request and tries to insert that instead because for example as seen here(Sorry for the bits of Finnish as well):
If I were to click the "Accept" button on the above, older one, the query would still insert it like this:
So it basically inserts the info from the latest refund_request insert and inserts that instead of the one selected. However the one that had been selected still gets deleted from the table.
Here's the code that is triggered when the user clicks on "Accept"
$custname = $_SESSION['custname'];
$prodname = $_SESSION['prodname'];
if(isset($_GET['acceptid'])) {
$accept = $_GET['acceptid'];
/* Query to do whatever here */
$wpdb->print_error();
$wpdb->insert("wp_acceptedrequests", [
"customer_name" => "$custname",
"name_product" => "$prodname",
"date" => date("Y/m/d/G:i:sa") ,
]);
$wpdb->print_error();
$wpdb->query("DELETE FROM wp_refundrequests WHERE request_id = $accept");
}
I have to say I have no idea why it doesn't want to insert the selected request, please comment if there's something confusing, I'll try to clear it up then.
Thanks in advance!
You redefine $_SESSION with in foreach loop so at the end of foreach it will equal to the last one, pass each row parameter to it is accept link like this
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']."&custname=".$row['customer_name']."&prodname=".$row['product_name']."'>Accept</a></li></div>";
Then call it the same way you get $accept-ID
if(isset($_GET['acceptid'])) {
$accept = $_GET['acceptid'];
$custname = $_GET['custname'];
$prodname = $_GET['prodname'];
Note:Iuse my phone so make sure if it was a syntax error in the href part of the code
Please try like this and comment out the session variable.
if(isset($_GET['acceptid'])) {
$accept = $_GET['acceptid'];
$accepted_requests = $wpdb->get_results("SELECT * FROM wp_refundrequests WHERE id = $accept", ARRAY_A);
if( !empty($accepted_requests) ) {
$insert = $wpdb->insert("wp_acceptedrequests", $accepted_requests);
if($insert) {
$wpdb->query("DELETE FROM wp_refundrequests WHERE request_id = $accept");
}
}
}

How to format mass data pulled from a database?

I am using a PHP script to pull large amounts of entries from a database, it looks like this:
foreach($events as $e){ //sets each set of data as a value of $e
$vidID = $e["Test Video YouTube ID"]; //stores each video ID as this variable, so that it can be called when embedding the video
echo "<br>" . '<iframe width="250" height="140" src="http://www.youtube.com/embed/' . $vidID . '?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>' . "<br>"
. '<strong> DOC: </strong>' . $e["Axial Cut"] . " " . '<strong> IPM: </strong>' . $e["Inches Per Minute"] . "<br>" .
'<strong> WOC: </strong>' . $e["Radial Cut"] . " " . '<strong> FPT: </strong>' . $e["Inch per Tooth"] . "<br>" .
'<strong> SFM: </strong>' . round($e["Surface Feet per Minute"]) . "<br>"; //each value here is displayed. use the form '$e["Column to be dislplayed"].'
This displays each field for the entry I need, then goes to the next entry and does the same, displaying every entry in the database.
My issue is that it only displays them in a vertical line, so what is the best way to format the output in such a way that it displays in a grid, with a set amount of columns?
*EDIT - To clarify, I don't want to use something like a CSS table for this. It limits me in that the data cannot automatically fill into columns, instead each entry would either appear in a single column or I would have to update each field every time the database had a new entry which would be quite tedious. So what is the best way to have data automatically flow into these columns and rows?

Convert data from SQL to string in PHP

Problem:
I am using Google Map API using the link: http://www.phpinsider.com/php/code/GoogleMapAPI/ - and when I try to print out an address on the map manually it will show up but not when selected from a database.
PHP code (this works):
$map->addMarkerByAddress('114 53 Grevgatan 31','The Tudor Arms','<b>The Tudor Arms</b>');
PHP code (this does NOT work):
$location = $row['postalnumber'] . ' ' . $row['address'] . ' ' . $row['city'];
$map->addMarkerByAddress($location , $row['name'],'<b>'. $row['name'] .'</b>');
Desired solution:
To be able to extract data from a table in an SQL database and send it to the Google Map API function.
Additional remarks: When I echo the variables above the address and all information will print out but not when sent to the Google Map API function. Do I need to convert the data into a string?
Yes, you should say google the format like:
$location = $row['postalnumber'] . ' ' . $row['address'] . ' ' . $row['city'];
$map->addMarkerByAddress("'".$location."'", "'".$row['name']."'","'<b>". $row['name'] ."</b>'");

Most efficient way to get last initial?

I'm working on a custom forum. It will use an email and password to log in, and the forum will display your first name and last initial. The database stores their first name and full last name.
What would be the easiest way to make it abbreviate the last name to an initial?
It currently uses this to display full name:
$name = $row['user_firstname'] . " " . $row['user_lastname'];
Thanks!
$name = $row['user_firstname'] . " " . $row['user_lastname'][0];
Just add [0] to the end to get the first character.
And to make it prettier:
$name = ucfirst(strtolower($row['user_firstname'] )). " " . ucfirst($row['user_lastname'][0]);
so MYFIRSTNAMe lastName still shows as MyfirstnameL

Categories