Serialised Array Query - newbie

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
Smason1974
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Aug 11, 2017 2:21 pm

Fri Aug 11, 2017 2:27 pm

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

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 525
Joined: Mon Feb 22, 2016 5:52 pm

Fri Aug 11, 2017 2:50 pm

What do you mean by "serialise the output"?

And it would help if you showed your script using the [</>] button on the 'Post a reply' box

Smason1974
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Aug 11, 2017 2:21 pm

Sat Aug 12, 2017 5:25 am

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.

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

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 525
Joined: Mon Feb 22, 2016 5:52 pm

Sat Aug 12, 2017 7:43 am

Can't you put

Code: Select all

serialize($row);
into your while loop?

Or just serialize the whole query?

Smason1974
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Aug 11, 2017 2:21 pm

Sat Aug 12, 2017 1:38 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.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 525
Joined: Mon Feb 22, 2016 5:52 pm

Sun Aug 13, 2017 3:04 am

Try them both, and see which one makes more sense.

Post Reply