0

I am trying to get some data from the db but it's across 2 separate tables of data. I am unsure of the best way to go about solving a problem like this.

Also both tables need the charid but I don't know if I need to bind it again.

<?php
include_once "mmoconnection.php"; 

$mydata = json_decode(file_get_contents('php://input'));
$charid = $mydata ->charid;
$userid = $mydata ->userid;

$stmt = $conn->prepare("SELECT name, health, mana, level, experience, clan, posx, posy, posz, rotation_yaw, 
equip_head, equip_chest, equip_hands, equip_legs, equip_feet, hotbar0, hotbar1, hotbar2, hotbar3 FROM characters WHERE id = ? ");

$stmt->bind_param("i", $charid);  // "i" means the database expects an integer

$stmt->execute();

$stmt->bind_result($row_name, $row_health, $row_mana, $row_level, $row_experience, $row_clan_id, $row_posx, $row_posy, $row_posz, $row_rotation_yaw, 
$row_equip_head, $row_equip_chest, $row_equip_hands, $row_equip_legs, $row_equip_feet, $row_hotbar0, $row_hotbar1, $row_hotbar2, $row_hotbar3);

$stmt = $conn->prepare("SELECT 1, 2 FROM skills WHERE id = ? ");

$stmt->bind_result($row_1, $row_2);
  // output data of each row

if($stmt->fetch()) {
    //other code
}    
?>
Fabulous
  • 719
  • 1
  • 10
  • 28
Althaen
  • 29
  • 8
  • 3
    Are these tables related in any way such that you can just issue *one* query and get the `JOIN`ed results? If not and if you truly need two queries, what exactly isn't working? If you can successfully query the database, what's stopping you from doing that twice? Do you just need to use a second "statement" variable? – David Dec 14 '17 at 13:44
  • What David said; plus it looks like you forgot to `$stmt->bind_param` on your second `$conn->prepare` – IsThisJavascript Dec 14 '17 at 13:46
  • This is how the db is set up: https://gyazo.com/a88fe5f6dcdfc2025c06a57b0ccf9abd and the error I get: Fatal error: Call to a member function bind_param() on boolean in C:\wamp64\www\site\mmogetcharacter.php on line 22 – Althaen Dec 14 '17 at 14:04
  • I need information from both tables to be accessed in one go. – Althaen Dec 14 '17 at 14:22
  • @Althaen: If you want to join the tables into a single query then you *probably* want to take a look at the `JOIN` keyword in SQL. How you join them depends on how they're structured, which we don't know. – David Dec 14 '17 at 14:24
  • Both tables have different columns so I don't know if they can be joined. I need the data for variables on a player character in the MMO I am developing. The only other way would be to just put it all on one table. – Althaen Dec 15 '17 at 00:09

0 Answers0