Solved

Loading LIST Menus with data from database

Posted on 2004-09-19
7
223 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.htaccess 5 39
Single quotes on sqlsrv (mssql+php) prepared statements with parameters save as two quotes into DB 4 55
Cookie not unsetting 7 21
Decrypt string by php 7 33
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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 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