Solved

Loading LIST Menus with data from database

Posted on 2004-09-19
7
246 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 look for a specific file type in a local or remote server directory using PHP.

624 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