Page 1 of 1

Hyperlinked results, with complications

Posted: Tue Aug 03, 2010 10:29 pm
by Balveda
So far I have a full database detailing my WoW guild's characters, alts, roles, etc. Can input and search vis scripts with no problems, but I want to add a final feature to the results.

Most of the results return character names, and I want these names to be hyperlinks to that characters wow-heroes page. The main problem is that to get the results from wow-heroes you have to enter a zone (EU), realm (Eonar), and character name. The link to one of my characters is:

http://www.wow-heroes.com/index.php?zon ... me=balveda

The zone and realm will always be static, but the character name will have to come from the returned mysql search results.

Any idea how I could incorporate this into the output script? I've been going through scripts from php roster mods, but Im struggling to try and pull it all together.

I promise this is the last problem I have :?

Balveda

Re: Hyperlinked results, with complications

Posted: Tue Aug 03, 2010 11:02 pm
by superdezign
If you can return their names already, then why can't you just add that name to the URL?

Re: Hyperlinked results, with complications

Posted: Tue Aug 03, 2010 11:24 pm
by Balveda
superdezign wrote:If you can return their names already, then why can't you just add that name to the URL?
Thats what I dont know how to do - how to make their names a hyperlink, and to add the character name to the url so it displays that characters page.

Re: Hyperlinked results, with complications

Posted: Wed Aug 04, 2010 5:39 am
by superdezign
Well, you haven't provided any code so I can't give you anything more than concept. And, conceptually, if you can echo the name once, you can do it twice.

Let's say your code looks like this:

Code: Select all

echo $name;
Then, you could make it look like this:

Code: Select all

echo '<a href="http://www.wow-heroes.com/index.php?zone=eu&server=eonar&name=' . $name . '">' . $name . '</a>';

Re: Hyperlinked results, with complications

Posted: Wed Aug 04, 2010 8:59 am
by Balveda
Ok, I kinda see where it's going. What syntax would I use when the name (char1) is being echoed from an array into a table?

Code: Select all

while($row = mysql_fetch_array($result2))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['char1'] . "</td>";
  echo "<td>" . $row['rank'] . "</td>";
  echo "<td>" . $row['class'] . "</td>";
  echo "<td>" . $row['spec1'] . "</td>";
  echo "<td>" . $row['spec2'] . "</td>";

Re: Hyperlinked results, with complications

Posted: Wed Aug 04, 2010 4:53 pm
by superdezign
Balveda wrote:Ok, I kinda see where it's going.
Kinda? lol
I take it you're not exactly a programmer, yet. I'd recommend getting into it more. Make some Lua addons. :)

Code: Select all

while($row = mysql_fetch_array($result2))
  {
  echo '<tr>';
  echo '<td>' . $row['id'] . '</td>';
  echo '<td><a href="http://www.wow-heroes.com/index.php?zone=eu&server=eonar&name=' . $row['char1'] . '">' . $row['char1'] . '</a></td>';
  echo '<td>' . $row['rank'] . '</td>';
  echo '<td>' . $row['class'] . '</td>';
  echo '<td>' . $row['spec1'] . '</td>';
  echo '<td>' . $row['spec2'] . '</td>';
There you go. Only because you're a WoW player. ;)

Re: Hyperlinked results, with complications

Posted: Wed Aug 04, 2010 11:11 pm
by Balveda
superdezign wrote:I take it you're not exactly a programmer
Im so far from being a programmer you wouldnt believe it dude. Many thanks for your help :D

Re: Hyperlinked results, with complications

Posted: Thu Aug 05, 2010 12:03 am
by Balveda
Ok - last question, I promise.

I have a form that lets me search for all characters of a particular role (tank, healer, etc), withing a chosen class - ie., I can search for all paladin tanks. I've been trying to set an option in the class drop-down menu that will select all classes, thereby returning, say, a list of all tanks, regardless of their class. I had thought that having * as the value of the select all option of the form would work, but it doesnt.

here's the relevant bit of the form:

Code: Select all

 <form action="multi_search.php" method="post">
<p>
      <label for="class">Pick the class:</label>
      <select id="class" name="class">
      <option value="*">All Classes</option>      
      <option value="Paladin">Paladin</option>
      <option value="Hunter">Hunter</option>
      <option value="Death Knight">Death Knight</option>
      <option value="Shamen">Shamen</option>
      <option value="Priest">Priest</option>
      <option value="Druid">Druid</option>
      <option value="Mage">Mage</option>
      <option value="Warlock">Warlock</option>
      <option value="Rogue">Rogue</option>
      <option value="Warrior">Warrior</option>
    </select>
  </label>
</p>
and the relevant bit of the script to process it:

Code: Select all

<?php

$class = $_POST['class'];
$role = $_POST['role'];
$eg_ready = $_POST['eg_ready'];

include ("connect.php");

$result1 = mysql_query("SELECT * from `character` WHERE max_lvl='Yes' AND ((role1='$role' AND class='$class' AND r1eg='$eg_ready') OR (role2='$role' AND class='$class' AND r2eg='$eg_ready'))");

echo "<table border='1'>
<tr>
<th>Character</th>
<th>Class</th>
</tr>";


while($row = mysql_fetch_array($result1))
  {
  echo "<tr>";  
  echo '<td><a href="http://www.wow-heroes.com/index.php?zone=eu&server=eonar&name=' . $row['char1'] . '">' . $row['char1'] . '</a></td>';
  echo "<td>" . $row['class'] . "</td>";
  echo "<br />";
  }
I had assumed that sending * to $class would select all classes - where am I going wrong?

Re: Hyperlinked results, with complications

Posted: Thu Aug 05, 2010 2:33 am
by superdezign
There's a flaw in that logic. When you use "*" as the class name, your query is looking for classes that are named "*". What I would do is give the value for all classes something like "All" and, if that value is met, then remove the class from the WHERE clause of your query. This way, you are selecting all characters regardless of class. While on the topic of what I'd do, I'd also limit the valid options of the POST value, considering it is insecure to place the raw POST data into a query.

Code: Select all

function validSelect($name, array $validOptions) {
  return isset($_POST[$name]) && in_array($_POST[$name], $validOptions) ? $_POST[$name] : $validOptions[0];
}

$validClasses = array('All', 'Paladin', 'Hunter', ...);
$validRoles = array('All', 'Tank', 'Healer', 'DPS');

$class = validSelect('class', $validClasses);
$role= validSelect('role', $validRoles);

$hasClass = $class != $validClasses[0];
$hasRole = $role != $validRoles[0];

$query =  "select * from `character` WHERE max_lvl='Yes' AND ("
  . "(" . ($hasRole ? "role1='$role' AND " : "") . ($hasClass ? "class='$class' AND " : "") . "r1eg='$eg_ready')"
  . " OR "
  . "(" . ($hasRole ? "role2='$role' AND " : "") . ($hasClass ? "class='$class' AND " : "") . "r2eg='$eg_ready')"
  . ")";

$result1 = mysql_query($query);

Re: Hyperlinked results, with complications

Posted: Thu Aug 05, 2010 4:51 am
by Balveda
Genius, pure genius :P

It works perfectly - thank you so much for your help.

I wont even pretend to understand all the changes you made, but I'm trying to learn - just a very long process for me :oops:

Thanks again,

Balveda