Jump to content

update in Mysql table, PHP code not working


natasha_sharma

Recommended Posts

Hi,

 

I am just not able to figure out what is wrong with below code, its just not working:

 

If i run the MYSQL commands indivisually on mYSQL for testing they work fine.

 

Also, if i do a print_r($rows) then there is no output. So looks like the pointer is not even going to the loop.

 

What is the error?


	if (isset($_POST['fundamentals'])) 
	{				
					if (!isset($_POST['tickers']))
					{	
					$queray = "CREATE INDEX st_hist_index ON stock_history (ticker, date_dt, new_record_flag)";
					mysql_query($queray);
					}
					
										
				$query = "select ticker, date_dt, spill_over, net_sales, interest,  net_operating_profit, reserves_surp,  equity, debt, capex, operating_assets  from `fundamentals` order by ticker, date_dt";
				
				$rows = sqlfetch($query);
				if ($rows != "") {    
                            foreach ($rows as $row) {
								
			$ticker = $row['ticker'];
			$date_dt = $row['date_dt'];  
			$spill_over = $row['spill_over'];
			$net_sales_dis = $row['net_sales'];
			$interest_dis = $row['interest'];
			$net_operating_profit_dis = $row['net_operating_profit'];
			$reserves_surp_dis = $row['reserves_surp'];
			$equity_dis = $row['equity'];
			$debt_dis = $row['debt'];
			$capex_dis = $row['capex'];
			$operating_assets_dis = $row['operating_assets'];
			if ($_POST['sex'] == 'new')
			{
        $query = "UPDATE stock_history SET spill_over='$spill_over', category='Qtr Result', category_id=1, net_sales_dis = '$net_sales_dis', interest_dis = '$interest_dis', net_operating_profit_dis = '$net_operating_profit_dis', reserves_surp_dis = '$reserves_surp_dis', equity_dis = '$equity_dis', debt_dis = '$debt_dis', capex_dis = '$capex_dis', operating_assets_dis = '$operating_assets_dis' WHERE new_record_flag=1 AND ticker='$ticker' AND date_dt='$date_dt'";
            }
			else
			{	
        $query = "UPDATE stock_history SET spill_over='$spill_over' ,category='Qtr Result', category_id=1, net_sales_dis = '$net_sales_dis', interest_dis = '$interest_dis', net_operating_profit_dis = '$net_operating_profit_dis', reserves_surp_dis = '$reserves_surp_dis', equity_dis = '$equity_dis', debt_dis = '$debt_dis', capex_dis = '$capex_dis', operating_assets_dis = '$operating_assets_dis' WHERE ticker='$ticker' AND date_dt='$date_dt'";
			}
            mysql_query($query);
           
            
							}
                    }
			
			
				$queray = "ALTER table stock_history DROP index st_hist_index";
				mysql_query($queray);	
					
    }
Link to comment
Share on other sites

Why would one add an index everytime a script is run? If you WANT an index, then create it by hand and stop worrying about it.

 

As for other problems - turn on php error checking, add your own error checking (like test if your query runs before moving on) and see what pops up.

Link to comment
Share on other sites

The reason why i am adding-removing index on every run is, my master table (table1) is being updated (joined) by table2, table 3, table 4, table5 all in same code with different keys.

 

If i make one time index then i need almost 6-7 variables in index in TABLE1. Also, this code UPDATES TABLE1 and if the index has that many variables then they get refreshed and slowdown the update process.

 

That's my understanding...

Link to comment
Share on other sites

@ginerjm:

 

Thanks for your tip on checking php error. Need you guidance:

 

1) I am using XAMPP local server. So, what should i do to see the PHP run error?

 

2) Also, i saw your signature says

 

  error_reporting(E_ALL);

        ini_set('display_errors', '1');

 

So, i just need to add at top of my .php script and it will output the error if any?

Link to comment
Share on other sites

The reason why i am adding-removing index on every run is, my master table (table1) is being updated (joined) by table2, table 3, table 4, table5 all in same code with different keys.

 

If i make one time index then i need almost 6-7 variables in index in TABLE1. Also, this code UPDATES TABLE1 and if the index has that many variables then they get refreshed and slowdown the update process.

 

That's my understanding...

 

 

The code you posted has no joins. I suspect you have a bad database design. Post an SQL dump of your DB.

Link to comment
Share on other sites

The reason why i am adding-removing index on every run is, my master table (table1) is being updated (joined) by table2, table 3, table 4, table5 all in same code with different keys.


 


If i make one time index then i need almost 6-7 variables in index in TABLE1. Also, this code UPDATES TABLE1 and if the index has that many variables then they get refreshed and slowdown the update process.


 


That's my understanding...


 

Is this wrong understanding?

Link to comment
Share on other sites

Correct, Index will get updated, which i am well aware. 

 

But my contention is Performance and not index getting updated automatically. 

 

Having many indexes on a table will slowdown the UPDATE & INSERT into the table.

 

(if you re-read my posts above, i have explained that my main table is being updated with 4 other tables using different column combinations. Also the main table gets updated with at least 5000 New records every day. So there is UPDATE and INSERT happening everyday.

Link to comment
Share on other sites

main table is being updated with 4 other tables using different column combinations.

 This smells of a bad DB design which I believe is really your biggest problem that needs to be fixed FIRST. Post your DB schema. You also dont seem to have any concern that you are using obsolete mysql code.

Edited by benanamen
Link to comment
Share on other sites

 This smells of a bad DB design which I believe is really your biggest problem that needs to be fixed FIRST. Post your DB schema. You also dont seem to have any concern that you are using obsolete mysql code.

Okey I will post Schema today. Also, I am not a coder, i hired someone at freelancer. I have basic understanding of DB design, but you guys are expert so I think i wll have to revisit the design now.

Link to comment
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.