Re: SELECT & FETCH ARRAY

From: Date: Thu, 14 Sep 2000 15:50:46 +0000
Subject: Re: SELECT & FETCH ARRAY
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2651@lists.php.net to get a copy of this message
Revised from direct email sent to you. I did have a typo. Depending on what option(0) is, something like this..... If your first option = "Any" then substitue "" for "Any", etc. This method will permit you to select from the database whether the user select noth, one or none of the toptions. If it doesn't work right (I may have typos [I'm half asleep]) simply include a line before $cursor = mysql_query($sql); that reads echo "sql statement reads = $sql"; this will let you see exactly what is being requested from mysql. ----------------------- $sql = "SELECT * FROM Accommodation "; if ($Town != "" OR $Grade != "") $sql .=$sql."WHERE "; if ($Town != "") $sql .= $sql.Town = $Town; if ($Grade != "") $sql .= $sql.Grade = $Grade; $cursor = mysql_query($sql); if (!$cursor) { echo("<H3>MySQL error: " . mysql_error() . "</H3>"); exit(); } while ( $row = mysql_fetch_array($cursor) ) { print("<TR><TD><b>" . $row["Grade"] . "</b><BR><BR></TD></TR>"); print("<TR><TD><b>" . $row["Establishment"] . "</b><BR></TD></TR>"); print("<TR><TD>" . $row["Town"] . "<BR></TD></TR>"); print ("<HR>"); } ?> This may not be the best programming solution, but I use that style and it's worked. >$cursor = mysql_query("SELECT * FROM Accommodation WHERE Town = '$Town' >AND Grade = '$Grade'"); >if (!$cursor) >{ > echo("<H3>MySQL error: " . mysql_error() . "</H3>"); > exit(); >} > >while ( $row = mysql_fetch_array($cursor) ) > >{ > >print("<TR><TD><b>" . $row["Grade"] . >"</b><BR><BR></TD></TR>"); >print("<TR><TD><b>" . $row["Establishment"] . >"</b><BR></TD></TR>"); >print("<TR><TD>" . $row["Town"] . >"<BR></TD></TR>"); >print ("<HR>"); >} > >?> ------------------------ On the point of tables - it depends on the table assignments and where the column is placed within thatr table, e-mail me the URL and I'll have a look. Regards At 03:00 PM 14/09/00 +0100, you wrote: >Okay PHP gurus I have a problem and I am hoping someone can help me >with it. > >I have the script below connecting to a db to extract info based on a >particular town($Town) and then on the type ($Grade) of accommodation >available in that town. >What happens is that if I select from my drop down menus the Town and >the Grade of accommodation I get what I want. However, if I neglect to >specify either of the two, that being Town or Grade I get nothing, what >I would like is all in either category to be displayed if one of the >select options is NULL. > >On a final note, this is probably a really crap question - ( I ask them >on occasion) - but I seem to have trouble containing a returned table >within say a defined area of 600 px width. Even whn I specify a table >width it always overides it. The table always stretches to 100% of a >given area. It works within frames where I can specify the master frame >width but I am trying to avoid the use of frames. > Steve Dickson <mailto:steve@nrb.com.au>steve@nrb.com.au <http://www.nrb.com.au/>Northern Rivers Business Guide P.O. Box 1247, Ballina, 2478 Phone (02) 6681-4481

« previous php.windows (#2651) next »