RE: [PHP-DB] using query_strings in sql
| From: | mayo | Date: | Wed, 21 Jan 2004 19:28:32 +0000 |
| Subject: | RE: [PHP-DB] using query_strings in sql | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-32555@lists.php.net to get a copy of this message | ||
my bad: I typed in the script and forgot the echo.
-- gil
> -----Original Message-----
> From: Rick Dahl [mailto:dmbserver@hotmail.com]
> Sent: Wednesday, January 21, 2004 2:28 PM
> To: mayo; php-db@lists.php.net
> Subject: Re: [PHP-DB] using query_strings in sql
>
>
> Looking at that. You are combining html and php without distinguishing
> between the two. I am assuming you are in "php mode" because
> html wouldn't
> give you errors. try this:
>
> echo "<a href='somefile.php?order=";
> if ($order == "ASC"){
> echo "DESC";
> }else{
> echo "ASC";
> }
> echo "'>";
>
>
> ----- Original Message -----
> From: "mayo" <mayo@nycinteractive.com>
> To: <php-db@lists.php.net>
> Sent: Wednesday, January 21, 2004 1:10 PM
> Subject: RE: [PHP-DB] using query_strings in sql
>
>
> > I have a table displaying data. The column headers are links that allow
> the
> > users to order the content in ASC or DESC.
> >
> > basic version is:
> >
> > <a href="somefile.php?order=ASC">Title</a>
> >
> >
> > a closer to reality version is (or would be if it worked)
> >
> > <a href="somefile.php?order=
> > if ($order == "ASC"){
> > echo "DESC";
> > }else{
> > echo "ASC";
> > }
> > ">
> >
> > (Actually that would be a switch/case :-) )
> >
> >
> > The sql call is
> >
> > $selection = mysql_query("
> > SELECT *
> > FROM classes
> > ORDER BY title $order
> > ")
> >
> >
> > And since there is no query string when someone lands on the page there
> > needs to be a default value set:
> >
> >
> > // setting the default variables
> >
> > if(!isset($order)){$order="ASC";}
> >
> > Unfortunately its not working :(
> >
> >
> > thx, gil
> >
> >
> > > -----Original Message-----
> > > From: Micah Stevens [mailto:micah@raincross-tech.com]
> > > Sent: Wednesday, January 21, 2004 1:59 PM
> > > To: php-db@lists.php.net
> > > Cc: mayo
> > > Subject: Re: [PHP-DB] using query_strings in sql
> > >
> > >
> > >
> > > I may be misunderstanding you, but your first statement about
> > > pulling from a
> > > query string is throwing me.
> > >
> > > <?php echo $section; ?> will only display the value of $section
> > > on the screen.
> > > You will need to build a form to get a value into $section.
> > >
> > > <form action="soemthing.php">
> > > <input type="text" name="section">
> > > </form>
> > >
> > > something.php:
> > >
> > > <?php echo "This is what was submitted in the form: ".$section; ?>
> > >
> > > Now you can do your query:
> > >
> > > $selection = mysql_query("SELECT *
> > > FROM classes
> > > WHERE
> > > classCategory = '$section'
> > > ")
> > >
> > > you'll notice I pulled the other variables out since you had not
> > > defined them
> > > yet, like your ordering variables. Otherwise the SQL would end
> > > with ORDER
> > > which will cause an error..
> > >
> > > -Micah
> > >
> > >
> > > On Wed January 21 2004 10:41 am, mayo wrote:
> > > > I'm a cold fusion refugee and am having incredible problems
> > > with something
> > > > that I think is relatively easy -- so I must be missing
> > > something basic.
> > > >
> > > > I would like to pull info from a query string and use it
> > > inside a database
> > > > call.
> > > >
> > > > I can pull the query string into a general variable:
> > > >
> > > > <?php echo $section; ?>
> > > >
> > > > now I would like to use it in a SQL statement, or in
> > > > if/else clauses to modifiy results from queries.
> > > >
> > > > examples below:
> > > >
> > > >
> > > > USE query_string in SQL :
> > > >
> > > > <?php
> > > >
> > > > function whatever(){
> > > >
> > > > $username = "";
> > > > ...
> > > >
> > > > // setting the default variables
> > > >
> > > > if(!isset($category)){$category="Something";}
> > > > if(!isset($section)){$section="SomethingElse";}
> > > >
> > > > $connection=@mysql_connect($hostname,$username,$password);
> > > > mysql_select_db($database);
> > > > $selection = mysql_query("
> > > > SELECT *
> > > > FROM classes
> > > > WHERE
> > > > classCategory = '$category'
> > > > ORDER BY $reorder $order
> > > > ")
> > > >
> > > > ...
> > > >
> > > > ?>
> > > >
> > > > The PHP SQL call below work nicely:
> > > >
> > > > while ($row = mysql_fetch_array($selection)){
> > > >
> > > > echo $row["sectionName"];
> > > >
> > > > }
> > > >
> > > > now I would like to do an if/else to modifiy it:
> > > >
> > > >
> > > >
> > > > while ($row = mysql_fetch_array($selection)){
> > > >
> > > > if (section == $sectionName){
> > > > echo "<b>" . $row["sectionName"] .
> > > > "</b>";
> > > > }else{
> > > > echo $row["sectionName"];
> > > > }
> > > >
> > > > Nothing is working. I must be missing something basic over here.
> > > >
> > > > thx, Gil
> > >
> >
> > --
> > 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
>