Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MySQLi get the row using foreach
    primarykey
    data
    text
    <p>I have this function that i created for getting the rows of data from mysqli database.</p> <p>I try to used foreach but the only i got was something like i attached the image please view.</p> <p>oops sorry i can't post image it required me 10 reputation to do that.</p> <p>below : Yes these is what i got <code>1 2 x M M n O O X</code></p> <p>my codes below with form and php</p> <pre><code>## FOR SHORTHAND DATABASE if ( !function_exists( 'hs_debugSQL' ) ) { function hs_debugSQL($hs_db, $string, $debug=0) { if ($debug == 1) print $string; if ($debug == 2) error_log($string); $result = mysqli_query($hs_db, $string); if ($result == false) { error_log("SQL error: ".mysqli_error($hs_db)."\n\nOriginal query: $string\n"); // Remove following line from production servers die("SQL error: ".mysqli_error($hs_db)."\b&lt;br&gt;\n&lt;br&gt;Original query: $string \n&lt;br&gt;\n&lt;br&gt;"); } return $result; } } ## FOR SELECT SQL if ( !function_exists( 'hs_getrows' ) ) { function hs_getrows($sql, $debug=0) { $result = hs_debugSQL($sql, $debug); if($lst = mysqli_fetch_array($result)) { mysqli_free_result($result); return $lst; } mysqli_free_result($result); return false; } } </code></pre> <p>form</p> <pre><code>&lt;label for="message_title"&gt;Send to Admin &lt;span class="red"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;input id="name" name="user_to" class="text" /&gt; &lt;select name="user_to"&gt; &lt;?php global $hs_db; $get_list_admin = hs_getrows( $hs_db, "SELECT * FROM hs_users WHERE user_control = 'admin' " ); foreach ( $get_list_admin as $keys ) { echo '&lt;option value="'.$keys['user_login'].'"&gt;'.$keys['user_login'].'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; </code></pre> <p>connection from mysqli is fine as you can see i can get the data from mysqli. but when i used foreach to retrieve the data it only show 1 number and sometimes 1 character.</p> <p>i like to learn what is wrong with my codes for foreach.</p> <p>thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload