Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i pattern a php database call?
    primarykey
    data
    text
    <p>specs: PHP 5 with mySQL built on top of Codeigniter Framework.</p> <p>I have a database table called <code>game</code> and then sport specific tables like <code>soccerGame</code> and <code>footballGame</code>. these sport specific tables have a <code>gameId</code> field linking back to the <code>game</code> table. I have corresponding classes <code>game</code> and <code>soccerGame</code>/<code>footballGame</code>, which both extend <code>game</code>.</p> <p>When I look up game information to display to the user, I'm having trouble figuring out how to dynamically link the two tables. i'm curious if it's possible to get all the information with with one query. The problem is, I need to query the <code>game</code> table first to figure out the sport name.</p> <p>if that's not possible, my next thought is to do it with two queries. have my <code>game_model</code> query the game table, then based off the sport name, call the appropriate sport specific model (i.e. <code>soccer_game_model</code>) and get the sport specific info.</p> <p>I would also pass the <code>game</code> object into the <code>soccer_model</code>, and the <code>soccer_model</code> would use that object to build me a <code>soccerGame</code> object. this seems a little silly to me because i'm building the parent object and then giving it to the extending class to make a whole new object?</p> <p>thoughts?</p> <p>thanks for the help.</p> <p>EDIT:</p> <p>game table</p> <pre><code>gameId sport (soccer, basketball, football, etc) date other data </code></pre> <p>soccerGame table</p> <pre><code>soccerGameId gameId soccer specific information </code></pre> <p>footballGame table</p> <pre><code>footballGameId gameId football specific information </code></pre> <p>and so on for other sports</p> <p>So I need to know what the sport is before I can decide which sport specific table I need to pull info from.</p> <p>UPDATE:</p> <p>Thanks all for the input. It seems like dynamic SQL is only possible through stored procedures, something I'm not well versed on right now. And even with them it's still a little messy. Right now I will go the two query route, one to get the sport name, and then a switch to get the right model.</p> <p>From the PHP side of things now, it seems a little silly to get a <code>game</code> object, pass it to, say, my <code>soccer_game_model</code>, and then have that return me a <code>soccer_game</code> object, which is a child of the original <code>game</code>. Is that how it has to be done? or am I missing something from an OO perspective here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload