Jump to content

Drop down choice to query


heraldic2

Recommended Posts

I have had nothing but great luck with these forums and I am hoping that I am not pressing said luck by asking another question.

 

I have a drop down list populated by information in a database:

 

<?php

include_once('../other/functions.php');

$con = mysql_connect($hostname, $username, $password)

OR DIE ('Unable to connect to database! Please try again later.');

$db = mysql_select_db($dbname, $con);

$sql="SELECT owner_id, teamname FROM owners WHERE active = 1 ORDER BY division, teamname";

$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["owner_id"];

    $thing=$row["teamname"];

    $options.="<OPTION VALUE=\"$id\">".$thing.'</option>';

    }

mysql_close($con);

?>

<SELECT NAME=thing>

<OPTION VALUE=0>Choose One

<?=$options?>

</OPTION>

</SELECT>

 

I have a query that will get the information I want into a table:

 

<?php

$con = mysql_connect($hostname, $username, $password)

OR DIE ('Unable to connect to database! Please try again later.');

$db = mysql_select_db($dbname, $con);

$query = "SELECT * FROM standings, owners, divisions WHERE owners.owner_id = standings.owner_id AND owners.division = divisions.division AND standings.owner_id = 1 ORDER BY year";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

if (!$result) {

    die('Invalid query: ' . mysql_error());

}

mysql_data_seek($result, 0);

echo "<table CELLPADDING=5 border =1>";

echo "<tr>";

echo "<th align=center colspan = 2> Team Name </th>";

echo "<th align=center> Team Owner </th>";

echo "<th align=center> Conference </th>";

echo "<th align=center> Division </th>";

echo "</tr>";

echo "<tr>";

echo "<td align=center colspan = 2>".$row['teamname']."</td>";

echo "<td align=center>".$row['firstname']."</td>";

echo "<td align=center>".$row['conference']."</td>";

echo "<td align=center>".$row['division']."</td>";

echo "</tr>";

echo "<tr>";

echo "<th align=center> Year </th>";

echo "<th align=center> Wins </th>";

echo "<th align=center> Losses </th>";

echo "<th align=center> Points For </th>";

echo "<th align=center> Points Against </th>";

echo "</tr>";

$row = mysql_fetch_array($result);

while ($row = mysql_fetch_array($result)) {

echo "<tr>";

echo "<td align=center>".$row['year']."</td>";

echo "<td align=center>".$row['win']."</td>";

echo "<td align=center>".$row['loss']."</td>";

echo "<td align=center>".$row['points_for']."</td>";

echo "<td align=center>".$row['points_against']."</td>";

echo "</tr>";

}

echo "</table>";

mysql_close($con);

?>

 

How do I make it so a user can use the drop down list, select a team name, and the query will then display the info??

 

Thank you very much

 

 

Link to comment
Share on other sites

i'm trying to help you..

ok first your query must correct.means what do you want from your database

 

like this:

 

$query = "SELECT team_id, name FROM sport.team

where team.team_id=11111

ORDER BY name ";

 

then you need to do is the option select,

 

like this:

 

(query result)

$result = pg_query($query);

 

while($line = mysql_fetch_array($result)) {

?>

      <option value="<?=$line["team_id"];?>"

  <? if ($line['team_id'] ==$id) echo "selected"?>>

      <?=$line["name"];?>

      </option>

      <?

}

  ?>

 

    </select>

    </td>

  </tr>

  </form>

</table>

 

i'm using mix html with php.and i dont know the risk,but i think it could solved your question.

correct me if i'm wrong. :)

 

 

 

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.