Hi everyone in the database a column called attachments stores data like this
"a:3:{s:6:\"saveTo\";s:7:\"wpmedia\";s:14:\"attachmentType\";s:6:\"images\";s:11:\"attachments\";a:1:{i:0;a:6:{s:12:\"attachmentId\";i:176165;s:4:\"file\";s:68:\"https://www.yallamission.com/wp-content/uploads/2022/10/MG_00283.jpg\";s:8:\"fileName\";s:12:\"MG_00283.jpg\";s:9:\"thumbnail\";s:76:\"https://www.yallamission.com/wp-content/uploads/2022/10/MG_00283-150x150.jpg\";s:8:\"fileSize\";s:9:\"292.85 KB\";s:8:\"fileType\";s:10:\"image/jpeg\";}}}
i need to fetch the image url only yet i am unable to do it successfully as i don't understand this format
I tried to use php functions and substr() yet the text before and after has dynamic content and no fixed standard.
This is serialized data and you can unserialize them and access the attachments by using unserialize($variable) and access the attachment elements.
Use json_encode instead of serialize when building the data for INSERTing. Then use the JSON functions in SQL (if your MySQL is new enough).
Related
I am looking to store HTML in a MySQL database, this will be added via a WYSIWYG editor on a webpage and posted via php to a MySQL database. This HTML is used to display news articles on a website. So what is the correct way of storing and returning this, I don't want to remove HTML so I guess it's a straight insert via pdo bind parameters and then just select and display on the webpage when returning? Or should I be using any functions to encode/ make safe the HTML code.
Also as part of this I also need to return the news articles for a mobile app in a JSON api, I will use json_encode function on the returned data but should I be running any make safe functions on that too?
Thanks
Save html into database directly as text received as post data
$htmlcontents = $_POST['htmlcontents'];
insert into db
$query = 'INSERT INTO dbname (htmlcontents) values('.$htmlcontents.')';
run the insert query
getting the stored html contents
$query = 'SELECT htmlcontents from dbname';
save the htmlcontents from database into a variable $htmlcontents.
sent the html as json to the client
print json_encode(array('htmlcontents' => $htmlcontents));
use this json and append the htmlcontents to body
$(body).append(response.htmlcontents);
I have a database hosted on server whose field values have to be passed to my app. I would like to do with PHP. But people suggest me to use JSON too. Is JSON required? Please guide me how to pass the field values to android app.
JSON means JavaScript Object Notation and it's just a way of formatting your output in a standard way.
So, if you'd like to pass data from a database to an application, you'd need to implement a small API. This can be done using PHP. At this point, you can access data from your database using a browser and parametrizing your queries using url parameters.
PHP can render the data in a simple HTML table for example, but this is just a way of presenting your data. You can also use JSON.
This means that if you need the badges a user has earned, you'll use something like this:
<link_to_your_api>/index.php?method=getBadges&user=<user>
This in turn, will make a request to the database
<?php
// 1. connect to database
// 2. query for the information
// 3. get the result as array
$result = $db->getData();
echo json_encode($result);
?>
This is just an example, hope it helps.
link to json documentation: http://www.json.org/
You pass the data to your app, when it makes a request to your PHP script. JSON is handy because you can package your data in a format, that is both well readable by humans and machines. You can use the gson library then, to process the JSON data in your app.
Create REST api using any server side script PHP,nodejs or any you like which returns JSON response
call the rest api using http request which returns JSOn text
decode the JSON string to JSON object and use with your android code
I have absolutely no Idea what to do so please help me.
I have a Database Table that contains BLOB for Image, text, numeric fields.
I have accomplished to retrieve the data from the Table by sending a request from Javascript to PHP tru AJAX by this steps.
Create a AJAX request from javascript using POST method . I passed the SQL fom the post method.
Process the $_POST["SQL"] and retrieve the data from mysql database. Using mysqli_query.
I use mysqli_fetch_array to convert the result to an associative array.
I use echo json_encode to have a JSON string as an output then echo it.
My problem starts here since the field that contains the BLOB image has 'null' value while other fields behave perfectly fine.
Take note that I'm not only retrieving the Image field but multiple fields.
I'm new to web development and I am using Javascript( not Jquery ) and PHP.
What should I do?
Thank you in advance!
I have to list the table entries from mysql in my iPhone app when a button is pressed. I am able to do it properly but it is just not the way I want it. I am using a PHP script to send Xcode what has to be printed.
First, I tried doing it using HTML table, but I didn't like the way it was printed with cells. Next I tried printing plain text by giving spaces(between columns) and \n for every new row. I used NSURL and loaded the webView to the iPhone. Looks good on browser but the same is not preserved when the iPhone tries to open it.
Is there a good way to do this? So I can just list the table entries without having to go through the traditional HTML table or any other idea is welcome.
Also, please try to be easily understood, as I am new to Obj-C, and PHP as well.
Thanks!!
Any thoughts on how I can do this in a UITableView..?? Do I have to return a string with component separation characters and fill in the tableView?
Output the results encoded in JSON. Send an a(sync) request to the server using NSURLConnection or using a third-party library such as AFNetworking. Parse the JSON using NSJSONSerialization, turning the results into an array/dictionary depending on the contents. Then parse the results into the UITableViewCell. It may be easier to subclass the cell so that you include the data that you'd like to use.
To encode the results from the database into JSON, you can use the method json_encode().
I had developed an Application in android in which I fetch some data from MYSQL database and do some operations on it and store it in SQLite.Now I want to send all the data stored in SQLite to MYSQL.I know i need to use JSON there.I will store my result in Cursor say
Cursor c="select * from emp" (just example)
now how i will parse this cursor into String to send it to the php page? and how i will decode it there?? Please help me.
If what you are asking is how you can encode data and send it to php as GET parameter you could use the following:
$encoded=base64_encode(serialize($data))
and then call example.com/?data=$encoded
where $data could be the query result from $data=$sth->fetchAll(PDO::FETCH_ASSOC);
and on the receiving end:
$decoded=unserialize(base64_decode($_GET['data']))
but this will limit you to about 2K of data.
If you can use POST, then use POST.