Jump to content

Recommended Posts

The following page searches a table for missing info. Once it finds a record with info I need it will then display it in a list.

 

example:

hey bob, you are missing

stain number

border color

on joes cafe

 

hey mike, you are missing

blah blah

on truckstop cafe

 

The problem I'm having is it displays each distrubuter and restaurant even if all information is present.

 

example:

hey todd, you are missing

on waffle house

 

Anyone know how to fix this?

 

<?php

error_reporting(E_ALL); 
include('include/db_con.php'); 

/*If (date("d") != 1 || date("d")!=15){ exit; }*/ 

$query="SELECT dist_id, table_type, stain, paint, qty_oak, qty_nooak, contact_fname, rest_name, rest_address_1, rest_phone_sf, corners, stain, bg_colors, bg_img, bd_colors FROM DATABASE WHERE (order_year > '2006' || order_date > '05/01/2007') & (table_type = '' || qty_oak = '0' & qty_nooak = '0' || contact_fname = '' || rest_address_1 = '' || rest_phone_sf = '0' || corners = '' || stain = '' || paint = '')";

$result=mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$dist_id = $row['dist_id'];
$table_type = $row['table_type'];
$stain = $row['stain'];
$paint = $row['paint'];
$qty_oak = $row['qty_oak'];
$qty_nooak = $row['qty_nooak'];
$contact_fname = $row['contact_fname'];
$rest_name = $row['rest_name'];
$rest_address = $row['rest_address_1'];
$rest_phone_sf = $row['rest_phone_sf'];
$corners = $row['corners'];
$stain = $row['stain'];
$paint = $row['paint'];
$bg_colors = $row['bg_colors'];
$bg_img = $row['bg_img'];
$bd_colors = $row['bd_colors'];

$query2="SELECT email, fname FROM sales_rep WHERE sales_id=$dist_id";
$result2=mysql_query($query2);
while($row2 = mysql_fetch_assoc($result2)){
$email = $row2['email'];
$fname = $row2['fname'];

echo "$fname, you are missing:<br>";

  if ($table_type == "") {
       echo "type of table<br>";
  }
  if ($qty_oak != "0" & $stain == "") {
       echo "stain number<br>";
  }
  if ($qty_nooak != "0" & $paint == "") {
       echo "paint number<br>";
  }
  if ($contact_fname == "") {
       echo "restaurant contact<br>";
  } 
  if ($rest_address == "") {
       echo "restaurant address<br>";
  } 
  if ($rest_phone_sf == "0") {
       echo "restaurant phone number<br>";
  }
  if ($corners == "") {
       echo "size of corners<br>";
  }
  if ($bg_colors == "") {
       echo "background colors<br>"; 
  }
  if ($bg_img == "") {
       echo "background image<br>";
  }
  if ($bd_colors == "") {
       echo "border color<br>";
  }

echo "for $rest_name <br><br>";}}
?>

Link to comment
https://forums.phpfreaks.com/topic/51362-solved-displaying-all-only-need-some/
Share on other sites

try

<?php
while($row2 = mysql_fetch_assoc($result2)){
    $email = $row2['email'];
    $fname = $row2['fname'];

    $miss = 0;

    $str = "$fname, you are missing:<br>";

    if ($table_type == "") {
       $str .= "type of table<br>";
       $miss = 1;
    }
    if ($qty_oak != "0" & $stain == "") {
       $str .= "stain number<br>";
       $miss = 1;
    }
    if ($qty_nooak != "0" & $paint == "") {
       $str .= "paint number<br>";
       $miss = 1;
    }
    if ($contact_fname == "") {
       $str .= "restaurant contact<br>";
       $miss = 1;
    } 
    if ($rest_address == "") {
       $str .= "restaurant address<br>";
       $miss = 1;
    } 
    if ($rest_phone_sf == "0") {
       $str .= "restaurant phone number<br>";
       $miss = 1;
    }
    if ($corners == "") {
       $str .= "size of corners<br>";
       $miss = 1;
    }
    if ($bg_colors == "") {
       $str .= "background colors<br>"; 
       $miss = 1;
    }
    if ($bg_img == "") {
       $str .= "background image<br>";
       $miss = 1;
    }
    if ($bd_colors == "") {
       $str .= "border color<br>";
       $miss = 1;
    }

    $str .= "for $rest_name <br><br>";
    
    if ($miss) echo $str;
}
?>

lostboy (webberforums) had a similar solution

both work great

 

$query2="SELECT email, fname FROM sales_rep WHERE sales_id=$dist_id"; 
$result2=mysql_query($query2); 
while($row2 = mysql_fetch_assoc($result2)){ 
$email = $row2['email']; 
$fname = $row2['fname']; 

$boolShowDetails = false; 

$sOuput = "$fname, you are missing:<br>"; 

  if ($table_type == "") { 
       $sOuput .="type of table<br>"; 
       $boolShowDetails = true; 
  } 
  if ($qty_oak != "0" & $stain == "") { 
       $sOuput .="stain number<br>"; 
       $boolShowDetails = true; 
  } 
  if ($qty_nooak != "0" & $paint == "") { 
       $sOuput .="paint number<br>"; 
       $boolShowDetails = true; 
  } 
  if ($contact_fname == "") { 
       $sOuput .="restaurant contact<br>"; 
       $boolShowDetails = true; 
  } 
  if ($rest_address == "") { 
       $sOuput .="restaurant address<br>"; 
       $boolShowDetails = true; 
  } 
  if ($rest_phone_sf == "0") { 
       $sOuput .="restaurant phone number<br>"; 
       $boolShowDetails = true; 
  } 
  if ($corners == "") { 
       $sOuput .="size of corners<br>"; 
       $boolShowDetails = true; 
  } 
  if ($bg_colors == "") { 
       $sOuput .="background colors<br>";\ 
       $boolShowDetails = true; 
  } 
  if ($bg_img == "") { 
       $sOuput .="background image<br>"; 
       $boolShowDetails = true; 
  } 
  if ($bd_colors == "") { 
       $sOuput .="border color<br>"; 
       $boolShowDetails = true; 
  } 

   $sOuput .="for $rest_name <br><br>"; 
    
   if ($boolShowDetails == true) 
   { 
     echo $sOutput; 
   } 

   }} 
?>

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.