JTapp Posted April 17, 2008 Share Posted April 17, 2008 Been working on some script with another user and can't seem to get the following to populate my form dropdown menu. Do you see anything wrong? // Connect to database here require('config.php'); include('includes/mysql.php'); $sql = "SELECT intDistrictID, strDistrictName FROM tblDistricts ORDER BY strDistrictName ASC"; $res = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_assoc($res)){ echo "<option value=\"{$r['intDistrictID']}\" />{$r['strDistrictName']}</option>\n"; } ?> </select> </p> <input type="submit" value="Click Here To View Details" name="Go"> </p> <p align="center"> </p></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/ Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 What is the dropdown omitting? Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519043 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 everything.. there is nothing there. Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519045 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 Try starting a dropdown You don't have <select name="boo"> But you do have the ending tag for it Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519046 Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 The code looks good, so my guess is the SQL connection, or the table name. Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519047 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 The code looks good, so my guess is the SQL connection, or the table name. He would get an error if there was a SQL error, hence the or die statement. Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519048 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 I've got the dropdown started.. maybe its in the wrong place? <form name="form1" method ="post" action="results.php" target="_blank"> <p class="style1"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td bordercolor="#000000"> <p> </p> <p align="center"> <input type="hidden" name="metode" value="tblLodges.intDistrictID"/> <p> </p> <span class="style9">Enter District Number:</span> <select name="search"> <?php $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("dbd",$dbhandle) or die("Could not select db"); // Connect to database here require('config.php'); include('includes/mysql.php'); $sql = "SELECT intDistrictID, strDistrictName FROM tblDistricts ORDER BY strDistrictName ASC"; $res = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_assoc($res)){ echo "<option value=\"{$r['intDistrictID']}\" />{$r['strDistrictName']}</option>\n"; } ?> </select> </p> <input type="submit" value="Click Here To View District Details" name="Go"> </p> <p align="center"> </p></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519053 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 Can we confirm there are entries in the table? Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519054 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Absolutely. The tables are working in another script... Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519055 Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 He would get an error if there was a SQL error, hence the or die statement. I'm getting tired. I've been helping where I can on these forums since this morning, and am now starting to make mistakes, and miss stuff. maybe I should stop for the night. I've been coding at work as well.... Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519057 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 <?php echo "<select name=\"search\">\n"; $sql = "SELECT intDistrictID, strDistrictName FROM tblDistricts ORDER BY strDistrictName ASC"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($res)) { echo "<option value=\"".$row['intDistrictID']."\" />".$row['strDistrictName']."</option>\n"; } echo "</select>\n"; ?> view the source of the page, what is showing up Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519058 Share on other sites More sharing options...
gammaman Posted April 17, 2008 Share Posted April 17, 2008 I am new at PHP so I was looking at your code and was wondering why you did not use mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519059 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 mgallforever - Thanks.. the dropdown is now populating.. Unfortunately, my results.php page is not. Care to stick with me for a bit longer? Here is my php code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"><h1 align="center"><strong> District Details </strong><br /> </h1></td> </tr> </tbody> </table> <center> </center> <center> <p> </p> <p> </p> <p><br /> <br /> </p> <table border="1" cellpadding="4" cellspacing="0" width="86%"> <tbody> <tr> <td colspan="5" bgcolor="FFFF99" height="18"><center> <strong>List Of Distrct Lodges </strong> </center></td> </tr> <tr> <td width="10%" height="18" align="center" bgcolor="FFFF99"><center> Lodge ID Number </center></td> <td width="30%" height="18" align="center" bgcolor="FFFF99"><center> Lodge Name </center></td> <td width="24%" align="center" bgcolor="FFFF99"> Click Button To View Lodge Details </td> <td width="26%" height="18" align="center" bgcolor="FFFF99"><center> City </center></td> <td width="10%" height="18" align="center" bgcolor="FFFF99"><center> District Number </center></td> </tr> <?php $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("db",$dbhandle) or die("Could not select db"); require('config.php'); include('includes/mysql.php'); $id = $_POST['search']; echo $id; $query = "SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeMailingCity, a.strLodgeMailingPostCode, b.strDistrictName, b.strDistrictWebSite, c.strOfficerTitle, c.strFirstName, c.strLastName FROM tblDistricts AS b LEFT JOIN tblLodges AS a ON b.intDistrictID = a.intDistrictID LEFT JOIN DistrictOfficers AS c ON a.intDistrictID = c.intDistrictID WHERE b.intDistrictID='$id' GROUP BY a.strLodgeName LIMIT 50"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ echo "<tr bgcolor=\"#dddddd\"><td><center>"; echo $row["strOfficerTitle"]; echo "</center></td><td><center>"; echo $row["strDistrictName"]; echo "</center></td><td><center>"; echo $row["strDistrictWebSite"]; echo "</center></td><td><center>"; echo $row["strOfficerTitle"]; echo "</center></td><td><center>"; echo $row["strFirstName"]; echo "</center></td><td><center>"; echo $row["strLastName"]; echo "<tr bgcolor=\"#dddddd\"><td><center>"; echo $row["intLodgeNumber"]; echo "</center></td><td><center>"; echo $row["strLodgeName"]; echo "</center></td><td><center><span class=\"style2\">"; echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='5view.php?id="; echo $row["intLodgeNumber"]; echo "'\" /></center></td>"; echo "</center></td><td><center>"; echo $row["strLodgeMailingCity"]; echo "</center></td><td><center>"; echo ltrim($row["intDistrictID"], '0'); echo "<hr>"; } ?> </tbody> </table> <br /> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519060 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 Then he'll have to decide whether he wants to use it as MYSQL_ASSOC, MYSQL_NUM or MYSQL_BOTH assoc being what he is using now, with only field names num being field IDs, and both being either, field IDs or field names Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519061 Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 What kind of error(s) are you getting Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519063 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 No errors.. just no data. gammaman - I started out that way, but what you are seeing now is just an evolution... I'm new at this, too. Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519064 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 gammaman - on my form the field name "strDistrictName" is not needed. I'm wondering if this is causing the problem.. Quote Link to comment https://forums.phpfreaks.com/topic/101468-solved-form-fetch-results-not-returning/#findComment-519069 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.