Jump to content

Recommended Posts

I'm attempting to make a customizable report page for our companies audit database but I can't get the one query to work right.

SELECT * FROM `auditrecord`

WHERE

`Type` = 9 OR

`Type` = 10 OR

`Type` = 11 OR

`Type` = 12 OR

`Type` = 13

AND

`AuditDate` >= '2008-09-11'

 

The query stops going through the list as soon as it gets it's first match in `Type`.

 

So I tried moving the date to the top

 

SELECT * FROM `auditrecord`

WHERE

`AuditDate` >= '2008-09-11'

AND

`Type` = 9 OR

`Type` = 10 OR

`Type` = 11 OR

`Type` = 12 OR

`Type` = 13

 

This query is built by a php script so it changes depending on what the user selects.

 

Any Ideas?

 

Sean

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/127897-solved-query-issues/
Share on other sites

First of all you should really use the code tags. The next question that I have is the type coming from a post if so you can use this:

 

<?php
$type = $_POST['type'];

$query = "SELECT * FROM auditrecord WHERE type = '$type'";

?>

 

 

When the user selects the type it will use that to query the database. Please let me know if that was helpful.

 

Link to comment
https://forums.phpfreaks.com/topic/127897-solved-query-issues/#findComment-662142
Share on other sites

The `Type` comes from another query as the `auditrecord` table only contains the audit type and not the area of concern. I'm try to get it to retrieve all the audit records in a specific area.

$sql = "SELECT `Type` FROM `audit_types` WHERE `AreaID` = ".$area;

$result = mysql_query($sql);

while ($type_raw = mysql_fetch_array($result)) {
  $type[] = $type_raw['Type']; 
  }

foreach ($type as $a) {
  if (isset ($sql_temp1)) {  // Adds an OR if we all ready have something in $sql_temp
       $sql_temp1 = $sql_temp1." OR ";
       } 
    $sql_temp1 = $sql_temp1. " `Type` = ".$a;
    }
$sql_temp = $sql_temp1." AND ".$sql_temp;

Link to comment
https://forums.phpfreaks.com/topic/127897-solved-query-issues/#findComment-662212
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.