Mysql Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Mysql Query

Post by SidewinderX »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Below is a simple code that allows a user to enter a name and it searches the table skills_warrior for that skill the user entered. however i want this script to search multiple tables, like skills_warrior, skills_monk, skills_necromancer ect... how do i do that?

Code: Select all

$sql_row = $_POST['sql_row'];
$skillname = $_POST['skill_name'];
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);
$result = mysql_query("SELECT * FROM skills_warrior WHERE $sql_row='$skillname'", $db);

echo "Skill Name:
<br>
<form method = 'post' action = 'index.php'>
  <select name='sql_row'>
    <option>Name</option>
    <option>Mana</option>
    <option>Recharge</option>
    <option>Trainer</option>
  </select><br>
<input type = 'text' name = 'skill_name'>
<input type = 'submit' value = 'Go'>
<br>
<br>";

while ($row = mysql_fetch_array($result))
{
echo "<table width=\"600\" cellpadding=\"3\" cellspacing=\"2\" border=\"1\">
<tr><td  width=\"100\"> Skill</td><td>" . $row["name"] . "</td>

<td rowspan=\"5\"  width=\"55\"><center>
  <img src=\"".$row["image"]."\" width=\"64\" height=\"64\">
</center></td></tr>

<tr><td  width=\"100\"> Description</td>
<td>" . $row["description"] . "</td></tr>

<tr><td  width=\"100\">Mana</td>
    <td>" . $row["mana"] . "</td>
  </tr>
<tr><td  width=\"100\">Recast Time</td><td>" . $row["recharge"] . "</td></tr>
<tr><td  width=\"100\">Location</td><td> Trainer: " . $row["location"] . "</td></tr>
</table><br>";
}


?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could use a UNION, or simply loop over all the tables you wish to search.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

By the sound of it you're using seperate tables to store the skill details of different character classes. You should only be using one table to store them all.
Post Reply