Jump to content


Photo

default variable


  • Please log in to reply
2 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 September 2006 - 03:18 PM

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

$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>";

Thanks in advance.
"Whats wrong with the cat?" - Mrs Schrödinger

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 September 2006 - 03:23 PM

Give that a try...

<?php
if (!isset($_GET['ModelSelect'])){
   $ModelSelect = "model";
}
?>

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 September 2006 - 04:00 PM

Nice one Rich,
That worked a treat!
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users