Jump to content

Combining 2 statements


chrispulliam

Recommended Posts

 

I Have the following 2 statements that I need help with to try to combine

 

<? 
$query="SELECT * FROM programs";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<select name=program_name value=''></option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[Title]>$nt[Title]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
?>

 

<option value="<?php echo $row_processing['eng_review']; ?>" selected="selected"><?php echo $row_processing['eng_review']; ?></option>

 

 

 

What I am needing to do is on my form pull in information from a database entry as well as pulling in a predefined list from a separate table.

 

Link to comment
https://forums.phpfreaks.com/topic/265767-combining-2-statements/
Share on other sites

I'll try to answer this with the information I think I've understood so far. You've got a pre-determined select option that you want to enter as well as some that you're pulling out of a database.

 

If you want to combine those two code you can just add the second line just before the while command so it doesn't get repeated in the loop.

 

<?php

$query="SELECT * FROM programs";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */

$result = mysql_query ($query);

echo "<select name=program_name value=''></option>";
// printing the list box select command

echo "<option value=\"" . $row_processing['eng_review'] . "\" selected=\"selected\">" . $row_processing['eng_review'] . "</option>"; //Where are you getting this array from? 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
	echo "<option value=$nt[Title]>$nt[Title]</option>";
	/* Option values are added by looping through the array */
}

echo "</select>";// Closing of list box 

?>

But I don't see where $row_processing[] array is defined so I don't know if this is what you wanted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.