Solved

Loading LIST Menus with data from database

Posted on 2004-09-19
7
206 Views
Last Modified: 2008-03-06
Hi,

<form name="form1" method="post" action="">
                    <select name="select">
                      <option value="<?php $selected="domain 1";print mysql_result($result,0,"domain");?>" selected><?php print mysql_result($result,0,"domain");?></option>
                      <option value="<?php $selected="domain 2";print mysql_result($result,1,"domain");?>"><?php print mysql_result($result,1,"domain");?></option>
                    </select>
                    <input type="submit" name="Submit" value="SHOW">
                  </form>

Im using the code above to force 2 rows of data into the list menu, how do I get the list menu to auto populate from the rows in the database ?

When one is actually selected and the Submit button is clicked it also needs to set the $selected variable to the domain name selected.

Thank
0
Comment
Question by:MirageSF
  • 4
  • 2
7 Comments
 

Author Comment

by:MirageSF
ID: 12098038
Actually, be better if $selected = 0 for first item on list, then 1, 2 and so on
0
 
LVL 6

Expert Comment

by:peyox
ID: 12098051
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 250 total points
ID: 12100436
This appears to be the same as what you need in the other question.  Heres a different method to do it, which is actually more straight forward then what i thought you wanted in the other one.

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>";>
 <select name="domain">
 <?php
  $query = mysql_query("SELECT * FROM tablename") or die(mysql_error());
 
  $num = 0;

  while ($row = mysql_fetch_assoc($query)) {
   echo "<option";
   if (isset($_POST['domain']) && $_POST['domain'] == $row["domains"]) echo " selected";
   echo ">".$row["domains"]."</option>\n";
  }
 ?>
 </select>
 <input type="submit" name="submit" value="SHOW">
</form>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:Diablo84
ID: 12100442
sigh, im not having much luck today

you can remove $num = 0; you don't need it.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12100446
>> When one is actually selected and the Submit button is clicked it also needs to set the $selected variable to the domain name selected.

$selected = $_POST['domain'];

The post value of domain will contain the domain name that was selected in the drop down list
0
 

Author Comment

by:MirageSF
ID: 12100556
Hi Diablo84,

I used a slightly smaller piece of code that seems to do the trick nicely, seems its all pretty much working as planned at the moment...

http://www.stormfusion.com/dms.php
L=DMS-001-1000
P=test

Except for the DOMAIN link, it currently links to http://www.stormfusion.com/domainone.com for some reason, it should be http://www.domainone.com.  The $domain variable only contains the domainone.com part and not the http://www.

Im using the code as...

<?php echo "<a href='" . mysql_result($result3,0,"domain") . "'>" . mysql_result($result3,0,"domain") . "</a>"; ?>

Once this is fixed I will close the question.

Thankyou
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12100619
unless you have the http:// protocol in front of the domain it will simple regard is as a link within your site so you would have to do something like:

<?php echo "<a href='http://" . mysql_result($result3,0,"domain") . "'>" . mysql_result($result3,0,"domain") . "</a>"; ?>
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now