Jump to content

Recommended Posts

 

 

Is there a peramiter or way one can write something like this? and if so whats the proper way.

 

if ($test1 != "Select One")

{

$test1=$_Post[''];  // i know syntax is wrong but this isnt my problem

}

else

{

$test="*";  // This is where i am having problems.  If the user doesnt select a option on my dropdown it pretty much removes all the data from query results because they have input. 

}

 

$dlquery = "SELECT * FROM Whatever WHERE test1='$test1' AND test2='$test2'";

?>

 

that way when someone doesnt select a peramiter for test one it just includes any entry in the datafield in the quarry.  I would appreciate the help.  BTW ive only been doing this for about 3 weeks and this is first real snag ive had that just browsing you guys and w3 hasnt gotten me my answers.

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/
Share on other sites

try this

 

if ($test1 != "Select One")
{
$test1= "test1=".$_Post[''];  // i know syntax is wrong but this isnt my problem
}
else
{
$test="1";   // This is where i am having problems.  If the user doesnt select a option on my dropdown it pretty much removes all the data from query results because they have input. 
}

$dlquery = "SELECT * FROM Whatever WHERE $test AND test2='$test2'";
?>

[code]

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1185916
Share on other sites

kk here is the real script

------------------------------

<?php

 

include('srvdbcon.php');

 

$leaguepass = strip_tags($_POST['league']);

 

$type = strip_tags($_POST['type']);

$race = strip_tags($_POST['race']);

$vsrace = strip_tags($_POST['vsrace']);

$player1 = strip_tags($_POST['player1']);

$player2 = strip_tags($_POST['player2']);

$map = strip_tags($_POST['map']);

 

if ($leaguepass == "Select One")

{

$leaguepass = "1";

$dlquery = "SELECT * FROM replays WHERE league='$leaguepass' AND type='$type' AND race='$race' AND vsrace='$vsrace' AND player1='$player1' AND player2='$player2' AND map='$map'";

$dlqueryresult = mysql_query($dlquery);

 

 

if ($dlqueryresult)

{

while($dlqueryrow = mysql_fetch_array($dlqueryresult))

{

echo '<p><a href="http://www.mydomain.org/upload/' . $dlqueryrow['code'] . '.SC2Replay"' . ' >' . $dlqueryrow['name'] . '</a></p>';

}

}

else

{

echo "This shit isnt querying";

}

}

?>

 

 

-----------------------------------------------------

currently the qeury works fine if all fields have an option selected.  But when a field is left on "Select One" which is default option, the query only pulle data from field where "Select One" is in the field. So im trying to make it to where if Select One is selected it pulls includes all the data from that field in the quary.  So i was trying to get a * peramiter or all entries valid kinda thing going.  I tried to exchange the 1 but it didnt work.  THanks man.

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1185934
Share on other sites

try this

 

if ($test1 != "Select One")
{
$test1= "test1=".$_Post[''];  // i know syntax is wrong but this isnt my problem
}
else
{
$test="1";   // This is where i am having problems.  If the user doesnt select a option on my dropdown it pretty much removes all the data from query results because they have input. 
}

$dlquery = "SELECT * FROM Whatever WHERE $test AND test2='$test2'";
?>

[code]

 

i see the logic behind your change but when 1 is set for $test1 doesnt that just put a 1 in the quary bassically making the query read

 

$dlquery="SELECT * FROM whatever WHERE 1 and test2='$test2'";

 

cuase if so that creates an illegal search wouldnt it?

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1185939
Share on other sites

Sure. Just don't use a WHERE clause at all, and it will return all records from the table. If you just want one field, or a couple fields from all records specify it/them explicitly.

 

SELECT field1, field2 FROM table

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186462
Share on other sites

Bump.

So if I'm refering to a database table field, there's no way to include / allow all data entries from that table inti a query?

Such as

$dlquey= "SELECT * FROM table WHERE field='*'";

Honestly that is the same result as saying this..

$dlquery="SELECT * FROM whatever

In both cases you will get everything as there is essentially no search restrictions.  "Where field = ANYTHING" is the same thing as "Give me all fields"

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186463
Share on other sites

Im replying from a phone so bear with me.

 

so if what your saying works then i should be able to do something like the fallowing.

 

<?php

include srvdbcon // i know bad syntax

 

$field1=$_POST('field1');

$field2=$_POST('field2');

$field3=$_POST('field3');

// field two was only item seletected for query, meaning lets say he wants "5" to be in field2 but wants to include all the data in fields1/3

 

if ((field1="Select One") || (field1=""))

{$field1=""}

else {$field1="$field1"}

 

 

if ((field2="Select One") || (field2=""))

{$field2=""}

else {$field2="$field2"}

 

 

if ((field3="Select One") || (field3=""))

{$field3=""}

else {$field3="$field3"}

 

dlquery= "SELECT * FROM table" . $field1 . $field2 . $field3"

 

--------------------------------------------------------

problem is in the code i have, i have to write like 300 if statements to create the individual cases of haveing one field as "" or nul to not have it in the dlquery.

so the ifstatements make $field1-10= "" if theres no input in text or "Select One" is left as default on dropdown.  But theres still the  either  "." or the "," thats has to be delt with so i had to right more and more if'statements to make up for each possible combination of select one / null query entries.

 

My code is like 500 lines.  I'm trying to figure out a way that could make the code like 5 lines.

 

$dlquery="SELECT * FROM table1 WHERE field1='$field1', field2='$field2', field3='$field3'";

 

the only other code that would have to be done up is as fallows

 

if ($field1 == "SELECT ONE")

{$field1 = "*";}

else

{$field1 = $_POST('field1');}

 

the problem is when im usign the $variables in the $dlquery, they need to all be there or else i have to deal with removing or adding "," or "and" depending on box selections.

so if they all can have a value, even if that value says (all) then it would shorten code by about 300 lines.

 

Thanks for helping guys, i know im new to this im just really into the logic and am hopeing theres something like:  $field1="*", that is legal syntax. so when i move it to dlquery string it produces field1="*" and allows all data into query under that field.

 

 

SO ALL IN ALL THE QUESTION IS.

 

IS THERE A WAY.... WITHIN THE "SELECT * FROM table WHERE field1=" something to make it select all".

 

thats what im needing, is it possible, inside of select our outside as a variable.

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186468
Share on other sites

Bump.

So if I'm refering to a database table field, there's no way to include / allow all data entries from that table inti a query?

Such as

$dlquey= "SELECT * FROM table WHERE field='*'";

Honestly that is the same result as saying this..

$dlquery="SELECT * FROM whatever

In both cases you will get everything as there is essentially no search restrictions.  "Where field = ANYTHING" is the same thing as "Give me all fields"

 

but its not the same, one would pull all the data from all fields, and the other would only include the data from "field"  Or is there something im not seeing. Not to mention one will keep me from having restrictions being pulled from the other 9 queries.

 

clquery= "SELECT * FROM table WHERE field1="*", field2="*", Field3="4", field4="whatevertheytypedin" through field9;  Think you get my drift

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186470
Share on other sites

<?php

include('');

$leaguepass=strip_tags($_POST['league']);

$type = strip_tags($_POST['type']);

$race = strip_tags($_POST['race']);

$vsrace = strip_tags($_POST['vsrace']);

$player1 = strip_tags($_POST['player1']);

$player2 = strip_tags($_POST['player2']);

$map = strip_tags($_POST['map']);

$and= " AND ";

////////////////////////////////////////

////////////////////////////////////////

////////////////////////////////////////

if (($leaguepass == "Select One") && ($type == "Select One"))

{

$leaguepass = "";

}

else if ($leaguepass == "Select One")

{

$leaguepass = "  ";

}

else if (($leaguepass != "Select One")&&($type != "Select One"))

{

$leaguepass = "league='" . strip_tags($_POST['league']) . "' " . $and;

}

else

{

$leaguepass = "league='" . strip_tags($_POST['league']) . "' ";

}

///////////////////////////////////////

///////////////////////////////////////

///////////////////////////////////////

if (($type == "Select One") && ($race == "Select One"))

{

$type = "";

}

else if ($type == "Select One")

{

$type = "  ";

}

else if (($type != "Select One")&&($race != "Select One"))

{

$type = "type='" . strip_tags($_POST['type']) . "' " . $and;

}

else

{

$type = "type='" . strip_tags($_POST['type']) . "' ";

}

//////////////////////////////////////

//////////////////////////////////////

//////////////////////////////////////

if (($race == "Select One") && ($vsrace == "Select One"))

{

$race = "";

}

else if ($race == "Select One")

{

$race = "  " ;

}

else if (($race != "Select One")&&($vsrace != "Select One"))

{

$race = "race='" . strip_tags($_POST['race']) . "' " . $and;

}

else

{

$race = "race='" . strip_tags($_POST['race']) . "' ";

}

//////////////////////////////////////

if (($vsrace == "Select One") && ($player1 == ""))

{

$vsrace = "";

}

else if ($vsrace == "Select One")

{

$vsrace = "  ";

}

else if (($vsrace != "Select One")&&($player1 != ""))

{

$vsrace = "vsrace='" . strip_tags($_POST['vsrace']) . "' " . $and;

}

else

{

$vsrace = "vsrace='" . strip_tags($_POST['vsrace']) . "' ";

}

//////////////////////////////////////////

if (($player1 == "") && ($player2 == ""))

{

$player1 = "";

}

else if (($player1 == "") && ($player2 != ""))

{

$player1 = "  " . $and ;

}

else if (($player1 != "")&&($player2 != ""))

{

$player1 = "player1='" . strip_tags($_POST['player1']) . "' " . $and;

}

else

{

$player1 = "player1='" . strip_tags($_POST['player1']) . "' ";

}

//////////////////////////////////////////

if (($player2 == "") && ($map == "Select One"))

{

$player2 = "";

}

else if (($player2 == "") && ($map != ""))

{

$player2 = "  " . $and ;

}

else if (($player2 != "Select One")&&($map != "Select One"))

{

$player2 = "player2='" . strip_tags($_POST['player2']) . "' " . $and;

}

else

{

$player2 = "player2='" . strip_tags($_POST['player2']) . "' ";

}

///////////////////////////////////////

if ($map == "Select One")

{

$map = "";

}

else

{

$map = "map='" . strip_tags($_POST['map']) . "'";

}

////////////////////////////////////////////////////////

 

 

?>

 

<html>

<head><title></title>

<link rel="STYLESHEET" type="text/css" href="">

</head>

<body>

<div id="header">

<center><a href="index.html"><img src="images/.jpg" width="90%" height="200" border="0"></a></center>

</div>

<div class="colmask threecol">

<div class="colmid">

<div class="colleft">

<div class="col1">

<!-- CENTER COLUMN CONTENT  -->

<center>

<h2> Your query has produced the fallowing Replays</h2>

<p>Please click links below to download.</p>

<?php

$dlquery = "Select * FROM replays WHERE " . $leaguepass . $type . $race . $vsrace . $player1 . $player2 . $map;

$dlres = mysql_query($dlquery);

 

if ($dlres)

{

while($row=mysql_fetch_array($dlres, MYSQL_BOTH))

{

    echo "<p><a href=http://www./upload/";

echo ".SC2Replay>" . "File: " . $row['code'] ."  " . "Name: " . $row['name'] . "</a></p>";

echo "<p>" . $row['des'] . "</p>";

    echo "<br />";

    }

}

else

{

echo "<p>This shit isnt querying</p>";

echo $dlquery;

}

?>

<br />

<br />

<h3>Uploads</h3>

<p> If you would like to upload more replays then please do so <a href="upload.php">Here</a></p>

<br />

<h3> Downloads</h3>

<p> To browse/search for replays please do so <a href="download.php">Here. </a></p>

</center>

<!-- CENTER COLUMN CONTENT END -->

</div>

 

<div class="col2">

<!-- LEFT COLUMN START -->

<center><h2>Quicklinks</h2>

<p>Use these to navigate site.

<p><a href="index.php">Home</a></p>

<p><a href="download.php">Download</a></p>

<p><a href="upload.php">Upload</a></p>

 

<h2>HOT ITEMS</h2>

<p>The 5 best training Replays</p>

 

</center>

<!--LEFT COLUMN END -->

</div>

 

<div class="col3">

<!-- RIGHT COLUMN START -->

<center><h2>UNUSED SPACE</h2>

<h3>___________________</h3>

<h3>___________________</h3>

</center>

<!-- RIGHT COLUMN END -->

</div>

</div>

</div>

</div>

<div id="footer">

<center><p>This page was created by using stricktly html and css code.  Banner was not originally designed by the site.  Thank you for visiting </a>.</p></center>

</div>

</body>

 

 

</html>

 

----------------------------------------------------------

code exactly as it is on website, with full function

only thing i took out was url information of course. :)

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186472
Share on other sites

Not real clear on what your query is trying to do. -.-

 

But give this a try...

 

            <?php
            //rownamehere should be changed to any field in your database, say name for instance
            $dlquery = mysql_query("Select code,name,des FROM replays WHERE rownamehere='value'");

   if(mysql_num_rows($dlquery) > 0)
   {
            if ($dlquery)
            {

            while($row=mysql_fetch_array($dlquery))
            {
            echo "<p><a href=http://www./upload/";
            echo ".SC2Replay>" . "File: " . $row['code'] ."   " . "Name: " . $row['name'] . "</a></p>";
            echo "<p>" . $row['des'] . "</p>";
            echo "<br />";
             }

            }
            else 
            {
            echo "<p>Query failure.</p>";
            }
    }
    else
    {
         echo "No such result exists in the database.";
    }
            ?>

Link to comment
https://forums.phpfreaks.com/topic/230287-help-with-a-query/#findComment-1186473
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.