I have 2 php files. Additional some php code included in Joomla directly in an article with Sourcerer.
Something seems to be missing here.
The first error I get is:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
the warning shows to the line in db-queries.php where it says
return $result = mysqli_query($db, $q);"
The second error is:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given.
It shows to the script in the Joomla article where I want to check the num_rows. That's pretty clear, because there is no result. So I mainly need to fix error #1...
So somehow the script didn't know that $db is. I'm stuck...can anybody help or give a small hint?
1: db-connect.php
$sqlhost = "xxx";
$sqluser = "xxx";
$sqlpassword = "xxx";
$sqldb = "xxx";
$db = mysqli_connect ($sqlhost, $sqluser, $sqlpasswort, $sqldb);
mysqli_set_charset($db,"utf8");
2 db-queries.php
<?php include ("db-connect.php");
function squadresults ($squad_nr) {
global $db;
$q = "
SELECT spieler_id, spiel1, spiel2, spiel3, spiel4, spiel5, spiel6, netto, hdc, gesamt_hdc, qualifiziert
FROM onyc_ergebnisse
WHERE squad_nr='".$squad_nr."'
ORDER BY gesamt_hdc DESC, hdc ASC";
return $result = mysqli_query($db, $q);
}
3 included code in Joomla article
<?php
require_once JPATH_SITE.'/_skripte_/db-queries.php';
$q = squadresults ('despo_2018'); // the function squadresults in db-queries.php is called
var_dump ($q); // just to check if there are any results --> NULL
if (mysqli_num_rows($q)==0) {echo "<p class='info'><br/>This squad hasn't been played yet.</p>";}
else {?>
<table class="table-striped">
<tr class="header">
<td class="header">Place</td>
<td class="header">Player</td>
<td class="header">Result</td>
<td class="header">HDC</td>
<td class="header">Total</td>
<td class="header">qual</td>
</tr>
<?php $platz = 1; while ($row = mysqli_fetch_assoc($q)) {
$spieler_id = $row['spieler_id'];
$spieler = mysqli_fetch_row (spielernamen_ergebnisse($spieler_id));
var_dump ($spieler);
echo "<tr>
<td class='center'>".$platz.".</td>
<td class='spieler'>".$spieler[0]." ".$spieler[1]."</td>
<td class='center'>".$row['spiel1']."</td>
<td class='center'>".$row['hdc']."</td>
<td class='center'>".$row['gesamt_hdc']."</td>
<td class='center'>".$row['qualifiziert']."</td>
</tr>";
$platz++;
}?>
</table>
<?php } ?>