Hi, I am a newbie to pho MySQL scripting and have been banging my head against the wall with serialised queries.
I'm trying to select the rows in a MySQL table into an array and then serialise the output.
This is so I can feed the results dynamically into a tableS
I can get the rows to return to screen, however every time I try to serialise the output I'm getting no output.
I would eternally appreciate any pointers to how to achieve this
Thanks
Steve
Serialised Array Query - newbie
Moderators: egami, macek, gesf
-
- New php-forum User
- Posts: 3
- Joined: Fri Aug 11, 2017 2:21 pm
Apologies, i should have posted the code.
What the aim is to have thep PHP script results dynamically passed to a table plugin i using wordpress, the plugin however doesnt allow the parameterised variables to be set, however it doe support serialized php.
Thanks
Steve
What the aim is to have thep PHP script results dynamically passed to a table plugin i using wordpress, the plugin however doesnt allow the parameterised variables to be set, however it doe support serialized php.
Code: Select all
<?php
/* available system variables */
$current_user = wp_get_current_user();
$groveid = "$current_user->user_login";
$orgid = "$current_user->display_name";
$mysqli = mysqli_connect('****, '****', '****', '*****', 3306);
$query = "SELECT id, tagid,location,category, sublocation, allocated,description,serialno,leased,purchasedate from inventory where disposed = 'no' and orgid = '$orgid'";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
echo $row["tagid"];
echo $row["location"];
echo $row["sublocation"];
echo $row["allocated"];
echo $row["description"];
echo $row["serialno"];
echo $row["leased"];
echo $row["purchasedate"];
}
/* free result set */
$result->close();
}
echo serialize($row);
/* close connection */
$mysqli->close();
?>
Thanks
Steve
Can't you put
into your while loop?
Or just serialize the whole query?
Code: Select all
serialize($row);
Or just serialize the whole query?
-
- New php-forum User
- Posts: 3
- Joined: Fri Aug 11, 2017 2:21 pm
Thankyou for the advice, I will test that approach, to serialise the whole query do I serialise the $result instead of the row.
I'm not totally sure which would be the best / optimal approach.
I'm not totally sure which would be the best / optimal approach.