Xtremer360 Posted February 10, 2009 Share Posted February 10, 2009 Okay I have one table of countries (id,country) and one table of arenas (id,country,citystate,arena,capacity). It somewhat works now. What happens right now is that it doesn't matter what country is originally clicked it still shows all the arenas. So I don't know how to correct my query in the arenas function. I thought I sent over the country correctly and queried it right so that it'd go to the areas table and grab all the arenas that has the matching country that was chosen before. Countries function function countries() { print '<h1 class=backstage>Arena Management</h1><br />'; print "<h2 class=\"backstage\">Countries :: <a href=\"#\" onclick=\"ajaxpage('addcountries', 'content'); return false;\">Add New</a></h2><br />"; $query = "SELECT * FROM countries ORDER BY `country`"; $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 width="20" align="center">ID</td>'; print '<td> </td>'; print '<td>Country</td>'; print '<td> </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 align=\"center\" width=\"20\">%s</td>", $row [id] ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editcountry('editcountry', 'content' , '". $row ['country'] ."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [country] ); print "<td valign=\"top\" align=\"center\" width=\"80\"><a href=\"#\" onclick=\"arenas('arenas', 'content' , '". $row ['country'] ."'); return false;\">Arenas</a></td>"; print '</tr>'; } echo '</table>'; } else { print '<span>There are no countries.</span><br />'; } print '<br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } Arenas Function function arenas() { $country = $_GET['country']; $query = mysql_query("SELECT * FROM `arenas` WHERE `country` = '" . $country . "'"); $row = mysql_fetch_array($query); print '<h1 class="backstage">Arena Management</h1><br />'; print "<h2 class=\"backstage\">Country Name Arenas :: <a href=\"#\" onclick=\"ajaxpage('addarena', 'content'); return false;\">Add New Arena</a></h2><br />"; $query = "SELECT * FROM arenas ORDER BY `citystate`"; $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>City</td>'; print '<td>Arena</td>'; print '<td align="center">Capacity</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 ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editmatchtype('editmatchtype', 'content' , '". $row ['arena'] ."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [citystate] ); printf ( "<td valign=\"top\">%s</td>", $row [arena] ); printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [capacity] ); print '</tr>'; } echo '</table><br />'; } else { print '<span>There are no arenas for this country.</span><br />'; } print '<input type="button" value="Return to Country List" class="button200"><br /><br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } Link to comment https://forums.phpfreaks.com/topic/144652-solved-passing-variables/ Share on other sites More sharing options...
revraz Posted February 10, 2009 Share Posted February 10, 2009 Post the URL you are passing to the GET statement, and post the data structure and sample data of your Arena table. I would also advise that you don't resuse your variable on the same page. You re-use $query. Also echo $country to make sure it does contain something valid. Link to comment https://forums.phpfreaks.com/topic/144652-solved-passing-variables/#findComment-759116 Share on other sites More sharing options...
Xtremer360 Posted February 10, 2009 Author Share Posted February 10, 2009 function countries() { print '<h1 class=backstage>Arena Management</h1><br />'; print "<h2 class=\"backstage\">Countries :: <a href=\"#\" onclick=\"ajaxpage('addcountries', 'content'); return false;\">Add New</a></h2><br />"; $query = "SELECT * FROM countries ORDER BY `country`"; $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 width="20" align="center">ID</td>'; print '<td> </td>'; print '<td>Country</td>'; print '<td> </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 align=\"center\" width=\"20\">%s</td>", $row [id] ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editcountry('editcountry', 'content' , '". $row ['country'] ."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [country] ); print "<td valign=\"top\" align=\"center\" width=\"80\"><a href=\"#\" onclick=\"arenas('arenas', 'content' , '". $row ['country'] ."'); return false;\">Arenas</a></td>"; print '</tr>'; } echo '</table>'; } else { print '<span>There are no countries.</span><br />'; } print '<br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } Link to comment https://forums.phpfreaks.com/topic/144652-solved-passing-variables/#findComment-759121 Share on other sites More sharing options...
Xtremer360 Posted February 11, 2009 Author Share Posted February 11, 2009 Okay I've been working on it for a while and now I almost have it completely done. Have one problem when I submit my form it doesn't send the country name with it. //Form was submitted - determine the form if ( isset ( $_POST['addarena'] ) ) { // Define the query. $arena = $_POST['arena']; $capacity = $_POST['capacity']; $citystate = $_POST['citystate']; $query = "INSERT INTO `arenas` (`country`, `citystate`, `arena`, `capacity`) VALUES ('".addslashes($country)."','".addslashes($citystate)."', '".addslashes($arena)."', '".addslashes($capacity)."')"; // Execute the query. if (@mysql_query ( $query )) { print '<p>The arena has been added.</p>'; } else { print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>'; } //mysql_close (); } function arenas() { $country = $_GET['country']; $query = mysql_query("SELECT * FROM `arenas` WHERE `country` = '" . $country . "'"); $row = mysql_fetch_array($query); print '<h1 class="backstage">Arena Management</h1><br />'; print "<h2 class=\"backstage\">".$country." Arenas :: <a href=\"#\" onclick=\"ajaxpage('addarena', 'content', '". $row ['country'] ."'); return false;\">Add New Arena</a></h2><br />"; $query = "SELECT * FROM arenas WHERE `country` = '" . $country . "' ORDER BY `citystate`"; $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>City</td>'; print '<td>Arena</td>'; print '<td align="center">Capacity</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 ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editarena('editarena', 'content' , '". $row ['arena'] ."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [citystate] ); printf ( "<td valign=\"top\">%s</td>", $row [arena] ); printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [capacity] ); print '</tr>'; } echo '</table><br />'; } else { print '<span>There are no arenas for this country.</span><br /><br />'; } print '<input type="button" value="Return to Country List" class="button200"><br /><br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } Link to comment https://forums.phpfreaks.com/topic/144652-solved-passing-variables/#findComment-759379 Share on other sites More sharing options...
Xtremer360 Posted February 11, 2009 Author Share Posted February 11, 2009 I do need to include this of course which wasn't included yet. What it is not doing is not posting the variable to the DB when the form is submitted. I thought I was passing it right and put it in the hidden field properly. function addarena() { $country = $_GET['country']; print '<h1 class="backstage">Arena Management</h1><br />'; print '<h2 class="backstage">Add New Arena</h2><br />'; print '<form name="addarena" method="post" action="backstage.php" id="addarena">'; print '<table width="100%" class="table2">'; print '<tr>'; print '<td width="120" class="rowheading" valign="center">Arena:</td><td class="row3"><input type="text" name="arena" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td width="120" class="rowheading" valign="center">City, State:</td><td class="row3"><input type="text" name="citystate" class="fieldtext490"></td>'; print '</tr>'; print '<tr>'; print '<td width="120" class="rowheading" valign="center">Capacity:</td><td class="row3"><input type="text" name="capacity" class="fieldtext140"></td>'; print '</tr>'; print '</table><br />'; print "<input type='hidden' name='country' value='$country'>"; print '<input type="submit" value="Save Arena" class="button" name="addarena"><br /><br />'; print '<input type="button" value="Return to Arena List" class="button200"><br /><br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } And the update arenas code: function arenas() { $country = $_GET['country']; $query = mysql_query("SELECT * FROM `arenas` WHERE `country` = '" . $country . "'"); $row = mysql_fetch_array($query); print '<h1 class="backstage">Arena Management</h1><br />'; print "<h2 class=\"backstage\">".$country." Arenas :: <a href=\"#\" onclick=\"ajaxpage('addarena', 'content', '". $row ['country'] ."'); return false;\">Add New Arena</a></h2><br />"; $query = "SELECT * FROM arenas WHERE `country` = '" . $country . "' ORDER BY `citystate`"; $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>City</td>'; print '<td>Arena</td>'; print '<td align="center">Capacity</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 ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editarena('editarena', 'content' , '". $row ['arena'] ."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [citystate] ); printf ( "<td valign=\"top\">%s</td>", $row [arena] ); printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [capacity] ); print '</tr>'; } echo '</table><br />'; } else { print '<span>There are no arenas for this country.</span><br /><br />'; } print '<input type="button" value="Return to Country List" class="button200"><br /><br />'; print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>'; } Link to comment https://forums.phpfreaks.com/topic/144652-solved-passing-variables/#findComment-759475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.