Jump to content

[SOLVED] [PHP][MYSQL] dropdown - select ID and display its ROW in DIV or new page


karol65

Recommended Posts

Hi,

 

I am completely newbie. I have created dropdown list, that reads some vars form msql Dbase. The thing is I would like to allow, by clicking on selected position form dropdown, to display all rows (form ID) in new or new window.

 

my code:

 

<?php

$query = mysql_query("SELECT * FROM table ORDER BY id");

echo '<select name="ids" style="width :500px">';

while($row = mysql_fetch_array($query))

{

echo '<option name="'.$row['id'].'">'.$row['name'].', CMD: '.$row['cmd'].', Date: '.$row['StartDate'].'</option>';

}

echo '</select>';

?>

 

I don't know how to pass those vars (or how to declare it). Thanks for any suggestions.

 

Link to comment
Share on other sites

OK, thanks for reply. I get the point, but I cannot input select list with all records in one place. Instead of this I have (based on script below):

 

|------------||--------------||--------------||------------------| (numbers of those fields = numbers of IDs in table)

 

And how to pass those vars by submit button?

 

<?php include 'config.php'; ?>

 

<?php

 

 

$sql = "SELECT name,StartDate,id FROM `my_table` ORDER BY `id` ASC";

$result = mysql_query($sql) or die (mysql_error());

echo "<select name=\"\" id=\"\">";

while ($row = mysql_fetch_array($result)){

  extract ($row);

  echo "<form action=\"sum.php\" method=\"post\">";

  echo "<select name=\"genfile\" OnChange=\"submit();\">";

  echo "<option>-------</option>";

 

echo "<option value=\"$id\">$name - $cmd - $StartDate</option>";

}//Ends while

//echo "</select>";

echo "<input type=\"submit\">";

echo "</form>";

echo "<br />";

echo "<br />";

 

 

 

 

 

?>

Link to comment
Share on other sites

Now I have something like this:

 

<?php

 

 

 

 

$sql = "SELECT * FROM `table` ORDER BY `id` ASC";

$result = mysql_query($sql) or die (mysql_error());

//echo "<select name=\"\" id=\"\">";

 

while ($row = mysql_fetch_array($result)){

  extract ($row);

  echo "<form action=\"sum.php\" method=\"post\">";

//  echo "<select name=\"genfile\"  value=\"$id\" OnChange=\"submit();\">";

  echo "<option value=\"$id\" OnChange=\"submit();\" > $name - $cmd - $StartDate - $t_letter_code_ef </option>";

 

 

// echo "<value=\"$row[id]\"> $row[t_letter_code_ef]</option>";

 

 

//echo "<option value=\"$id\">$name - $cmd - $StartDate</option>";

}//Ends while

//echo "</select>";

echo "<br />";

echo "<br />";

echo "<input type=\"submit\">";

echo "</form>";

echo "<br />";

echo "<br />";

 

 

?>

 

But this is not a select list, it displays all as a static list, I want to make it clickable, like real select list (dropdonw= and send all row to sum.php. Any idea how to do this?

Link to comment
Share on other sites

untested

<?php
if(isset($_POST['Test']))
{
echo $_POST['Test']."SELETED<br>";
}
$sql = "SELECT * FROM `table` ORDER BY `id` ASC";
$result = mysql_query($sql) or die (mysql_error());
//echo "<select name=\"\" id=\"\">";

echo "<form action=\"sum.php\" method=\"post\">";
echo "<select name=\"Test\">";  //ADDED
while ($row = mysql_fetch_array($result)){
   extract ($row);
  echo "<option value=\"$id\" OnChange=\"submit();\" > $name - $cmd - $StartDate - $t_letter_code_ef </option>";
}//Ends while
echo "</select>";
echo "<br>";
echo "<br>";
echo "<input type=\"submit\">";
echo "</form>";
echo "<br>";
echo "<br>";

Link to comment
Share on other sites

  • 4 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.