Xtremer360 Posted November 27, 2009 Share Posted November 27, 2009 I've been working on this join for about 3 hours now. And I'd really like to seek out some help on figuring out what my issue is now. I'm trying to get the correct values for my style, alignment, and status fields for the list of characters I have. I don' t know what the issue is whether it be my join code or the table code itself calling the table values. Here is my DB scheme: table efed_bio id charactername username charactershortname posername style_id fed_id status_id alignment_id sortorder table efed_list_style id name table efed_list_status id name table efed_list_alignment id name <!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 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 $row ['style_id'] = 'style.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 ['alignment_id'] ); 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> So for example if I have the following for one row for a character just as example lol: Darth Vader- Charactername darth.jpg- posername 1- style_id 1-alignment_id 1-status_id So basically it's going to take Darth's style_id which is one and then go to the efed_list_style table and match 1 against the id in the table and then grab the value of what's in name field in this case it could be "bad guy" and then return that value to the actual table list of characters with the word "bad guy" in that place for the style for Darth Vader. Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/ Share on other sites More sharing options...
Mchl Posted November 27, 2009 Share Posted November 27, 2009 And what problems you have? Seems fine at first look... Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966622 Share on other sites More sharing options...
Xtremer360 Posted November 27, 2009 Author Share Posted November 27, 2009 Well it's not displaying the name "bad guy". It's giving this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/character.php on line 32 Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966626 Share on other sites More sharing options...
Mchl Posted November 27, 2009 Share Posted November 27, 2009 On second look I'm surprised it works What's in $row['style_id'] here? WHERE $row ['style_id'] = 'style.name' Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966640 Share on other sites More sharing options...
Xtremer360 Posted November 27, 2009 Author Share Posted November 27, 2009 Yeah that shouldn't be like that. I have a 1 inside the style_id field in the bio table so it shoudl take that and search for the id on the styles table and then select the corresponding name with it and then actually put that name into the html table. Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966643 Share on other sites More sharing options...
Xtremer360 Posted November 27, 2009 Author Share Posted November 27, 2009 Does anyone else know or can see how to fix my issue? Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966687 Share on other sites More sharing options...
Xtremer360 Posted November 28, 2009 Author Share Posted November 28, 2009 Full updated code however with this query with joins I'm not getting the complete recent but I'm almost there just can't figure out the rest. <?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 style.id = bio.style_id"; $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 ['alignment_id'] ); 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(); } ?> I ran the query in sql in the DB and got the following results:] Results: charactername style_id id name Darth Vader 1 1 Bad Guy In the html table on the style id should be saying Bad Guy and not 1. Quote Link to comment https://forums.phpfreaks.com/topic/183157-seeking-help-after-3-hours-of-a-problem/#findComment-966812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.