jamkelvl Posted January 15, 2010 Share Posted January 15, 2010 <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 More sharing options...
Felex Posted January 15, 2010 Share Posted January 15, 2010 use == not = = parameter, od assignment even if it is in if statement Link to comment https://forums.phpfreaks.com/topic/188637-simple-loop-and-if/#findComment-995880 Share on other sites More sharing options...
jamkelvl Posted January 15, 2010 Author Share Posted January 15, 2010 Rofl, I'm a noob. Should have known. Thanks! Link to comment https://forums.phpfreaks.com/topic/188637-simple-loop-and-if/#findComment-995886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.