iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2009, 09:02 AM
bizgen's Avatar
WebProWorld New Member
 
Join Date: Mar 2004
Location: South of England, UK
Posts: 24
bizgen RepRank 0
Default Struggling with audit trail

I have created an audit trail to record the creation of a new list of selected categories against a newly created service provider.

The problem I am having is that it is only posting the first record to the database table even though I have included the audit trail within the foreach statement. The same audit trail has worked fine in other areas of the database, but this is the only one where I have used it in relation to an array and a foreach statement so am wondering if I am doing something wrong with that.

Code below......................


foreach ($_POST['selected_cat'] as $levelc_lk) {
$querycatcodes = "SELECT * FROM $table_cat_level3 WHERE levelc_lk = '$levelc_lk'";
$result_querycatcodes = MYSQL_QUERY ($querycatcodes);
$levelb_lk=mysql_result($result_querycatcodes,0,"l evelb_lk");
$levela_lk=mysql_result($result_querycatcodes,0,"l evela_lk");

$insert="INSERT INTO $table_main (clientid,levela_lk,levelb_lk,levelc_lk) VALUES ('$clientid','$levela_lk','$levelb_lk','$levelc_lk ')";
MYSQL_QUERY($insert);

//audit trail -----------------------------------------------------------------------------------------
$type="Create";
$field="Cat Record";
$userid=$_SESSION['user_id'];
$old_data="Not Applicable";
$new_data="$levelc_lk";
$audit="INSERT INTO $table_audit_main (userid, clientid, type, field, old_data, new_data) VALUES ('$userid','$clientid','$type','$field','$old_data ','$new_data')";
MYSQL_QUERY($audit);

//------------------------------------------------------------------------------------------------------

}


Any help appreciated.
__________________
Mike (Bizgen)
SEO for Small Business | Discontinued China | Car Boot Sales in UK
Reply With Quote
  #2 (permalink)  
Old 01-14-2009, 07:25 PM
WebProWorld Veteran
 
Join Date: Apr 2004
Posts: 349
imvain2 RepRank 1
Default Re: Struggling with audit trail

I would suspect part of the problem is your foreach. Foreach is meant to loop through arrays, but you are trying to loop through a list.

try:

$selected_cats = explode(",",$_POST['selected_cat']);

foreach ($selected_cats as $levelc_lk) {
Reply With Quote
  #3 (permalink)  
Old 01-16-2009, 07:13 PM
MrGamm's Avatar
WebProWorld Pro
 
Join Date: Dec 2007
Posts: 268
MrGamm RepRank 3MrGamm RepRank 3
Default Re: Struggling with audit trail

My guess is that your hogging the database and pulling too many queries...

Why not use the for loop to create the query you need.

INSERT INTO (1,2,3) VALUES (1,2,3), (1,2,3), (1,2,3),(1,2,3), (1,2,3), (1,2,3),(1,2,3), (1,2,3), (1,2,3)

I can't remember the syntax exactly... but you also have the option to INSERT DELAYED or with LOW PRIORITY... I am not sure which one will reduce the server load for your instance... but it's worth looking into... jmo...

It would be my preference to record the entire action of the for loop in a single audit entry. Why audit a for loop? Why not audit the function?
__________________
James Weisbrod - programmer
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
On the Trail of the Long Tail WPW_Feedbot Search Engine Optimization Forum 0 02-17-2005 12:00 PM
Enhance pay-per-click audit iowasmiles Search Engine Optimization Forum 1 09-21-2004 08:20 PM
cardsremembered.com - SEO Review/Audit goervin Submit Your Site For Review 2 07-25-2004 05:15 PM
Link Audit software? rcmedia2004 Google Discussion Forum 0 06-17-2004 02:21 AM
Help Trail of Words!!!!!!!!!! shawtyshygurl Graphics & Design Discussion Forum 2 01-14-2004 12:53 AM


All times are GMT -4. The time now is 11:44 AM.



Search Engine Optimization by vBSEO 3.3.0