Reputation:
I'm querying a DB and want that query in string format, not object so what I've been doing is:
$StringHolder = "";
$sql = (some sql)
$result = mysqli_query($conn, $sql);
if($row = mysqli_fetch_row($result)){
$StringHolder = $row;
}
$StringHolder = implode($StringHolder);
Is there a better way to go about doing this? As you can probably tell I'm very new to this PHP.
So, one of my actual chunks of code is:
$connection = mysqli_connect($server,$username,$password,$databaseBuilding);
$tenantIdSql= "SELECT tenant_id FROM rooms WHERE room_num = '".$roomNum."'";
$tenantIdObj= mysqli_query($connection, $tenantIdSql);
$tenantID = "";
if($row = mysqli_fetch_row($tenantIdObj){
$tenantID = $row;
}
$tenantID = implode($tenantID);
Upvotes: 1
Views: 36
Reputation: 61
you just need to replace $tenantID = $row;
with $tenantID = $row['tenant_id'];
and if that is not working well then try $tenantID = $row[0];
Upvotes: 0
Reputation: 34914
Try something like this
$tenantID_array = array();
if($row = mysqli_fetch_row($tenantIdObj){
$tenantID_array[] = $row['tenant_id'];
}
$tenantID_str = implode(",",$tenantID_array);
echo $tenantID_str;
Upvotes: 1