Jump to content

Search the Community

Showing results for tags 'where'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 11 results

  1. I've been baffled by this for 2 days now and cannot figure it out after exhaustive searches. I'd like to think I'm doing this correctly, but cannot get it to work. I'm trying to use a variable within a query WHERE statement, and it shows 0 results. If I directly hardcode the text instead of using the variable, it works. The variable is pulling from a $_GET, and if I echo that variable, it is showing the correct text. Here's my code: $Domain = $_GET['Domain']; $result = mysql_query(SELECT Code, Title, Domain, Status FROM tablename WHERE Domain="$Domain" ORDER BY Code'); If I swap out "$Domain" for direct text, like "ABC", it works. I have tried swapping out the quotes and single quotes throughout the statement, removing the quotes around $Domain, concatenating the statement separately....all yield erros or the same result. And as stated, if I echo $Domain, it shows "ABC" (or whatever it's supposed to show), so i know it's pulling correctly from the $_GET. Anyone know what I'm doing wrong?
  2. Hi, Im having a problem and I can't seem to figure it out or find anything on the net. If I use the following code the script successfully updates every row in the table: mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud'"); However if I try updating the table using the WHERE clause in any of the combinations below nothing happens. mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud' WHERE Ads_ID=$DBROWID"); ---------------------------------------------------------------------- My Script: mysqli_query($con,"INSERT INTO Ads (Ads_ID, Ads_AID, Ads_Title) VALUES ('', '$Polished_AdRef', '$Polished_AdTitle')"); $DBROWID = mysqli_insert_id($con); mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID=$DBROWID"); // TRIED THESE TOO // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='$DBROWID'"); // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='5'"); Does any one know where I am going wrong?
  3. I have searched this forum as well as over 200 other forums and have not found the answer that is specific to my question. I have shortened my code drastically to assist in resolving this quickly - I have a search form that has criteria for the search criteria with "virtual" "columns" in an array but it's not working. If I search one column at a time it works just fine but when I try to search 8 columns with one select I get the following error: SELECT Error: Unknown column 'achievements' in 'where clause'. When a user selects search in Achievements, I need it to look at all 8 columns that are associated with achievements and bring back the results that match - the same as if the user selects search in Associations, I need it to look at all 5 columns and bring back the results that match. My shortened code is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Search</title> </head> <body> <form name="search" action="" method="POST"> <p>Search:</p> <p> Achievements/Associations: <input type="text" name="find1" /> in <Select NAME="field1"> <Option VALUE="achievements">Achievements</option> <Option VALUE="associations">Associations</option> </Select> <br><br> Secondary Education: <input type="text" name="find2" /> in <Select NAME="field2"> <Option VALUE="edu1sectype">Highest Certificate Attained</option> <Option VALUE="edu1secname">Highest Grade Passed</option> <Option VALUE="edu1secinst">Name of High School</option> <Option VALUE="edu1secdate">Date Completed</option> <Option VALUE="edu1secinsttyp">Type of Institution</option> <Option VALUE="subjects">Subjects</option> </Select> <br><br> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </p> </form> <?php $searching = $_POST['searching']; $find1 = $_POST['find1']; $field1 = $_POST['field1']; $find2 = $_POST['find2']; $field2 = $_POST['field2']; if ($searching =="yes") { echo "<br><b>Searched For:</b> $find1 $find2<br>"; echo "<br><h2>Results</h2><p>"; //If they did not enter a search term we give them an error // Otherwise we connect to our Database include_once "connect_to_mysql.php"; mysql_select_db("table_name") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim($find); $find = mysql_real_escape_string($find); $field = mysql_real_escape_string($field); $data = mysql_query("SELECT * FROM table_name WHERE upper(".$field1.") LIKE '%$find1%' AND upper(".$field2.") LIKE '%$find2%' ") or die("SELECT Error: ".mysql_error()); $result = mysql_query("SELECT * FROM table_name WHERE upper($field1) LIKE '%$find1%' AND upper($field2) LIKE '%$find2%' ") or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); echo "There are $num_rows records:<br>"; echo '<center>'; echo "<table border='1' cellpadding='5' width='990'>"; // set table headers echo "<tr><th>Reference</th> <th>First Name</th> <th>Last Name</th> </tr>"; //get images and names in two arrays $name= $row["name"]; $surname= $row["surname"]; $achieve1 = $row["achieve1"]; $achieve2 = $row["achieve2"]; $achieve3 = $row["achieve3"]; $achieve4 = $row["achieve4"]; $achieve5 = $row["achieve5"]; $achieve6 = $row["achieve6"]; $achieve7 = $row["achieve7"]; $achieve8 = $row["achieve8"]; $assoc1 = $row["assoc1"]; $assoc2 = $row["assoc2"]; $assoc3 = $row["assoc3"]; $assoc4 = $row["assoc4"]; $assoc5 = $row["assoc5"]; $edu1sectype = $row["edu1sectype"]; $edu1secinst = $row["edu1secinst"]; $edu1secname = $row["edu1secname"]; $edu1secdate = $row["edu1secdate"]; $edu1secinsttyp = $row["edu1secinsttyp"]; $subject1 = $row["subject1"]; $subject2 = $row["subject2"]; $subject3 = $row["subject3"]; $subject4 = $row["subject4"]; $subject5 = $row["subject5"]; $subject6 = $row["subject6"]; $subject7 = $row["subject7"]; $subject8 = $row["subject8"]; $compsoft1name = $row["compsoft1name"]; $compsoft2name = $row["compsoft2name"]; $compsoft3name = $row["compsoft3name"]; $compsoft4name = $row["compsoft4name"]; $compsoft5name = $row["compsoft5name"]; $compsoft6name = $row["compsoft6name"]; $achievements = array('achieve1', 'achieve2', 'achieve3', 'achieve4', 'achieve5', 'achieve6', 'achieve7', 'achieve8'); $associations = array('assoc1', 'assoc2', 'assoc3', 'assoc4', 'assoc5'); $subjects = array('subject1', 'subject2', 'subject3', 'subject4', 'subject5', 'subject6', 'subject7', 'subject8' ); $compsoft = array('compsoft1name', 'compsoft2name', 'compsoft3name', 'compsoft4name', 'compsoft5name', 'compsoft6name'); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td ALIGN=LEFT>" . $row['id'] . "</td>"; echo "<td ALIGN=LEFT>" . $row['name'] . "</td>"; echo "<td ALIGN=LEFT>" . $row['surname'] . "</td>"; echo "</tr>"; } echo "</table>"; //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query"; } } ?> </body> </html> Any assistance will be greatly appreciated as I have been working on this website for the past 4 months which has totalled over 150 pages and this is one of the last pages left to program and it's taken 6 days to get to this search page to this point.
  4. Hello this error is my problem. help me please $query = "SELECT * FROM car WHERE owner = ".$_POST['owner']."";
  5. I have a MySQL database on justhost with a field called "category" that I want to use in a WHERE query. The database opens fine without any WHERE clause. It's only when I begin to use a WHERE clause that I begin to get into trouble. All the "Gurus" out there tell me I need to be shifting over to PDO, so here is my attempt to get up to speed. The previous page (select_category.php) had a form with a selection drop-down box for category. I addressed it in the next file (quiz.php) like this: $cat = $_POST['category']; Now I want to query the data: $db = new PDO('mysql:host=localhost;dbname=' . $dbname , $dbusername, $pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql->prepare("SELECT * FROM QuestionsAnswers WHERE category = " . $cat); //This is line 23 foreach ($db->query($sql) as $row) { print '<p>' . $row['question'] .' <br /> '. $row['displaystring'] . '</p>'; } but I'm getting errors: I have been around and around on this for two days. Does anybody see what I am obviously missing? Thanks.
  6. I am doing a MySQL query in which the WERE clause contains an array that would have up to 100's of clauses. Basically I have a DB of words. When people enter letters to search for words containing those letters, and only those letters, it will at that to the query. For Example: * The code below is extremely abbreviated but you should get the point. <?php /* Say someone enters "abc" So I have it setup that $word = 'a' , OR `word` = 'b' , OR `word` = 'c' , OR `word` = 'ab' , OR `word` = 'ac' , OR `word` = 'ba' , OR `word` = 'ca' , OR `word` = 'cb' , OR `word` = 'abc' , OR `word` = 'cba' , OR `word` = 'bca' */ $sql = mysql_query("SELECT * FROM `words` WHERE `word` = ".$words." ORDER BY `word` DESC"); ?> Well this turns out to be quick with "abc" but if you enter abcdefg the combinations would be thousands and brutally slow! Is there a way to speed things up with a better, more optimized query? Thanks for your help!
  7. Ok so more on my lil comic app... (and all was going so well) GOAL: Trying to take a value from a form and create sql statement to look for that comic title in the DB and show what has been entered. (I.E search for Spider-Man -> Shows all Rows that Pertain to Spider-Man) So I can't figure out what is wrong with my code. Soon as I enter in my while statement my php failes however my query seems to be doing just fine. I've used the same kind of template on other pages and it works just fine the only difference is when I added a WHERE statement to my sql query. * NOTE: If I take the output of my query and plug it into mysql workbench I get the correct tables and results so I'm yeah kinda confused. * NOTE: The way I retrieve the $data variable is from a query from the form page which pulls all the comic names from the DB and displays in a drop down so the values that it passes are the exact same names / titles from the DB itself. <?php require('./scripts/con_db.php'); // Query DB for Comic_Names // $data = $_POST['comic_name']; $query = "SELECT * FROM `comic_db`.`comic_db` WHERE `comic_name`='$data'"; $com_sql = mysqli_query($comic_connect, $query); if (!$com_sql){ echo "Failed to connect to db" . mysqli_errorno(); } ?> <body> <p align="center"><img src="./images/comic_front.png" /></p> <table align="center"> <tr> <?php while($row = mysqli_fetch_array($com_sql)) { echo "<td>" .$row "</td>"; } ?> </tr> </table> <br /> <br /> <?php require('./scripts/footer.php'); ?> I should also say i've tried these other passes as well with no luck : <?php while($row = mysqli_fetch_assoc($com_sql)) { echo "<td>" .$row "</td>"; } ?> while($row = mysqli_fetch_assoc($com_sql)) { echo "<td>" .$row['comic_name'] "</td>"; } ?> <?php while($row = mysqli_fetch_assoc($com_sql)) { echo "<td>" .$row['$data'] "</td>"; } ?> I've also tried something I found in a book that says to do extract($row) then do my echo "<td>" .$row "</td>"; but that didn't work either so I'm missing something here is what the output for the SELECT string gives me as well from the browser which seems to be fine and again if I plug into mysql workbench it displays what I need.. SELECT * FROM `comic_db`.`comic_db` WHERE `comic_name`='Iron Man - V5' TY for help guys I've try to keep the ??'s down but I'm missing something (probably pretty obvious) so I need some guidence.
  8. MYSQL version: 5.5.24 I've got a problem. For my project in a class I want to show the characters of the person who is currently logged in. I get it to show every character in the database "characters" but not the logged in. I've tried to put this code in the WHERE but it will just ignore it and all of the other code jsut gets commented away when I do the "" to make it visible (in php) a friend of mine have written a C++ program that does this exact same thing altough I don't get it to work. So my question is what should I put in the WHERE to get the characters.name of the "current user" I've thought of making the: WHERE accounts.id = " . htmlentities($_SESSION['username'] ." Altough these two " makes so the rest of the code gets commented away and I've tried to put an extra " but nothing happens and I need the two " too make the htmlentities correct. I know this is both PHP and MYSQL but since it's the SQL part I need help with I put it here. If any admin see this as the wrong place to have my post please move it in that case or tell me to redo it at the right place
  9. Hello all! I need a bit of help with my coding. I'm new to php so be nice! My goal is to fetch data from a database, display it in divs and be able to sort, filter etc. And I have succeeded to a point but have run into a few problems. First you might want to have a look at the users point of view: http://tinyurl.com/bv6fm7b And yes I am using mysql and not mysqli or pdo which I will convert to in the future, but most of the tutorials I've found use mysql so to get my head around it I am using that, I also probably have not put it all together the best way so any suggestions would be great. Ok so the main problem at the moment are my sort/filtering functions. For example if you go to my page, click 'Rock and Pop' and then sort it by 'price high to low' it will forget the 'Rock and Pop' Where clause and vice versa. Also with this problem are the other sorting options and the pagination. I'm using the GET method so I thought I'd try and enter say ?categories=rockandpop&sort=PriceHigh manually to the end of the url, but it only applied the price sorting and not the category. There is a lot of code so I wont post all of it but try to put examples of each function. Categories: if($_GET['categories'] == 'rockandpop') { $query = "SELECT * FROM searchacts WHERE category='Rock and Pop'"; } if($_GET['categories'] == 'tributebands') { $query = "SELECT * FROM searchacts WHERE category='Tribute Bands'"; } Sort By: if(isset($_GET['sort'])) { if($_GET['sort'] == 'PriceLow') { $query = "SELECT * FROM searchacts ORDER BY price ASC"; } elseif($_GET['sort'] == 'PriceHigh') { $query = "SELECT * FROM searchacts ORDER BY price DESC"; } if(isset($_GET['upto'])) { if($_GET['upto'] == 'upto100') { $query = "SELECT * FROM searchacts WHERE price <= '100'"; } elseif($_GET['upto'] == 'upto200') { $query = "SELECT * FROM searchacts WHERE price <= '200'"; } Example of one of the forms: <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='get' name='form_filter' class="sortoptions" > <select name="sort"> <option value="all">All</option> <option value="PriceLow">Price (Low to High)</option> <option value="PriceHigh">Price (High to Low)</option> </select> <br /> <input type='submit' value = 'Re-Order your results'> </form> And the data into the divs: <?php $i=0; while ($i < $num) { $image=mysql_result($result,$i,"image"); $name=mysql_result($result,$i,"name"); $category=mysql_result($result,$i,"category"); $description=mysql_result($result,$i,"description"); $stamps=mysql_result($result,$i,"stamps"); $stickmen=mysql_result($result,$i,"stickmen"); $price=mysql_result($result,$i,"price"); $view=mysql_result($result,$i,"view"); $actpagelink=mysql_result($result,$i,"actpagelink"); ?> <a href="<?php echo $actpagelink; ?>" class="searchitem"> <div class="searchimage"><img src="<?php echo $image; ?>"/></div> <div class="searchtext"> <div class="searchname"><?php echo $name; ?></div> <div class="searchcategory"><?php echo $category; ?></div> <div class="searchdescription"><?php echo $description; ?></div> </div> <div class="searchstamps"><img src="<?php echo $stamps; ?>" /></div> <div class="searchstickmen"><img src="<?php echo $stickmen; ?>" /></div> <div class="searchprice"><span class="pricefrom">from</span>£<?php echo $price; ?></div> <div class="searchview"><img src="<?php echo $view; ?>" /></div> </a> I've also attached my full code if that helps. Thanks code.txt
  10. I am Simplifying my Question here with data as well. *I have a String of keywords that i have to search with my database's fields. *I have 4 fields(variables) upon which i have to apply Where clause. * I wanted to have a query that fetch data either one of 4 where clauses or all of them(OR operation in Where) Here is the Php Code that extracts keywords from string and make query. $condition = strtoupper($_GET['iname']); //for keywords string $operation = $_GET['operation'];//Operation Type AND OR between Keywords //these are four flags determining that which where clause is present $titleflag = "false"; $descriptionflag = "false"; $productoldflag = "false"; $productnewflag = "false"; //if title present if(/*title present or Not*/)//if Not { $titleflag = "false"; $title =''; $titlearray[] = "upper(name) LIKE '%%'"; } else { $title = $condition; $titleflag = "true"; //*************************** $search = strtoupper($title); $search = trim($search); $terms = explode(' ', $search); $count = 0; $line=""; foreach ($terms as $term) { if(($term == " ")) { if($count == 0) { $count++; $titlearray[] = "upper(name) LIKE '%".$term."%'"; } else continue; } else { $titlearray[] = "upper(name) LIKE '%".$term."%'"; } } } //This is it. i did for three other where clauses //description,misold,misnew //below down is my query where i construct the actual query $sql = "Select distinct id,name from item WHERE (".implode( $operation ." ", $titlearray).") AND ".$titleflag." OR (".implode( $operation ." ", $descriptionarray).") AND ". $descriptionflag. " OR (".implode( $operation ." ", $oldmisarray).") AND ". $productoldflag. " OR (".implode( $operation ." ", $newmisarray).") AND ". $productnewflag. " order by name asc"; //Provided Search String /* $condition = "Altera EMP"; */ //If value in $operation = AND then produced query will be look like /* AND OPeration Select distinct id,name from item WHERE (upper(name) LIKE '%ALTERA%' AND upper(name) LIKE '%EMP%') AND true OR (upper(description) LIKE '%ALTERA%' AND upper(description) LIKE '%EMP%') AND true OR (upper(productnoold) LIKE '%%') AND false OR (upper(productnonew) LIKE '%%') AND false order by name asc */ /* Or Operation Select distinct id,name from item WHERE (upper(name) LIKE '%ALTERA%'OR upper(name) LIKE '%EMP%') AND true OR (upper(description) LIKE '%ALTERA%'OR upper(description) LIKE '%EMP%') AND true OR (upper(productnoold) LIKE '%%') AND false OR (upper(productnonew) LIKE '%%') AND false order by name asc */ Now what the requirement is that I must use OR in every Keyword for all Where and hence forth for every keyword. and combine the result of all keyword search either AND or OR
  11. I am creating a search page with php and codeigniter. I created the query which is; "SELECT * FROM my_account WHERE inex='$inex' AND type='$type' AND date BETWEEN '$date1' AND '$date2' " $date1 and $date2 values comes from form input and I have no problem here. On the other hand $inex value is also coming from form dropdown. $options = array( 'Income' =>'Income', 'Expense' =>'Expense', ); echo "<td>" . form_dropdown('inex',$options) ."</td>"; Now, if i do a search between two dates, i have to use Income or Expense values. But, I need the third option in the options array so that i can also choose both so that i can see both income and expenses between these two dates. I think there is a simple answer for that but somehow i cant figure it out. helps are appreciated. thanks in advance.
  • 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.