I have this in my functions.php file
function getUserOrders($userId){
global $conn;
$query = "SELECT * ";
$query .= "FROM orders ";
$query .= "WHERE userid=" . $userId . " ";
$odrset = mysqli_query($conn, $query);
while ($odr = mysqli_fetch_assoc($odrset)){
return $odr;
}
}
What should I do in the orders.php file is to display certain fields and their values from the $ odr returned array, since this fragment offers
$userId = sql_prep($_SESSION['userid']) ;
getUserOrders($userId);
echo $odr['title'].$odr['orderid'].'<br>'
I can only do this in the functions.php file ...
function getUserOrders($userId){
global $conn;
$query = "SELECT * ";
$query .= "FROM orders ";
$query .= "WHERE userid=" . $userId . " ";
$odrset = mysqli_query($conn, $query);
confirm_query($odrset);
while ($odr = mysqli_fetch_assoc($odrset)){
echo $odr['title'].$odr['orderid'].'<br>';
}
}
.. and call it in the orders.php file as follows:
$userId = sql_prep($_SESSION['userid']) ;
getUserOrders();
which is not very good, since I need to rework the function somewhere else and display different fields and their values. So I need $ odr to return as an array in my order.php
source
share