good point Micah !! :-)

I don't get an error msg. Nothing happens.

included is the file

Below are the three issues I have with query_strings and sql. The formatting
is of the .php page is awful. I'm not certain it's legible.


1. Main issue -- be able to use a query_string variable in a sql statement

SELECT *
FROM whatever
WHERE someField = '$queryString_variable'

2. Be able to set defaults in case variable doesn't exist.

if(!isset($category)){$category="Shop";}

3. be able to modify results from a sql query with a query_string variable

$selection = mysql_query("
        while ($row = mysql_fetch_array($selection)){

        if (query_variable is "X"){

                echo $row["classID"];
                }else{
                echo "<b>" . $row["classID"] . "</b>";
        }


thanks all, this is driving me crazy. My bad for taking this project. Easy
for me in Cold Fusion, driving me nuts in PHP.

<?php


function getClasses(){

$username="";
$password="";
$database="XXX";
$hostname="localhost";

global $category;
global $Section;
global $reorder;
global $order;
global $location;


if(!isset($category)){$category="Shop";}
if(!isset($section)){$section="All";}
if(!isset($reorder)){$reorder="classCode";}
if(!isset($order)){$order="DESC";}
if(!isset($location)){$location="ALL";}


[EMAIL PROTECTED]($hostname,$username,$password);
mysql_select_db($database);

$selection = mysql_query("
                                                        SELECT *
                                                        FROM classes
                                                        WHERE
                                                                classCategory 
='$category' AND
                                                                classDeleted = 0
                                                        ORDER BY $reorder $order

                                                ");


        echo "<table border>\n";
        echo "<tr>\n";
        echo "<th class=\"header\">&nbsp;</th>\n";
        echo "<th class=\"header\">&nbsp;</th>\n";
        echo "<th class=\"header\">&nbsp;</th>\n";

        echo "<th class=\"header\">Section";

/* *************** AREA WITH PROBLEM *************************
        if ($section == "All"){

print "$category";

                if ($reorder == "classSection" && $order == "ASC"){
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&Section=All&reorder=classSectio
n&order=DESC\" class=\"header\">Section -up <img
src=\"/knittinghands/graphics/arrow-up.gif\" border=\"0\" alt=\"\"></a>";
                }elseif($reorder == "classSection" && $order == "DESC"){
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&Section=All&reorder=classSectio
n&order=ASC\" class=\"header\" class=\"header\">Section<img
src=\"/knittinghands/graphics/arrow-down.gif\" border=\"0\" alt=\"\"></a>";

                }else{
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&Section=All&reorder=classSectio
n&order=ASC\" class=\"header\">Section - no<img
src=\"/knittinghands/graphics/arrow-none.gif\" border=\"0\" alt=\"\"></a> ";
                }

        }else{

                if ($reorder == "classSection" && $order == "ASC"){
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&section=All&reorder=classSectio
n&order=DESC\" class=\"header\">Section<img
src=\"/knittinghands/graphics/arrow-up.gif\" border=\"0\" alt=\"\"></a>";
                }elseif($reorder == "classSection" && $order == "DESC"){
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&section=All&reorder=classSectio
n&order=ASC\" class=\"header\" class=\"header\">Section<img
src=\"/knittinghands/graphics/arrow-down.gif\" border=\"0\" alt=\"\"></a>";

                }else{
                        echo "<a
href=\"eventsAdminList.php?category=Knitting&section=All&reorder=classSectio
n&order=ASC\" class=\"header\">Section<img
src=\"/knittinghands/graphics/arrow-none.gif\" border=\"0\" alt=\"\"></a> ";

                        }
                }

************************************************ */
        echo "</th>\n";

        echo "<th class=\"header\">Code</th>\n";
        echo "<th class=\"header\">Class Title</th>\n";
        echo "<th class=\"header\">Cost</th>\n";

        while ($row = mysql_fetch_array($selection)){
        echo "<tr>\n \n";
        echo "<td><a href=\"eventsAdminEdit.php?class=" . $row["classID"] .
"\">EDIT</a></td>";
        echo "<td><a href=\"eventsAdminDelete.php?class=" . $row["classID"] .
"\">DEL</a></td>";

        if ($row["classHide"] == "0"){
                echo "<td><a href=\"eventsAdminHide.php?act=hide&class=" . 
$row["classID"]
. "\">HIDE</a></td>";
                }else{
                echo "<td class=\"hide\"><a 
href=\"eventsAdminHide.php?act=unhide&class="
. $row["classID"] . "\">unhide</a></td>";
                }
        // if ($section == "All"){
        //      echo "<td><nobr>" . $row["classSection"] . "</nobr></td>";
        //      }
        echo "<td>" . $row["classCode"] . "</td>";
        echo "<td><a href=\"eventsAdminListMore.php?category=" .
$row["classCategory"] . "&section=" . $row["classSection"] . "&id=" .
$row["classID"] . "\" class=\"none\">" . $row["classTitle"] . "</a></td>";

        echo "<td align=\"right\"> $". $row["classCost"] . "</td>\n";
        echo "</tr>";
        }
        echo "</table>";
}



$title = "XXX: Administration: List Classes";
?>

<html>
<head>
        <title><?php $title ?></title>
        <link href="admin.css" type="text/css" rel="stylesheet">
        <style>
                .hide
                        {
                        background-color        :       #CCCCCC;
                        }
        </style>

</head>
<body>

<div id="left"></div>
<div id="nav"><?php include ("nav.php"); ?></div>
<div id="bodyTitle">XXX: Administration Screen: Class Management</div>
<div id="body" style="width:<?php if ($section == "All"){echo
"650";}else{echo "550";}?>px;" class="box">
<br><br><br>

<?php

if(isset($_SERVER['QUERY_STRING']))
{
print $_SERVER['QUERY_STRING'];
if(isset($reorder)){print "<br>" . $reorder;}else{$section="dkdkdk";}
}else{
print "too bad";
}
?>
<ul>
<h1 style="width:400px; font-size:14px;"><?php print "$category > $section
?></h1>


        <?php getClasses(); ?>

</ul>
</div>

&nbsp;
</body>
</html>

 > -----Original Message-----
 > From: Micah Stevens [mailto:[EMAIL PROTECTED]
 > Sent: Wednesday, January 21, 2004 2:26 PM
 > To: [EMAIL PROTECTED]
 > Cc: mayo
 > Subject: Re: [PHP-DB] using query_strings in sql
 >
 >
 >
 > What error is it giving you? What's not happening? Saying 'It
 > doesn't work'
 > doesn't help much especially when you don't give all the code.
 >
 > -Micah
 >
 > On Wed January 21 2004 11:10 am, mayo wrote:
 > > 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:[EMAIL PROTECTED]
 > >  > Sent: Wednesday, January 21, 2004 1:59 PM
 > >  > To: [EMAIL PROTECTED]
 > >  > 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";}
 > >  > >
 > >  > >       [EMAIL PROTECTED]($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

Reply via email to