Generate commands from MySQL Table
- Dominant language
- No language data
- Stars
- 33
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
First off, thank you for this framework! I have been building a chatbot with some JS libraries and really wanted a way to protect some of the clever coding I have done. This is a fantastic solution.
One of my current goals to use my nice GUI CRUD editor to build out my conversations.
The script below connects to a Database and creates a command for each row in the table.
However, every response is equal to the last row's response value. Can anyone provide me with a hint on what I should be googling to find a solution? Right now I am focused on Variable Scopes.
Cheers!
Brandon
```
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, command, responce, function FROM commands_general";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
// echo "
id: ". $row["id"]. " - Command: ". $row["command"]. " " . $row["responce"] . "
";
$command = $row["command"];
$GLOBALS['responce'. $row["id"]] = $row["responce"];
$GLOBALS['id'] = $row["id"];
$botman->hears($command, function ($bot) {
global $id;
// global $responce.$x;
$bot->reply('heard you '.$id);
$id ++;
});
}
} else {
echo "0 results";
}
$conn->close();
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.