Is this the proper way to get a string back from an sql query in PHP?

KAT

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);
Niklesh Raut

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;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is this the proper way to get a string back from an sql query in PHP?

From Dev

How to get the proper SQL result from a query

From Dev

Proper way to convert bytea from Postgres back to a string in python

From Dev

Proper way to loop a SQL Query?

From Dev

PHP/SQL get proper array from SQL table

From Dev

Proper way to get string list in JNI

From Dev

Proper way of converting string to long int in PHP

From Dev

Proper way of converting string to long int in PHP

From Dev

not getting link proper from query string

From Dev

Proper way to get the byte array from the JSON

From Dev

Proper way to retrieve data from sessionStorage in php

From Dev

How to pass a string containing back slash and front slash from PHP query page back to JavaScript using AJAX

From Dev

Php create proper String from array

From Dev

how to get a string from a list of string using SQL query

From Dev

how to get a string from a list of string using SQL query

From Dev

How to execute MySQL query through PHP in the proper way?

From Dev

What is the proper way in ColdFusion to return a Query object from Java?

From Dev

Proper Way to Escape Quotes in HTML string that includes PHP variables

From Dev

Proper way of using file_get_contents() PHP function

From Dev

Proper way to count the exact no. of rows in SQL using PHP PDO

From Dev

Get first letters from a string of two words (PHP - fastest way)

From Dev

Is there a way to get a Callable back from a FutureTask?

From Dev

Need Help in sql query to get substring from string value

From Dev

SQL query to get char from string based on criteria

From Dev

What is the proper way to construct a BigInteger from an implied unsigned hexadecimal string?

From Dev

What is the proper way to go from a String to a *const i8?

From Dev

How to match a word from string and retrieve data in SQL Query and PHP?

From Dev

Proper way to get an array of values from Doctrine2

From Dev

Proper way to (get from /insert into) table using Erlang Mysql Driver

Related Related

  1. 1

    Is this the proper way to get a string back from an sql query in PHP?

  2. 2

    How to get the proper SQL result from a query

  3. 3

    Proper way to convert bytea from Postgres back to a string in python

  4. 4

    Proper way to loop a SQL Query?

  5. 5

    PHP/SQL get proper array from SQL table

  6. 6

    Proper way to get string list in JNI

  7. 7

    Proper way of converting string to long int in PHP

  8. 8

    Proper way of converting string to long int in PHP

  9. 9

    not getting link proper from query string

  10. 10

    Proper way to get the byte array from the JSON

  11. 11

    Proper way to retrieve data from sessionStorage in php

  12. 12

    How to pass a string containing back slash and front slash from PHP query page back to JavaScript using AJAX

  13. 13

    Php create proper String from array

  14. 14

    how to get a string from a list of string using SQL query

  15. 15

    how to get a string from a list of string using SQL query

  16. 16

    How to execute MySQL query through PHP in the proper way?

  17. 17

    What is the proper way in ColdFusion to return a Query object from Java?

  18. 18

    Proper Way to Escape Quotes in HTML string that includes PHP variables

  19. 19

    Proper way of using file_get_contents() PHP function

  20. 20

    Proper way to count the exact no. of rows in SQL using PHP PDO

  21. 21

    Get first letters from a string of two words (PHP - fastest way)

  22. 22

    Is there a way to get a Callable back from a FutureTask?

  23. 23

    Need Help in sql query to get substring from string value

  24. 24

    SQL query to get char from string based on criteria

  25. 25

    What is the proper way to construct a BigInteger from an implied unsigned hexadecimal string?

  26. 26

    What is the proper way to go from a String to a *const i8?

  27. 27

    How to match a word from string and retrieve data in SQL Query and PHP?

  28. 28

    Proper way to get an array of values from Doctrine2

  29. 29

    Proper way to (get from /insert into) table using Erlang Mysql Driver

HotTag

Archive