-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
WordPress-Theme Twenty Twenty Four-customizing: how to do that - a Gutenberg special question...
By thedhubs,
- 1 answer
- 1,752 views
-
- 0 replies
- 12 views
-
- 3 answers
- 5,085 views
-
QNAP issues patch for an RCE security vulnerability affecting PHP in NAS Drive management
By Alap Naik Desai,
- remote code execution
- rce
- (and 12 more)
- 0 replies
- 18 views
-
Get this Dynamic 2022 Data & IT Security Training Bundle at 97% off
By News Staff,
- neowin deals
- cyber security
- (and 4 more)
- 0 replies
- 12 views
-
Question
generalt
I am trying to make a query from functions.php, but I get the following error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in .../functions.php on line 60
Here is functions.php:
<?php function inline($symbol){ GLOBAL $dbc; require_once ('mysqli_connect.php'); $inline_display = "error"; $q = "SELECT rating WHERE symbol = '$symbol'"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r)){ $rating = $row['rating']; } if($rating == 1) $inline_display = "$symbol - <font color=\"#ff0000\"><b>Avoid</b></font>"; if($rating == 2) $inline_display = "$symbol - <font color=\"#990000\"><b>Risky</b></font>"; if($rating == 3) $inline_display = "$symbol - <font color=\"#666666\"><b>Neutral</b></font>"; if($rating == 4) $inline_display = "$symbol - <font color=\"#006600\"><b>Compelling Buy</b></font>"; if($rating == 5) $inline_display = "$symbol - <font color=\"#ff6600\"><b>Top Pick</b></font>"; return $inline_display; } ?>
This is the page that calls the function:
And here is mysqli_connect.php:
I think my problem has something to do with making $dbc a global variable, but I haven't been able to resolve the issue. What am I doing wrong?
Link to comment
https://www.neowin.net/forum/topic/1138504-php-querying-db-in-functionsphp/Share on other sites
2 answers to this question
Recommended Posts