Trouble with MySQL code on WordPress

I'm working on a custom functions.php file for simplified templating on WordPress. Works great on my localhost but on a clients server it doesn't seem to be doing the MySQL... No error is being displayed so it is connecting correctly. But it isn't reading the variables in the foreach()...

Below is a sample of the code. The echo $result displays nothing. The echo "HELLO WORLD!<BR/>" prints on the screen 5 times. No matter what the query it seems to print 5 times...

$db_connect = mysqli_connect( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME ) OR die ( 'Could not connect to MySQL: ' . mysqli_connect_error() );

$query = '
        ' . $table_prefix . 'options

$results = mysqli_query( $db_connect, $query );

foreach( $results as $result ) {
    echo $result;
    echo "HELLO WORLD!<BR/>";


You beat me Akam, indeed its missing the

while($row = mysqli_fetch_array($results)) { .. }

You missed to fetch the results using mysqli_fetch_assoc() or mysqli_fetch_array()

if ($results = mysqli_query($db_connect, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {

    /* free result set */
Tags: PHP / Mysql / Wordpress

Similar questions

WebSite Hacked: Trouble Understanding Infected Php Code
By the way I am using WordPress, and the file containing this is being required by wp-config. I have identified that the source code below is responsible for the redirection of our website to another site.I tried understanding the code but was really confused how its being coded. I can only understand base64_decode. Here is the snippet: ...
Trouble for newbie with header code
I'm a newbie to code and pretty well illiterate. I have inserted some code into my customized header file only to realize it was the wrong place. I since received this error message when i try to get onto my website Parse error: syntax error, unexpected '$', expecting variable (T_VARIABLE) in /home2/seth1/public_html/wp-content/themes/TESSERACT/inc...
[code][/code] tags changes the posted code
I wanted to add codes to my hosted blog in a code friendly way. So I found this page since I can't use plugin. First this worked as promised. But later I checked the blog's code it has been change some codes replaced with symbols like below one &lt;servlet&gt; I don't...
If the only thing I use MySQL for is Wordpress, do I need MySQL's timezone tables?
The only thing I have MySQL around for is Wordpress. Some MySQL features, I gather, require you to import the system timezone database into special tables in the mysql database. (Which seems like a silly way to do things, but never mind.) Does Wordpress make use of any of those features? The MySQL global time zone is set to 'SYSTEM', and the server...
where I am going wrong in this MySQL query for wordpress Mysql?
I want to get the list of posts through this query. Can anyone can solve this query?
How to order my MySQL records ? | MySQL - WordPress
I am creating a website, for a client based on WordPress. My client want's in home page to display articles grouped under categories. In example, let's say we have the categories "Cat A", "Cat B" and "Cat C". My client want's to display the categories order in the following way "Cat B", "Cat A" and "Car C", in the home page, and then list 6 post fr...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.