logo       

RE: SQL: Limit 1 usage?: msg#00802

Subject: RE: SQL: Limit 1 usage?
Display mysql_error() in your die() statement... so you actually know
why your query is failing instead of a generic, worthless error message.

If you're not getting the statement in your die() function, then the
query is running, but it's not matching any rows. 

Also, FYI: Inside of a double quoted string, you can use {$_POST['key']}
or $_POST[key]... both are correct. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/

> -----Original Message-----
> From: jason wesley upton [mailto:upton@xxxxxxxxx]
> Sent: Thursday, January 30, 2003 5:12 PM
> To: php-db@xxxxxxxxxxxxx
> Cc: ignatius.reilly@xxxxxxx
> Subject: Re: [PHP-DB] SQL: Limit 1 usage?
> 
> Hmm, I trried your syntax and same problem.
> 
> I tried it exactly like this:  (though i'd like to stress that it
worked
> with the code labeled ORIGINAL below)
> 
> 
> <?php
> 
> 
> $connection = mysql_connect("********","*****","*********")
> or die("Couldn't make connection...because I hate you.");
> 
> 
> $db = mysql_select_db("national", $connection)
> or die("Couldn't select database.");
> 
> 
> $sql = "SELECT * FROM accessnums WHERE areacode='{$_POST['areacode']}'
and
> city='{$_POST['cityselected']}' ORDER BY network LIMIT 1";
> 
> 
> // ORIGINAL $sql = "SELECT * FROM accessnums WHERE
> areacode='$_POST[areacode]' and city='$_POST[cityselected]' ORDER BY
> network LIMIT 1";
> 
> //  WORKS just needs tweaking: SELECT * FROM accessnums WHERE
> areacode="318" and city="monroe" ORDER BY network LIMIT 1;
> 
> 
> $sql_result = mysql_query($sql,$connection)
> or die("Couldn't execute query.");
> 
> 
> while ($row = mysql_fetch_array($sql_result)) {
> 
> $network = $row["network"];
> $areacode = $row["areacode"];
> $cityselected = $row["cityselected"];
> 
> }
> 
> 
> 
> if ($network == 1):
>     echo "<p>This customer is on network: <font size=\"4\">A</font>.
This
> is Bayou Internet's network.<br>They should  download Dialer A at: <a
> href=
>
\"http://www.bayou.com/dialer/dialer.exe\";>http://www.bayou.com/dialer/d
ia
> ler.exe</a></p>";
> elseif ($network == 2):
>     echo "<p>This customer is on network: <font size=\"4\">B</font>.
This
> is Surf.net's network.<br>They should download Dialer B at: <a
> href=\"http://www.bayou.com/dialer/dialer-b.exe\";>
> http://www.bayou.com/dialer/dialer-b.exe</a></p>";
> elseif ($network == 3):
>     echo "<p>This customer is on network: <font size=\"4\">B</font>.
This
> is Surf.net's network.<br>They should download Dialer B at: <a
> href=\"http://www.bayou.com/dialer/dialer-b.exe\";>
> http://www.bayou.com/dialer/dialer-b.exe</a></p>";
> elseif ($network == 4):
>     echo "<p>This customer is on network: <font size=\"4\">E</font>.
This
> is Dual.usa / @usa's network.<br>They  should download Dialer E at: <a
> href=\"http://www.bayou.com/dialer/dialer-
> e.exe\">http://www.bayou.com/dialer/dialer-e.exe</a></p>";
> elseif ($network == 5):
>     echo "<p>This customer is on network: <font size=\"4\">C</font>.
This
> is Pop.net's network.<br>They should download Dialer C at: <a
> href=\"http://www.bayou.com/dialer/dialer-c.exe\";>
> http://www.bayou.com/dialer/dialer-c.exe</a></p>";
> elseif ($network == 6):
>     echo "<p>This customer is on network: <font size=\"4\">D</font>.
This
> is World.net's network.<br>They should download Dialer D at: <a
> href=\"http://www.bayou.com/dialer/dialer-d.exe\";>
> http://www.bayou.com/dialer/dialer-d.exe</a></p>";
> else:
>     echo "There has been a data error.  This is most likely the
> programmer's fault.  Blame funding.  <a
> href=\"http://www.bayou.com/dialer/admin/numbercheck.php\";>Ignore and
try
> again.</a>";
> endif;
> 
> 
> mysql_free_result($sql_result);
> mysql_close($connection);
> 
> ?>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 1/30/2003 3:51:15 PM, "Ignatius Reilly" <ignatius.reilly@xxxxxxx>
wrote:
> 
> >Doubly wrong PHP syntax.
> >
> >Try instead:
> >$sql = "SELECT * FROM accessnums WHERE
areacode='{$_POST['areacode']}'
> and
> >city='{$_POST['cityselected']}' ORDER BY network LIMIT 1";
> >
> >Ignatius
> >____________________________________________
> >----- Original Message -----
> >From: "jason wesley upton" <upton@xxxxxxxxx>
> >To: <php-db@xxxxxxxxxxxxx>
> >Sent: Thursday, January 30, 2003 9:42 PM
> >Subject: [PHP-DB] SQL: Limit 1 usage?
> >
> >
> >> Currently I have a script that contains this piece of code:
> >>
> >>
> >> $sql = "SELECT MIN(network)
> >> AS 'network' FROM accessnums WHERE areacode='$_POST[areacode]' and
> >city='$_POST[cityselected]'";
> >>
> >>
> >> This works fine and accomplishes what I need.  Some requirements
> changed
> >today and I now need to get more than just "network".  In MySQL
command
> line
> >I tried this:
> >>
> >> SELECT * FROM accessnums WHERE areacode="504" and city="New
Orleans"
> ORDER
> >BY network LIMIT 1;
> >>
> >> This gives me the exact response I require.  However, when plugging
it
> >into my php code:
> >>
> >> $sql = "SELECT * FROM accessnums WHERE areacode=$_POST[areacode]'
and
> >city='$_POST[cityselected]' ORDER BY network LIMIT 1";
> >>
> >> It can't execute the query.  Any suggestions?
> >>
> >>
> >>
> >>
> >> Jason Wesley Upton - Web Design / Development - Application
Development
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --
> 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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe