Solved

Query Question

Posted on 2011-03-16
10
269 Views
Last Modified: 2012-05-11
I have placed this question/issue a few times and have received some really great help!  I have not found an answer as of yet and am having an issue asking the question the correct way.  I'll attempt again:

I have a piece of code that evaluates info from a data feed against information that is in a data base.
If the information in a specific row within a column is different than the info in the feed, the DB field entry is updated. However, if that field is empty and evaluated the script updates the empty cell with the info from the feed, BUT it skips the messaging process.

So if $old_prodName is empty in the Database, this process does not work to then display the message.

if($new_prodName!=$old_prodName)$c->set_prodName($old_prodName, $new_prodName);

Open in new window

0
Comment
Question by:rgranlund
  • 5
  • 4
10 Comments
 
LVL 17

Expert Comment

by:nanharbison
ID: 35150512
So are you saying that the code you list here isn't working because it doesn't display some message?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 35151035
Correct.  Here is the entire thing:

<?php 
// CONNECT AND SELECT THE DATA BASE
set_error_handler ('oops'); 

// custom error handler 
function oops($type, $msg, $file, $line, $context) { 
	switch ($type) { 
// notices 
	case E_NOTICE: 
	break; 
// warnings 
	case E_WARNING: 
// report error 
	print "Non-fatal error on line $line of $file: $msg <br />"; 
	break; 
// other 
	default: 
	print "Error of type $type on line $line of $file: $msg <br />"; 
	break; 
	} 
} 
error_reporting(E_ALL);

echo "<h1>Update and Report</h1><br /><br />
*** To asure proper results, <h3>Please do not</h3> press any keys while this function is processing. ***<br /><br />
<fieldset>";

// THE CLASS DEFINITION TO HOLD THE CHANGELOG DATA FIELDS


class Changes
{
	protected $prodNo, $old_prodDisplayName, $new_prodDisplayName; 


//  CONSTRUCT PRODUCT NUMBER  //
   	public function __construct($prodNo)
    {
    	$this->prodNo = $prodNo;
		$this->old_prodDisplayName = NULL;
		$this->new_prodDisplayName= NULL;

		
    }
//  END CONSTRUCT PRODUCT NUMBER  //




//  DISPLAY NAME FUNCTION  //
	public function set_prodDisplayName($old_prodDisplayName, $new_prodDisplayName)
    {
		$this->old_prodDisplayName = $old_prodDisplayName;
		$this->new_prodDisplayName = $new_prodDisplayName;
    }




//  GET CHANGE MESSAGE  //
	public function get_change_message()  
    {
        // SET THE MESSAGE TO THE OBJECT'S prodNo ONLY
		$msg = $this->prodNo;


// ADD TO THE MESSAGE FOR ANY CHANGES
		


//  DISPLAY NAME  //
       	if ($this->old_prodDisplayName) {
			$msg .= "<br /> <h4>$this->new_prodName</h4><br /><span class=\"green\">THE DISPLAY NAME HAS CHANGED FROM<br />$this->old_prodDisplayName<br />
				TO:<br />$this->new_prodDisplayName</span><br />";
		}


// IF NO CHANGES NOTHING WAS ADDED TO THE MESSAGE STRING
		if ($msg == $this->prodNo)
		{
			echo "<fieldset>";
            $msg .= "<br/><span class=\"bold\">NO CHANGES MADE<br /> </span> <h4>$this->new_prodName</h4><br /></fieldset>";
        }
       	 	return $msg;
			
	}  //  END GET CHANGE MESSAGE  //

}  //  END CHANGES  //



$changelog = array();						
 						
 
 include('connect.php');

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );

// GET THE XML FEED IN A STRING
$xml = file_get_contents($url);
 
// MAKE AN OBJECT OUT OF THE XML
$obj = SimpleXML_Load_String($xml);

foreach ($obj->model as $model)
{  //  FOR EACH
	$new_brand = (string)$model->brand;
	$$new_prodType = (string)$model->prodType;
	$new_prodSubType = (string)$model->prodSubType;
	$new_prodDisplayName = (string)$model->prod_displayName;
	$prodNo = (string)$model->prodNo;

	
//  END OF PARSE AND PREP


	
 if ($new_brand=='F' && $new_prodSubType=='EG' && $new_prodType=='G') { 
 
		
// SELECT THE ROW FROM THE TABLE AND GET THE OLD INFORMATION INTO LOCAL VARIABLES
   		$q = "SELECT * FROM exp_weblog_data WHERE (field_id_104='$prodNo' AND weblog_id ='11') LIMIT 1";
			
    	$r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
		while($row = mysqli_fetch_assoc($r)) {
		
		$old_prodDisplayName = $row['field_id_34'];

			
// INSTANTIATE A NEW OBJECT TO LOG THE CHANGES  //

    	$c = new Changes($prodNo);

			if(($new_prodDisplayName!=$old_prodDisplayName) || ($old_prodDisplayName == NULL))$c->set_prodDisplayName($old_prodDisplayName, $new_prodDisplayName);

			$changelog[] = $c;



   		
		//$q = "UPDATE exp_weblog_data SET field_id_34='$new_prodDisplayName' WHERE field_id_104='$prodNo' LIMIT 1";
    	//$r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
	//echo $prodNo . "<br /><br />";	    
			
			}  //  END WHILE  //
	 }  //  END MAIN IF  //	
	}  //  END MAIN FOREACH  //


// NOW SHOW THE CHANGELOG
foreach ($changelog as $change_object) {
	$msg = $change_object->get_change_message();
	echo "<br /><fieldset>";
    echo "<br /><h4>PRODUCT NUMBER: &nbsp; $msg <br />" . PHP_EOL . "<br /></fieldset><br />";
}
echo "<br /><br /></fieldset>";
?>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 35151181
Have you tried echoing out the old and new prodDisplayNames?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 35151206
Yes, I have done that and it works.

if prodDisplayNames is empty in the database, the script updates it with the proper prodDisplayNames however, it skips giving the message.

if there is info in prodDisplayNames the script updates the info and gives the message.
0
 
LVL 17

Accepted Solution

by:
nanharbison earned 500 total points
ID: 35151320
Try changing
$old_prodDisplayName == NULL

to
$old_prodDisplayName == ""

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Author Comment

by:rgranlund
ID: 35151399
@nan  that was a really good idea but it did not work.so to re-state:
if old_prodDisplayName  is empty, the script will update but will not give the change message.
if old_prodDisplayName  is NOT empty, it will give the change_log message.


Weird.
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 35151481
Hmm, maybe its because you are missing the brackets around the if statement. I wasn't looking for this kind of error!
if(($new_prodDisplayName!=$old_prodDisplayName) || ($old_prodDisplayName == NULL))
{
     $c->set_prodDisplayName($old_prodDisplayName,
                 $new_prodDisplayName);
      $changelog[] = $c;
}

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 35151492
I still think you might have to use:

$old_prodDisplayName == ""

because this is not in the call to the datatbase, it is just what is being held in a variable.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 35151760
That did fix one error that I was not aware of.  However, it did not fix the issue I still have.  Any other suggestions?

Thank you in advance for your help!
0
 
LVL 5

Expert Comment

by:perezjos
ID: 37516302
Sorry I am confused,

in your question you mention $new_prodName that is not at all on the full listing of the class,  can we have  the script that call that class ?

thanks
jose

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now