Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading LIST Menus with data from database

Posted on 2004-09-19
7
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 27

Accepted Solution

by:
Diablo84 earned 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

688 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