[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP Equivalent to html FORM LISTS

Posted on 2004-09-19
8
Medium Priority
?
239 Views
Last Modified: 2008-03-06
Hi,

Is it possible to create a list box in PHP that contains the data retrieved from a database "field=domains", then a Submit button which is basically a link bank to the same page with the selection...

So...

domain1.com   would return 0
domain2.com   would return 1
domain3.com   would return 2

and so on, once the SUBMIT link it clicked it would reload the same page but as http://www.domain.com/test.php?domainselected=<number of result>

Cheers
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
  • 3
  • 2
8 Comments
 
LVL 6

Expert Comment

by:peyox
ID: 12098618
Yes, it is possible:

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21136994.html

If you need further assistance, let us know!
0
 
LVL 26

Accepted Solution

by:
Umesh earned 1000 total points
ID: 12099319
try this..


$dbLink = mysql_connect("yourhostname","username","secret-password");

$sQuery = @mysql_query("SELECT domains from  tableName ",$dbLink);

print("<form name=myForm action='$_SERVER[PHP_SELF]' method='GET'>");
print("<SELECT name='domainselected'>");
$i=0;
while($row=mysql_fetch_row($sQuery))
{

   print("<OPTION VALUE='$i'>$row[0]</OPTION>"); // would return 0 1 2 etc
  $i++;
}

print("</SELECT>");
print("<INPUT TYPE=SUBMIT name='sub' value='submit'>");
print("</form>");
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 1000 total points
ID: 12100415
This is my approach to it, similar to the above. It also remembers which domain was selected when the form is submitted.

Note, i have used the post method rather then get because its a slightly better method unless there is a specific reason why you want to use the query string. If you do want to use get change the forms method to "get" and the two instances of $_POST to $_GET.

<?php
//included the connection code up here as you may already have it
 $conn = mysql_connect("host","username","password") or die(mysql_error());
 mysql_select_db("db_name",$conn) or die(mysql_error());
?>

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>";>
 <select name="domain">
 <option value="">Please Select</option>

<?php
 $query = mysql_query("SELECT * FROM tablename") or die(mysql_error());
 
 $num = 0;

 while ($row = mysql_fetch_assoc($query)) {
  echo "<option value=\"$num\"";
  if (isset($_POST['domain']) && $_POST['domain'] == $num) echo " selected";
  echo ">".$row["domains"]."</option>\n";
 }
?>

 </select>
</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: 12100423
sorry, this section should be

<?php
 $query = mysql_query("SELECT * FROM tablename") or die(mysql_error());
 
 $num = 0;

 while ($row = mysql_fetch_assoc($query)) {
  echo "<option value=\"$num\"";
  if (isset($_POST['domain']) && $_POST['domain'] == $num) echo " selected";
  echo ">".$row["domains"]."</option>\n";
  $num++;
 }
?>

forgot to increment.

0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12492455
I object to the 3 way split.

My recommendation is split
ushastry {http:#12099319} & Diablo84 {http:#12100415}

The first link posted by peyox references my answer in another thread and i do not believe that pointing to another experts answer in another thread via a link warrants the award of expert points especially as it was a straight forward question, laziness does not signify expertise.
0
 
LVL 6

Expert Comment

by:peyox
ID: 12494522
Instead of pasting code every time I provide url to the right topic if user cannot or don't want to search for it.
However I agree with Diablo's comment.

Good luck guys!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

650 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