Getting Date from Subscription Data from Braintree Payments - php

I'm probably missing something obvious; I'm trying to get the date from the returned data from setting up a subscription with Braintree Payments. My code is as follows:
$result1 = Braintree_Subscription::create($subscriptionData);
if ($result1->success) {
echo("Subscription ID: " . $result1->subscription->id . "<br />");
echo("Transaction ID: " . $result1->subscription->transactions[0]->id . "<br />");
echo("Type: " . $result1->subscription->transactions[0]->amount . "<br />");
//next line has error!!!!!!
echo("Date: " . $result1->subscription->billingPeriodEndDate . "<br />");
The first three "echo's" return what they are supposed to without problem. If I try and get any date value e.g: billingPeriodEndDate, billingPeriodStartDate, createdAt, updatedAt the page just fails, (nothing more is displayed) but there is no error. Error reporting is switched on. Any help appreciated.
If I remove the line where the error is and add the following below
echo "<ul>";
foreach ($result1 AS $item) {
echo "<li>" . $item . "</li>";
}
Then I can see the entire contents of the array. But I still cannot pull the bit I need out. The date is in the format:
billingPeriodEndDate=Friday, 01-Jan-16 00:00:00 UTC,
As it contains a comma that may be the problem...?
Thanks

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
The date attributes return a DateTime object. Try formatting the date, you may be getting a Object of class DateTime could not be converted to string error.
echo("Date: " . $result1->subscription->billingPeriodEndDate->format('Y-m-d H:i:s') . "<br />");
Let me know if that helps!

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
Without knowing the exact error I would guess that there is no default timezone set. Try setting one and see if it works.
date_default_timezone_set("America/Chicago")

Related

Is it possible to reverse a concatenated/? string. making it into a single (changed) variable

I split this string ($messageText) using a formula like this:
list($msgat, $message) = explode("!", "$messageText", 2);
selecting a row from my database:
with this:
$sql = "SELECT verse FROM ".$datatable." WHERE book LIKE '%".$message."'";
I need to come up with a way to make this: (which works, on a page echoing)
echo " " . $row["book"]. " " . $row["verse"]. "<br>";
something back into a single string: something like this I've been trying.
$answer = " . $row["verse"]. "
thus, I would be able to use the original but changed, variable elsewhere.
I have tried various methods, trying to concoct a solution...
$answer = $row["verse"] ;
etc etc... I am stumped... it is probably right before me I just can't find it.
$answer = " " . $row["book"]. " " . $row["verse"]; //this will store value into single variable answer
echo $answer; // use this if you want to display the result on the page.
this will definitely work if not show us the error so that we can resolve it.

Teamspeak 3 Framework

I'm trying to get all clients database id, but I've been unable to using foreach etc as it always returns the value as NULL.
I need to get a foreach with the database ids and put it in an array
$userchannel = $clients->cid->clientList["client_database_id"];
After some fiddling i managed to get this to work, please verifiy. If you have questions regarding the code. Feel free to ask them.
What i've done in basic is modifing the existed code from the examples shown in the teamspeak php framework site. I used the Android user list for the most code. From there on its just trying and debugging ;)
this code will print the database id of the user together with the username. (Ofcourse from this point you can do everything you want with it.)
Also, maybe take a quick look at the api documentation for the php framework. It has alot of useful coding tips and tricks.
https://docs.planetteamspeak.com/ts3/php/framework/
edit (07-01-17)
Something I also noticed, make sure the query user has enough rights, for ease I made mine server admin query (grants access to all options, Please be aware that this could be insecure in a active site!)
<?php
// load framework files
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
try {
// connect to local server, authenticate and spawn an object for the virtual server on port 9988
$ts3_ServerInstance = TeamSpeak3::factory("serverquery://###:#######:##/?server_port=9987");
$selected_sid = $ts3_ServerInstance->serverList();
$ts3_VirtualServer = $ts3_ServerInstance->serverGetById($selected_sid);
/* walk through list of clients */
echo "<table class=\"list\">\n";
echo "<tr>\n" .
" <th>DB id</th>\n" .
" <th>Nickname</th>\n" .
"</tr>\n";
foreach($ts3_VirtualServer->clientList() as $client) {
echo "<tr>\n" .
" <td>" . $client['client_database_id'] . "</td>" .
" <td>" . htmlspecialchars($client) . "</td>" .
"</tr>\n";
}
echo "</table>\n";
}
catch(Exception $e) {
/* catch exceptions and display error message if anything went wrong */
echo "<span class='error'><b>Error " . $e->getCode() . ":</b> " . $e->getMessage() . "</span>\n";
}
I managed to fix it.
$ts3_VirtualServer->channelGetById(152) // 152 is the channel ID

Cannot selecting first row on database php pdo mysql

I couldn't understand what is wrong here. I cannot take the first row on database. I also cannot the data which are single according to $ara parameter. Here are the codes:
$ara =$_POST['ara'];
$query=$db->prepare("SELECT * FROM uyeler WHERE
name like '%".$ara."%' or
surname like '%".$ara."%' or
email like '%".$ara."%'
");
$query->execute(array());
if ($num_row = $query->fetchAll(PDO::FETCH_BOTH)){
echo "<li><a href='profil.php?id=".$num_row['user_id']."'>" .$num_row['name']. " " .$num_row['surname']."</a></li>";
}else{
echo "Hiç birşey bulunamadı!";
}
You need to correct your array call:
from
$num_row['user_id']
To
$num_row[0]['user_id']
Your code is tested and works, nice job.
what you need to correct is the following line:
echo "<li><a href='profil.php?id=" . $num_row[0]['user_id'] . "'>" . $num_row[0]['name'] . " " . $num_row[0]['surname'] . "</a></li>";
If you face such problem in the future, it is a good practice to var_dump the results like:
var_dump($num_row);
This will give you a total raw picture of the content.

How to create a series of DIVs using PHP + mySQL?

I'm looking to create a formatted product list from an SQL database. My aim is to have a store on my website with a series of small boxes containing some shorthand information about each product, that when clicked will open a pop-up containing detailed information. (I have a working Javascript/JQuery code to create the pop-ups.)
Here is the PHP code so far, simply to get the information from the database and display it on a webpage...
(I've been using XAMPP to provide an environment for me to test the code in)
<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("Database1") or die(mysql_error());
$strSQL = "SELECT * FROM Products";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "<br />";
}
mysql_close();
?>
I want the echoed line to be displayed in a divider, with a divider generated for each record in the SQL database (say I have 10 products available, there would be ten dividers, and 10 different boxes on the webpage). The divider's class is "ProductBox".
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
This was the closest I have come to a solution, which was simply managing to write a code with no syntax errors - alas, nothing actually displays on the webpage.
If I'm going about this entirely the wrong way please tell me - I'm fairly sure I need to use a SQL database to dynamically update stock on a live website, but if I need to implement a different programming language or whatever then just tell me what you think would work and help me with a solution.
You have an extra semicolon in your code
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
Replace with
echo "<div class=\"ProductBox\">". $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
mysql_fetch_array needs to be used like this (see PHP Doc):
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
}
or you could just use "mysql_fetch_assoc" instead.
HOWEVER, if you're new to PHP, I HIGHLY RECOMMEND that you get started on the right foot. mysql_query functions are soon to be deprecated. DON'T USE THEM. Most recommend using "PDO" for querying your database. Here's a great tutorial to teach you: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
Also, as mentioned, you have an extra semi-colon.
Dont forget these basics markups :
`<HTML>
<HEAD>
</HEAD>
<BODY> put in here your divs
</BODY>
</HTML>`

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