RE: [PHP-DB] elseif statement syntax
Thanks for responding Steve, My error reporting is turned on, because I always get errors. I found the problem, I had two ;; at the end of one of the statements. Thanks- Andrea -Original Message- From: Steve Cayford [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 10:27 AM To: Andrea Caldwell Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] elseif statement syntax You probably have error reporting turned off in your php.ini file or you may be directing errors into your log file, try checking there. Why are you tacking "or die(mysql_error())" on the end of each of your query assignments? You're just assigning a string to a variable so there's nothing to fail, or at least no mysql errors. -Steve On Wednesday, March 20, 2002, at 10:41 AM, Andrea Caldwell wrote: > Hi All, I'm pretty new at this, so go easy on me please ;-) > > What is wrong w/ this syntax? If the search results are 0, it just > displays > a blank screen instead of echoing the error message if numresults ==0 > or the > mysql_error message. If data is found, everything is fine. Thanks in > advance for your help! > > if($searchterm){ > $query = "select directory.realname, directory.phone, directory.ext, > directory.phone2, directory.email, directory.location from directory > where > realname like '%".$searchterm."%'" or die (mysql_error()); > } > elseif($location){ > $query = "select directory.realname, directory.phone, directory.ext, > directory.phone2, directory.email, directory.location from directory > where > location like '%".$location."%'" or die (mysql_error()); > } > else{ > $query = "select directory.realname, directory.phone, directory.ext, > directory.phone2, directory.email, directory.location from directory > where > location like '%".$searchloc."%'" or die (mysql_error()); > } > > $result = mysql_query($query) or die (mysql_error()); > $num_results = mysql_num_rows($result)or die (mysql_error());; > > if($num_results==0){ > echo "Sorry, nothing matched your search request. Please go back and > try > again."; > } > > else { > echo "Number of Entries Found: > ".$num_results.""; > } > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] elseif statement syntax
Hi All, I'm pretty new at this, so go easy on me please ;-) What is wrong w/ this syntax? If the search results are 0, it just displays a blank screen instead of echoing the error message if numresults ==0 or the mysql_error message. If data is found, everything is fine. Thanks in advance for your help! if($searchterm){ $query = "select directory.realname, directory.phone, directory.ext, directory.phone2, directory.email, directory.location from directory where realname like '%".$searchterm."%'" or die (mysql_error()); } elseif($location){ $query = "select directory.realname, directory.phone, directory.ext, directory.phone2, directory.email, directory.location from directory where location like '%".$location."%'" or die (mysql_error()); } else{ $query = "select directory.realname, directory.phone, directory.ext, directory.phone2, directory.email, directory.location from directory where location like '%".$searchloc."%'" or die (mysql_error()); } $result = mysql_query($query) or die (mysql_error()); $num_results = mysql_num_rows($result)or die (mysql_error());; if($num_results==0){ echo "Sorry, nothing matched your search request. Please go back and try again."; } else { echo "Number of Entries Found: ".$num_results.""; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Querying MySQL using PHP - modify existing query
I am a serious newbie (like less than two weeks & never programmed before), so I hope my code doesn't suck too bad & this isn't a really bad question... but here goes... I would like to modify this query so that it doesn't return the username, realname, and office results each time. The way the query is now, I see the username, realname & office results duplicated for each 'alias' result that is in the data. Instead, I'd like to see the username, realname & office only once & a list of the associated 'alias' (es) underneath it. If anyone can help w/ some "semi-real" code, that would be great. Since I'm new, it really helps to have code that actually reflects my field names so that I can learn from it. I appreciate any help you can provide. Thanks in advance! ~Andrea $query = "select users.username, users.realname, users.office, users.location, users.office_phone, users.alt_phone, users.password, alias.alias from users, alias where users.username like '%".$searchterm."%' and users.username = alias.username"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "Number of Users found: ".$num_results.""; for ($i=0; $i <$num_results; $i++){ $row = mysql_fetch_array($result); echo "".($i+1).". Username: "; echo htmlspecialchars( stripslashes($row["username"])); echo "Real Name: "; echo htmlspecialchars( stripslashes($row["realname"])); echo "Office: "; echo htmlspecialchars( stripslashes($row["office"])); echo "Alias: "; echo htmlspecialchars( stripslashes($row["alias"])); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]