Jump to content

Query issues


Xtremer360

Recommended Posts

I probably have this setup wrong well I know I do because nothing is showing up now. What I want is for it to show all the character names that are assigned to each user so yes than can be more than one. Can't figure out where at in my coding is my problem.

 

table efed_bio

id

charactername

 

table handler_characters

id

handler_id

bio_id

 

table efed_handler

id

default_character_id

login

forum_id

 

<?php {
   $query = "SELECT h.login, h.forumname,
        bio.charactername AS charactername
FROM efed_bio AS bio, efed_handler_characters AS ech, efed_handler AS h
WHERE h.default_char_id = bio.id
AND ech.handler_id=h.id
AND ech.bio_id=bio.id";           
   $result = mysql_query ( $query ); // Run The Query
   if ($result) {
      print '<h1 class=backstage>Active Handler Directory</h1><br />';
      print '<table width="100%" class="table1">';
      print '<tr class="rowheading">';
      print '<td>Name</td>';
      print '<td>Forum Name</td>';
      print '<td>Characters</td>';
      print '</tr>';
      // Fetch and print all records.
      $i = 0;
      while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
         $sClass = 'row2';
         if ($i ++ & 1) {
            $sClass = 'row1';
         }
         printf ( "<tr class=\"%s\">", $sClass );
         printf ( "<td valign=\"top\">%s</td>", $row [login] );
         printf ( "<td valign=\"top\">%s</td>", $row [forumname] );
         printf ( "<td valign=\"top\"><ul class=\"characters\"><li>%s</li>", $row [charactername] );
         print '</ul></td>';
         print '</tr>';
      }
      print '</table><br />';
      print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>';
   }
}
?>

Link to comment
Share on other sites

trigger_error will, well...trigger an error if there is one.  adding mysql_error() as the argument to trigger_error() will display any errors within the mysql query in question.

 

white screen usually means a parse error.  add:

 

<?php
ini_set ('display_errors', 1);
error_reporting(E_ALL);

 

to the very top of your script(s), immediately after <?php

Link to comment
Share on other sites

I found the issues. It's displaying the html table like it should and the join tag for the query is working properly now it's displaying the character names however it's giving me these errors above the table.

 

Notice: Use of undefined constant login - assumed 'login' in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/directory.php on line 38

 

Notice: Use of undefined constant forumname - assumed 'forumname' in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/directory.php on line 39

 

Notice: Undefined index: forumname in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/directory.php on line 39

 

Notice: Use of undefined constant charactername - assumed 'charactername' in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/directory.php on line 40

 

<?php {ror_reporting(E_ALL);
    
  $query = "SELECT h.login, h.id, b.charactername 
FROM efed_handler AS h 
JOIN efed_handler_characters AS c ON h.id = c.handler_id 
JOIN efed_bio AS b ON c.bio_id = b.id";    
   $result = mysql_query ( $query ) or trigger_error (mysql_error()); // Run The Query
   if ($result) {
      print '<h1 class=backstage>Active Handler Directory</h1><br />';
      print '<table width="100%" class="table1">';
      print '<tr class="rowheading">';
      print '<td>Name</td>';
      print '<td>Forum Name</td>';
      print '<td>Characters</td>';
      print '</tr>';
      // Fetch and print all records.
      $i = 0;
      while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
         $sClass = 'row2';
         if ($i ++ & 1) {
            $sClass = 'row1';
         }
         printf ( "<tr class=\"%s\">", $sClass );
         printf ( "<td valign=\"top\">%s</td>", $row [login] );
         printf ( "<td valign=\"top\">%s</td>", $row [forumname] );
         printf ( "<td valign=\"top\"><ul class=\"characters\"><li>%s</li>", $row [charactername] );
         print '</ul></td>';
         print '</tr>';
      }
      print '</table><br />';
      print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>';
   }
}
?>

Link to comment
Share on other sites

these are just Notices, but it's great practice to eliminate these.  the Notice:

 

Notice: Use of undefined constant x

 

is because you're not wrapping your $row index with quotes, like so:

 

$row['forumname']

  and so on.

 

the Notice:

 

Notice: Undefined index: forumname

 

would be because `forumname` has not been set by a value from the db.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.