Fearpig Posted September 6, 2006 Share Posted September 6, 2006 Hi guys,I've written the code below and its all working but I can't figure out the next step. Basically I have a page with a list of products when you click on a product it passes the variable to the next page wich displays all of the related parts.How do I set up this page to have a default vale incase someone gets to that page without the variable being set? If someone could point me in the right direction I'd be very happy!![code]$ModelSelect = $_GET['ModelSelect'];//basically I want a line here somewhere that says if $ModelSelect is null then 'Model1' $conn=odbc_connect('Spares','','');if (!$conn) {exit("Connection Failed: " . $conn);}$sql="SELECT * FROM Parts_Intranet WHERE Model='$ModelSelect'";$rs=odbc_exec($conn,$sql);if (!$rs) {exit("Error in SQL");}echo "<table border='1' cellpadding='2' cellspacing='0' class='Body2'><tr>";while (odbc_fetch_row($rs)){ $Model=odbc_result($rs,"Model"); $FileName=odbc_result($rs,"FileName"); $AirPressureSwitch=odbc_result($rs,"AIR Pressure Switch"); $AutoAirVent=odbc_result($rs,"AUTO Air Vent"); echo "<tr><td>Model</td><td>$Model</td></tr>"; echo "<tr><td>File Name</td><td>$FileName</td></tr>"; echo "<tr><td>Air Pressure Switch</td><td>$AirPressureSwitch</td></tr>"; echo "<tr><td>Auto Air Vent</td><td>$AutoAirVent</td></tr>";}odbc_close($conn);echo "</table>";[/code]Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/19912-default-variable/ Share on other sites More sharing options...
HuggieBear Posted September 6, 2006 Share Posted September 6, 2006 Give that a try...[code=php:0]<?phpif (!isset($_GET['ModelSelect'])){ $ModelSelect = "model";}?>[/code]Rich Link to comment https://forums.phpfreaks.com/topic/19912-default-variable/#findComment-87171 Share on other sites More sharing options...
Fearpig Posted September 6, 2006 Author Share Posted September 6, 2006 Nice one Rich,That worked a treat! Link to comment https://forums.phpfreaks.com/topic/19912-default-variable/#findComment-87199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.