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

Link to comment
Share on other sites

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.