Jump to content

[SOLVED] Form Fetch Results Not Returning


JTapp

Recommended Posts

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

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.