Re: Can a range be passed to a query?(RESOLVED)

From: Date: Mon, 03 Aug 2009 19:13:58 +0000
Subject: Re: Can a range be passed to a query?(RESOLVED)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-296233@lists.php.net to get a copy of this message
On Mon, 2009-08-03 at 09:33 -0700, Miller, Terion wrote: > Here is is incase anyone else ever needs it. > > //Create array with letters AND number sign > $letters = range('A','Z'); array_push($letters, > 'nums'); $menu = ''; > $selectedLetter = isset($_GET['letter']) ? $_GET['letter'] : null; > foreach($letters as $letter) { > if($letter == $selectedLetter && $selectedLetter != 'nums') > { $menu .= sprintf('%s&nbsp', $letter); > } else if($letter == $selectedLetter && > $selectedLetter == 'nums') { > $menu .= sprintf('%s&nbsp', '#'); } > else { if($letter == > 'nums') { $menu .= > sprintf('<a href="browse.php?letter=%s">%s</a>&nbsp;', > 'nums', '#'); } > else { $menu .= > sprintf('<a href="browse.php?letter=%s">%s</a>&nbsp;', $letter, > $letter); } } > } echo "<div > align=\"center\"><b>{$menu}</b><br /></div>"; > > > //Show all restaurants that start with $letter not between > "A" and "Z" if ($selectedLetter == "nums") > { for($i = 0; $i <= 9; $i++) > { $sql = "SELECT DISTINCT ID, name, address FROM restaurants > WHERE name LIKE '$i%'"; > $result = mysql_query($sql) or die(mysql_error()); > while($row = mysql_fetch_assoc($result)) > { $name = $row['name']; > printf('<a href="view.php?ID=%s"><b>%s</b><br > />%s<br /><br /></a>', $row['ID'], $row['name'], > $row['address']); } > } > } else { $sql = > "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE > '$selectedLetter%'"; $result = > mysql_query($sql) or die(mysql_error()); > while($row = mysql_fetch_assoc($result)) { > $name = $row['name']; printf('<a > href="view.php?ID=%s"><b>%s</b><br />%s<br /><br > /></a>', $row['ID'], $row['name'], $row['address']); > } > } > > On 8/3/09 10:12 AM, "Miller, Terion" <tmiller@springfi.gannett.com> wrote: > > > > > On 8/3/09 9:46 AM, "sono-io@fannullone.us" <sono-io@fannullone.us> wrote: > > > > On Aug 3, 2009, at 7:19 AM, Miller, Terion wrote: > > > Not sure why none of these are working for me since you have them > > tested against your table....I get this error... > > Hopefully I'm not speaking out of turn here, but did you by any > chance copy and paste that code from an e-mail? If so, there may be > invisible characters masquerading as spaces. I use TextWrangler (on a > Mac) and choose "Zap Gremlins..." so they show and then delete them. > That usually solves the problem for me. > > Frank > > > Thanks Frank, but yep I'm using an editor that is good about such things, I'm not > sure what the problem can be. And I get all the way to noon to figure it out. > > Just for the future, are you able to format your emails as pure text before you send them, as they get real mangled by the time they reach us otherwise! :p Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#296233) next »