Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Drop-down box to select mysql results
Old 08-16-2004, 10:25 AM Drop-down box to select mysql results
Novice Talker

Posts: 7
Trades: 0
Hi,

I want to pull the results out of my database using a drop-down menu. The options on the menu would be 'field 1', 'field 2' and 'field 3' and the results from the database should be ordered by the selected field. I have set up the code to extract my results but I don't know how to incorporate these into a drop-down menu and would appreciate any help in doing so.

My Code is

PHP Code:
<?php
/* Connecting, selecting database */
$link mysql_connect("host""name""pass")
or die(
"Could not connect : " mysql_error());
echo 
"Connected successfully";
mysql_select_db("db") or die("Could not select database");
/* Querying */
$query "SELECT * FROM table ORDER BY 'field1' DESC";
$result mysql_query($query) or die("Query failed : " mysql_error());
/* Printing results */
echo "<table>\n";
while (
$line mysql_fetch_array($resultMYSQL_ASSOC))
{
echo 
"\t<tr>\n";
foreach (
$line as $col_value)
{
echo 
"\t\t<td>$col_value</td>\n";
}
echo 
"\t</tr>\n";
}
echo 
"</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Querying */
$query2 "SELECT * FROM table ORDER BY 'field2' DESC";
$result2 mysql_query($query2) or die("Query failed : " mysql_error());
/* Printing results */
echo "<table>\n";
while (
$line mysql_fetch_array($result2MYSQL_ASSOC))
{
echo 
"\t<tr>\n";
foreach (
$line as $col_value)
{
echo 
"\t\t<td>$col_value</td>\n";
}
echo 
"\t</tr>\n";
}
echo 
"</table>\n";
/* Free resultset */
mysql_free_result($result2);
/* Querying */
$query3 "SELECT * FROM table ORDER BY 'field3' DESC";
$result3 mysql_query($query3) or die("Query failed : " mysql_error());
/* Printing results */
echo "<table>\n";
while (
$line mysql_fetch_array($result3MYSQL_ASSOC))
{
echo 
"\t<tr>\n";
foreach (
$line as $col_value)
{
echo 
"\t\t<td>$col_value</td>\n";
}
echo 
"\t</tr>\n";
}
echo 
"</table>\n";
/* Free resultset */
mysql_free_result($result3);
/* Closing connection */
mysql_close($link);
?>
#
Thanks
Sam Gamgee is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2004, 01:06 PM
Junior Talker

Posts: 1
Trades: 0
I'm not sure exactly what your asking? You want a drop down menu that will list/link output from a database? If that is what you want to do you just:

PHP Code:
while ($row  =  mysql_fetch_row($result)) { 
to output the fields you want to use as the names and ID's of the selections on you drop down menu. Use a CSS drop down menu so all you have to do is use something like

PHP Code:
echo " <td width='50'><a href='page1.php?linkID=$row[1]' id="navCSS">$row[0]</a></td>"

Then the page you link to will output the results of the database according to the linkID. So you just do a mySQL query with something like:

PHP Code:
$result=mysql("SELECT * FROM Table WHERE fieldID='$linkID' ORDER BY fieldID");
while (
$row  =  mysql_fetch_row($result)) {
echo 
"Info1: $row[0]<br>Info2: $row[1]<br>Info3: $row[2]";

So then search for something like "All CSS Drop down menu's" as they have plenty that use min. JavaScript if any. I have one on our site but it would take too long to explain it.
PMH-Aaron is offline
Reply With Quote
View Public Profile
 
Old 08-16-2004, 01:16 PM
Novice Talker

Posts: 7
Trades: 0
Thanks, I think that should get me started.
Sam Gamgee is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Drop-down box to select mysql results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45929 seconds with 12 queries