Jump to content

Simple loop and if?


jamkelvl

Recommended Posts

						<select name="shipTo" id="shipTo">
							<?php
								// Suppress all errors
								error_reporting(0);

								// Set all variables
								$hostname = "xxxxxxxx";
								$username = "xxxxxxxx";
								$password = "xxxxxxxx";
								$dbid="xxxxxxxx";

								// Attempt database connection
								$connect = mysql_connect($hostname, $username, $password);
								if($connect == false){
									echo('<p class="error">We are having technical difficulties and apologize for the inconvenience. Please try again later.</p>');
								}

								// Select database
								$db = mysql_select_db($dbid);

								// query database
								$select = "SELECT location_name FROM locations";
								$result = mysql_query($select);							

								// get results
								while($row = mysql_fetch_array($result)){
									extract($row);
									if ($location_name = $ship_to) {
										echo '<option value="'.$location_name.'" selected>'.$location_name.'</option>';	
									} else {
										echo '<option value="'.$location_name.'">'.$location_name.'</option>';
									}
								}									
								mysql_close($connection);
							?>
						</select>

 

Works great only it displays just the $location_name that is equal to $ship_to, it will not show any other locations stored in the database table.

 

Anyone know why?

Link to comment
https://forums.phpfreaks.com/topic/188637-simple-loop-and-if/
Share on other sites

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.