...

View Full Version : Inital Value in list taken from database



kakshmire
05-06-2006, 03:09 PM
Hi all. I have a form in which i want to the initial value of a select box set so when the page loads it is already selected. The values in the list box are taken from a databse though and arent listed. Here's the code:


<form name=\"GetTableForm\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
echo "<tr><td align=\"center\" valign=\"top\" rowspan=\"3\">";
echo "<strong>Select Table</strong><br><select name=\"GetTableName\" id=\"GetTableName\" size=\"".$getTableCount."\" onClick=\"GetTableListSubmit.focus(0);\">";
while($tablerow = mysql_fetch_array($getTableQuery))
{ if ((isset($_POST["GetTableName"]))&&($_POST["GetTableName"]==$tablerow[0]))
{ echo "<option value=\"".$tablerow[0]."\" selected>".$tablerow[0]."</option>"; }
else { echo "<option value=\"".$tablerow[0]."\">".$tablerow[0]."</option>"; }
}
echo "</select></td>";
echo "<td rowspan=\"3\">&nbsp;</td>";
echo "<td align=\"left\" valign=\"top\" colspan=\"2\">";
if (isset($_POST["GetTableListFieldCount"]))
{ echo "<strong>Number of fields</strong><br>(columns) to display<br><input type=\"text\" name=\"GetTableListFieldCount\" id=\"GetTableListFieldCount\" size=\"5\" value=\"".$_POST["GetTableListFieldCount"]."\" onblur=\"return isNum(this);\">"; }
else { echo "<strong>Number of fields</strong><br>(columns) to display<br><input type=\"text\" name=\"GetTableListFieldCount\" id=\"GetTableListFieldCount\" size=\"5\" value=\"4\" onblur=\"return isNum(this);\">"; }
echo "</td></tr>";
echo "<tr><td align=\"left\" valign=\"top\">";
if (isset($_POST["GetTableListRecordS"]) && $_POST["GetTableListRecordS"]!="")
{ echo "<strong>Starting Row Number</strong><br>(empty, 0, 1: beginning)<br><input type=\"text\" name=\"GetTableListRecordS\" id=\"GetTableListRecordS\" size=\"5\" value=\"".$_POST["GetTableListRecordS"]."\" onblur=\"return isNum(this);\">"; }
else { echo "<strong>Starting Row Number</strong><br>(empty, 0, 1: beginning)<br><input type=\"text\" name=\"GetTableListRecordS\" id=\"GetTableListRecordS\" size=\"5\" value=\"1\" onblur=\"return isNum(this);\">"; }
echo "</td><td align=\"left\" valign=\"top\">";
if (isset($_POST["GetTableListRecordT"]) && $_POST["GetTableListRecordT"]!="")
{ echo "<strong>Number of rows</strong><br>to display (empty or 0: all remaining)<br><input type=\"text\" name=\"GetTableListRecordT\" id=\"GetTableListRecordT\" size=\"5\" value=\"".$_POST["GetTableListRecordT"]."\" onblur=\"return isNum(this);\">"; }
else { echo "<strong>Number of rows</strong><br>to display (empty or 0: all remaining)<br><input type=\"text\" name=\"GetTableListRecordT\" id=\"GetTableListRecordT\" size=\"5\" value=\"0\" onblur=\"return isNum(this);\">"; }
echo "</td>";
$GetTableListFieldCountText = <<<GetTableListFieldCountText
<small class="x">
If records exist in the table, the resulting table will display either this number of fields, or all the fields in the table, whichever is less.<br><br>
Number is to be greater than 0 and less than or equal to 99. Anything else, such as 0, will yield all fields in table no matter how many fields there are.
</small>
GetTableListFieldCountText;
echo "</tr><tr><td colspan=\"3\" align=\"left\" valign=\"top\">".$GetTableListFieldCountText;
echo "<br><br><input type=\"submit\" name=\"GetTableListSubmit\" value=\"Show Records\">";
echo "</form>";

anyone got any ideas?

chump2877
05-07-2006, 04:32 AM
Suggestion: There's no need to echo out huge blocks of HTML code. Separate your HTML and PHP code better. Then you won;t have to escape every other quote mark in your code with a '\'.

There are other things you could do to optimize your code, but lets start with that...:thumbsup:

Then put your code into PHP tags for this post.

Those two things alone will make your code more readable for the rest of us.

finally, you claim that you are popluating your select menu by using a database. Check to make sure your db connection is solid, and echo out and check your queries for accuracy.

Also, I noticed you are displaying the values for each db row array like this:


$tablerow[0]

Do you really have a column in your database named "0" ??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum