/    Sign up×
Community /Pin to ProfileBookmark

Listing certain fields fro a drop down menu

similar to a previous post i put on here but this time instead of typing a query in a text box, how would i do it with a drop down menu?just need to list certain fields from one of the tables. here is the code to list all the fields in the table.

<?php
/*Script to display all full-time jobs in the full time job table*/

/*Open the database connection and use the findacareer database*/
$link = mysql_connect(“localhost”, “root”, “”)
or die(“No local host connection:”. mysql_error());

mysql_select_db(“findacareer”)
or die(“Could not select the database”);

/*Perform SQL Query*/
$query = “SELECT * FROM fulltime”;
$result = mysql_query($query);
or die(“Query failed:”.mysql_error());

echo “nt<h1>Full Time Positions</h1>n”;

/*Print the results in HTML*/
print “<table border=1>n<tr>n”;
echo “nt<th>Reference Number:</th>”;
echo “nt<th>Salary:</th>”;
echo “nt<th>Location:</th>”;
echo “nt<th>Arrangement:</th>”;
echo “nt<th>Sector:</th>”;
echo “nt<th>Contact Name:</th>”;
echo “nt<th>Email:</th>”;
“n</tr>”;

while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print “t<tr>n”;
foreach ($line as $col_value)
{
print “tt<td ALIGN = center>$col_value</td>n”;
}
print “t</tr>n”;
}
print “</table>n”;
mysql_free_result($result);

echo “<br>”;
echo “<br>”;

/*Perform SQL Query*/
$query = “SELECT * FROM customer”;
$result = mysql_query($query);
or die(“Query failed:”.mysql_error());

echo “nt<h1>Customer</h1>n”;

//Print the results in HTML
print “<table border=1>n<tr>n”;
echo “nt<th>Reference Number:</th>”;
echo “nt<th>Name:</th>”;
echo “nt<th>Age:</th>”;
echo “nt<th>Sex:</th>”;
echo “nt<th>Email:</th>”;
echo “nt<th>Phone:</th>”;
echo “nt<th>City:</th>”;
“n</tr>”;

while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print “t<tr>n”;
foreach ($line as $col_value)
{
print “tt<td ALIGN = center>$col_value</td>n”;
}
print “t</tr>n”;
}
print “</table>n”;
mysql_free_result($result);

/* Close connection */
mysql_close($link);
?>

cheers

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@chestertbJun 02.2004 — I'm not exactly certain I understand what you're trying to do, but try this...

Let's say you want to search on "Sector"...

<?php

$qr = "SELECT DISTINCT Sector FROM fulltime";

$rs = mysql_query($qr) or die("Die Message");

?>

<form name='form' id='form' method='POST'>

<select id='sector' name='sector'>";

while ($rw==mysql_fetch_array($rs))

{

$sector = $rw['sector'];

print "<option value='$sector'>$sector</option>";

}

?>

</select>

<input type='submit' value='Search'>

</form>

That will give you a drop down list. When you select a value and click the submit button, the selected value is submitted as field 'sector' as identified in the <select> html statement.

Hope this is what you were looking for.

CTB
×

Success!

Help @dennic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...