-1

I need help converting an array to sting -> i only need the value from the database.

inserting into DB

$sql = "INSERT INTO tickets1 (lastName, firstName, Address, policyNo, IdNumber, Test, Medicals)
VALUES ('$last', '$first', '$Address', '$policyNo', '$IdNumber', '$Tests', '$medical');";


mysqli_query($connect, $sql);

Pulling data i put into db table

 $result = $connect->query("SELECT TicketID FROM tickets1 where IdNumber = '$IdNumber'");

creating an array with the data

$meds = array();
while ($rows = mysqli_fetch_assoc($result)){
    $meds[] = $rows;
}
$meds1 = print_r($meds, true); // <- convert to an array 

I have tried json_encode(), var_dump, implode but it does not give me the value in the database.

Instead it gives me :

array(1) { 
    [0]=> array(1) { 
        ["TicketID"]=> string(2) "72" 
    } 
} 
Array ( 
    [0] => Array ( 
        [bloodID] => 1 
    ) 
)

Any ideas

7
  • Are you trying to create an object or a string? Jan 20, 2020 at 19:49
  • 2
    Where does bloodID come from? There's nothing like that in your code.
    – Barmar
    Jan 20, 2020 at 19:50
  • Do you expect $result to ever have more than one row? Do you expect $meds to ever have more than one row? Which array are you wanting to be as a string? Jan 20, 2020 at 19:51
  • The bloodID comes from the DB Jan 20, 2020 at 19:51
  • @FrancescoManicardi i am trying to pull the ID from the db table and place that into another table into the db based on a condition Jan 20, 2020 at 19:52

1 Answer 1

1

Just push the column you want into the array, not the whole row:

$meds[] = $rows['TicketID'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.