Jump to content

Trying to add functions to table


Xtremer360

Recommended Posts

I have this list of characters and I'm trying to figure out what I have to do to put the results of these functions into the table or what not. Keep in mine that these functions are included in a file that is with the bottom file.

 

function getstatusname($statusid)
{
$query = "SELECT
		s.name as status
	FROM
		efed_list_status as s
	WHERE
		s.id = '$statusid'"; 
$result = mysql_query ($query); 
while ($row = mysql_fetch_assoc($result))
{
	$status=cleanquerydata($row['status']);
	return $status;
}

}

function getstylename($styleid)
{
$query = "SELECT
		style.name as stylename
	FROM
		efed_list_styles as style
	WHERE
		style.id = '$styleid'"; 
$result = mysql_query ($query); 
while ($row = mysql_fetch_assoc($result))
{
	$style=cleanquerydata($row['stylename']);
	return $style;
}
}

function getalignmentname($alignmentid)
{
$query = "SELECT
		alignment.name as alignmentname
	FROM
		efed_list_alignment as alignment
	WHERE
		alignment.id = '$alignmentid'"; 
$result = mysql_query ($query); 
while ($row = mysql_fetch_assoc($result))
{
	$alignmentname=cleanquerydata($row['alignmentname']);
	return $alignmentname;
}
}

 

<?php {
    print '<h1 class=backstage>Character Management</h1><br />';
    print "<h2 class=backstage>Characters :: <a href=\"#\" onclick=\"ajaxpage('addcharacter', 'content'); return false;\">Add New</a></h2><br />";
    {
    $query = "SELECT * FROM efed_bio ORDER BY `charactername`";
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
    
    print '<table width="100%" class="table1">';
    print '<tr class="rowheading">';
    print '<td> </td>';
    print '<td> </td>';
    print '<td>Character Name</td>';
    print '<td align=center width=100>Poser Name</td>';
    print '<td align=center width=60>Style</td>';
    print '<td align=center width=60>Alignment</td>';
    print '<td align=center width=60>Status</td>';
    print '</tr>';
        // Fetch and print all records.
        $i = 0;
        $current_row = 0;
        while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
            $sClass = 'row2';
            if ($i ++ & 1) {
                $sClass = 'row1';
            }
            printf ( "<tr class=\"%s\">", $sClass );
            print "<td valign=\"top\" align=center width=35><a href=\"#\" onclick=\"ajaxpage('editcharacter', 'content'); return false;\">Edit</a></td>";
            print "<td valign=\"top\" align=center width=25><a href=\"#\" onclick=\"ajaxpage('bio', 'content'); return false;\">Bio</a></td>";
            printf ( "<td valign=\"top\">%s</td>", $row [charactername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [posername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [style] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [name] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [name] );
            print '</tr>';
        }
         print '</table>';
     }
     else
     {
     print '<span>There are characters.</span><br />';
     }
     print '<br />';
returnmain();
        }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/183096-trying-to-add-functions-to-table/
Share on other sites

adjusted something on the coding. Okay I have the chart of characters. However nothing shows up for the style, alignment, status. I want to know how to include those functions above since they already have the included querys so that it'll return the correct value for the correct character.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="" />

<title>Untitled 1</title>
</head>

<body>

<?php {
    print '<h1 class=backstage>Character Management</h1><br />';
    print "<h2 class=backstage>Characters :: <a href=\"#\" onclick=\"ajaxpage('addcharacter', 'content'); return false;\">Add New</a></h2><br />";
    {
    $query = "SELECT * FROM efed_bio ORDER BY `charactername`";
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
    
    print '<table width="100%" class="table1">';
    print '<tr class="rowheading">';
    print '<td> </td>';
    print '<td> </td>';
    print '<td>Character Name</td>';
    print '<td align=center width=100>Poser Name</td>';
    print '<td align=center width=60>Style</td>';
    print '<td align=center width=60>Alignment</td>';
    print '<td align=center width=60>Status</td>';
    print '</tr>';
        // Fetch and print all records.
        $i = 0;
        $current_row = 0;
        while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
            $sClass = 'row2';
            if ($i ++ & 1) {
                $sClass = 'row1';
            }
            printf ( "<tr class=\"%s\">", $sClass );
            print "<td valign=\"top\" align=center width=35><a href=\"#\" onclick=\"ajaxpage('editcharacter', 'content'); return false;\">Edit</a></td>";
            print "<td valign=\"top\" align=center width=25><a href=\"#\" onclick=\"ajaxpage('bio', 'content'); return false;\">Bio</a></td>";
            printf ( "<td valign=\"top\">%s</td>", $row [charactername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [posername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [style_id] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [name] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [status_id] );
            print '</tr>';
        }
         print '</table>';
     }
     else
     {
     print '<span>There are characters.</span><br />';
     }
     print '<br />';
returnmain();
        }
}
?>

</body>
</html>

Your surely don't mean you want to call those functions for each iteration through an existing result set? Thats going to equate to allot of queries being executed.

 

You might want to lookup a tutorial of using a mysql JOIN to get all the data you need in one query..

Well that's just it I'm not sure where my true problem is because it's not filling in the spot in the list of characters with the right style.

 

I'm almost there I can tell because there's no error message. Now it's just showing the message there's no characters.

 

Here's my new code.

 

<?php {
    print '<h1 class=backstage>Character Management</h1><br />';
    print "<h2 class=backstage>Characters :: <a href=\"#\" onclick=\"ajaxpage('addcharacter', 'content'); return false;\">Add New</a></h2><br />";
{
      $query = "SELECT 
            bio.charactername,
            bio.style_id,
            style.id,
            style.name
	FROM
		efed_bio as bio
	INNER JOIN
		efed_list_styles as style
	ON
		(
			bio.style_id = style.id				
		)
	WHERE
		bio.style_id = 'syle.name'"; 
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
    
    print '<table width="100%" class="table1">';
    print '<tr class="rowheading">';
    print '<td> </td>';
    print '<td> </td>';
    print '<td>Character Name</td>';
    print '<td align=center width=100>Poser Name</td>';
    print '<td align=center width=60>Style</td>';
    print '<td align=center width=60>Alignment</td>';
    print '<td align=center width=60>Status</td>';
    print '</tr>';
        // Fetch and print all records.
        $i = 0;
        $current_row = 0;
        while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
            $sClass = 'row2';
            if ($i ++ & 1) {
                $sClass = 'row1';
            }
            printf ( "<tr class=\"%s\">", $sClass );
            print "<td valign=\"top\" align=center width=35><a href=\"#\" onclick=\"ajaxpage('editcharacter', 'content'); return false;\">Edit</a></td>";
            print "<td valign=\"top\" align=center width=25><a href=\"#\" onclick=\"ajaxpage('bio', 'content'); return false;\">Bio</a></td>";
            printf ( "<td valign=\"top\">%s</td>", $row [charactername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [posername] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [style_id] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", $row [name] );
            printf ( "<td align=\"center\" valign=\"top\">%s</td>", bio.style_id );
            print '</tr>';
        }
         print '</table>';
     }
     else
     {
     print '<span>There are characters.</span><br />';
     }
     print '<br />';
returnmain();
        }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.