Forum Moderators: coopster
Is there an easier way to have the listbox populated once, assign a variable to it (or something) and then just "refer" to it multiple times for each recorde displayed so that the box is not repeating the code for every record displayed?
Thank in advance for any help, it is really appreciated!
<table border="0">
<tr>
<td width="125"><strong>Cost Code</strong></td>
<td width="125"><strong>Vendor Assigned</strong></td>
<td><strong>Change Vendor</strong></td>
</tr>
<?php do { ?>
<tr id="assigned-<?php echo $row_vendcchood['id']; ?>">
<td width="125"><?php echo $row_vendcchood['costcode']; ?></td>
<td width="125"><?php echo $row_vendcchood['vendor']; ?></td>
<td>
<select name="change[]" id="change">
<option value="0">select a new Vendor</option>
<?php do { ?>
<option value="<?php echo $row_vendors['id']?>"><?php echo $row_vendors['vendor']?></option>
<?php }
while ($row_vendors = mysql_fetch_assoc($vendors));
$rows = mysql_num_rows($vendors);
if($rows > 0) {
mysql_data_seek($vendors, 0);
$row_vendors = mysql_fetch_assoc($vendors);}?>
</select></td>
<td>
<select name="delete[]" id="delete">
<option value="0">Select to Delete</option>
<option value="1">Delete Entry</option>
</select><input name="id[]" type="hidden" value="<?php echo $row_vendcchood['id']; ?>" />
</td>
</tr>
<?php } while ($row_vendcchood = mysql_fetch_assoc($vendcchood)); ?> <tr>
<td colspan="3" align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" /></td>
</tr>
</table>
<?php do { ?>
<option value="<?php echo $row_vendors['id']?>"><?php echo $row_vendors['vendor']?></option>
<?php }
while ($row_vendors = mysql_fetch_assoc($vendors));
$rows = mysql_num_rows($vendors);
if($rows > 0) {
mysql_data_seek($vendors, 0);
$row_vendors = mysql_fetch_assoc($vendors);}?>
could you eplain or provide a short example pf what you are referring to? I am somewhat new to most of this still.
Thanks again for your help!
so what you need to do is append all the html to a variable instead of sending it to the browser.
something like this
$thedrop = '';
$thedrop .= '<select name="whatever">';
while ($row_vendors = mysql_fetch_assoc($vendors)) {
$thedrop .= '<option value="' . $row_vendors['id'] . '">' . $row_vendors['vendor'] . '</option>';
}
$thedrop .= '</select>';
then you can just
echo $thedrop;
to output the constructed code
for( $i = 0, $c = count($vendors); $i < $c; $i += 1 ){
$query .= " (".$vendors[$i].",".$ccodes[$i].",".$primary_key."),";}
$query = substr_replace($query,"",-1);
$mysql_return = mysql_query("INSERT INTO vendcchood (vendor, costcode, nhood) VALUES".$query) or die(mysql_error());
Thanks so much again, what a great place! I have been scratching my head to get that little bit figured out for a while now...
if that is less than every day then you could have a cron that ran every night that created that same html, saved it to a variable and then wrote it to a file. You could then include that file wherever you needed it.
you might want to have it as a function and pass it a name for the select