haiii all,

i have a php working code for dropdown list,i am unable to display that in a table,i am getting error if i write that code in <td> </td>
i am able to include buttons...but why i am i unable to include dropdownlist?

so can i place that code in another .php file and try to execute between <td> </td>

<td> dropdownlist.php </td> ???????? please anyone help me regarding this.....

example:

Items Select Insert
john dropdownlist Insertbutton
Marry dropdownlist insertbutton
Nancy dropdownlist insertbutton


if i select dropdownlist item and click on insert,it should insert in a datanabe table.

Recommended Answers

All 5 Replies

Try using

include 'dropdownlist.php'

and printing a variable from that in your <td> tags.

Example:
dropdownlist.php:

$ddlist="**your dropdownlist html goes here**"

Then
index.php (or whatever):

include 'dropdownlist.php';
...
print("<td>$ddlist</td>");

so can i write

<td> include 'dropdownlist.php' </td>

its not working!!!!

<?php
$db =mysql_connect("localhost", "root","root");
mysql_select_db("reports",$db);
$result = mysql_query("SELECT * FROM alertssummary",$db);
if ($myrow = mysql_fetch_array($result))
{

echo"<form method='POST' action='delete.php'>";
echo "<table border=1>\n";
echo "<tr><td>Id</td><td>AlertsDisribution</td><td>Label</td><td>Affects</td><td>Variations</td><td>Insert</td><td>Delete</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td> <td>%s</td> <td>%s</td>
<td><input type='checkbox' name='checkbox1[]' value='%s'/></td>

td> """""""""""""""""i should get it here"""""""""""""""""""""""""""""""""''''''' </td>
<td><input type='checkbox' name='checkbox[]' value='%s'/></td>
</tr>\n",$myrow["Id"],$myrow["AlertsDistribution"], $myrow["label"],$myrow["Affects"],$myrow["Variations"],$myrow["Id"],$myrow["Id"]);
}
while ($myrow = mysql_fetch_array($result));

echo "</table> <p> <center><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></center></form>";

$result2=mysql_query("SELECT Id,owasp FROM Owasp",$db);
echo "<center><select name=Owasp value=''><option>Owasp List</option></center>";
while($nt=mysql_fetch_array($result2))
{
echo "<option value=$nt[Id]>$nt[owasp]</option>";
}
echo "</select>";

echo "<p><center><input id='insert' type='submit' class='button' name='insert' value='Insert Selected Items'/></center></p>";
mysql_close($db);

}

?>

code in red is for dropdownlist, i am able to display it under table but i am not able to do it between <td> </td> tag

Here's how the include file is called...

<?php
include("filename.php");
?>

There is no <td> before and after the include...

Here is your code you posted, modified:

<?php
include 'selectlist_options.php';
$db =mysql_connect("localhost", "root","root");
mysql_select_db("reports",$db);

$result = mysql_query("SELECT * FROM alertssummary",$db);

include 'dropdownlist.php'; //Add this line, which retrieves all of the code in dropdownlist.php

if ($myrow = array($result))
{

echo"<form method='POST' action='delete.php'>";
echo "<table border=1>\n";
//Below, use $select_markup (or any variable you want) as the variable containing the string generated in selectlist_options.php
echo "<tr><td>Id</td><td>AlertsDisribution</td><td>Label</td><td>Affects</td><td>Variations</td><td>Insert</td><td>Delete</td></tr>\n";
printf("<tr><td>%s</td><td>%s</td><td>%s</td> <td>%s</td> <td>%s</td>
<td><input type='checkbox' name='checkbox1[]' value='%s'/></td>
<td>$select_markup</td>
<td><input type='checkbox' name='checkbox[]' value='%s'/></td>
</tr>\n",$myrow["Id"],$myrow["AlertsDistribution"], $myrow["label"],$myrow["Affects"],$myrow["Variations"],$myrow["Id"],$myrow["Id"]);

while ($myrow = mysql_fetch_array($result));
echo "</table> <p> <center><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></center></form>";
echo "<p><center><input id='insert' type='submit' class='button' name='insert' value='Insert Selected Items'/></center></p>";
mysql_close($db);

}

?>

Then, in another file (dropdownlist.php), the code that generates the list:

<?php

$result2=mysql_query("SELECT Id,owasp FROM Owasp",$db);
echo "<center><select name=Owasp value=''><option>Owasp List</option></center>";
while($nt=mysql_fetch_array($result2))
{
$select_markup = $select_markup."<option value=$nt[Id]>$nt[owasp]</option>";
}
echo "</select>";

?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.