Reputation: 741
I'm using this to get MySQL results into an array
$var = array();
$sql = "SELECT doc as document ,part, `desc`, price, qty, total FROM parts LIMIT 10";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
That works great. Is it possible to add a value to each row? Something like
$var = array();
$sql = "SELECT doc as document ,part, `desc`, price, qty, total FROM parts LIMIT 10";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
array_push($var['url'] = $url);
}
Upvotes: 0
Views: 871
Reputation: 5039
You should append url into $obj and then store $obj into $var array:
while($obj = mysqli_fetch_object($result)) {
$obj->url = $url; // first store url into obj
$var[] = $obj;
}
Upvotes: 2
Reputation: 1130
Hope this will help.
while($obj = mysqli_fetch_object($result)) {
$var[] = array($obj,'url'=>$url);
}
Upvotes: 0