Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Thu Jul 24, 2008 12:28 pm Reply with quote

I have code inserting questions into a table from a txt file.

I wanted to capture how many records were written.

sql_numrows was not working. sql_afffectedrows seems to be but I am only getting a count of 1 when the test.txt file has 10 questions.

Could this be as simple as ...

Quote:

A total of $i question was successfully written to the database!




Code:
for ($i=1; $i < count($quiz_ques); $i++)

{
      
      $sql = "INSERT INTO questions (cat_id, course_id, ques_name, stem, choice1, choice2, choice3, choice4, choice5, points, feedback, createdby, lastedited_by, lastedited_date, source, qtype) VALUES (".$ca.", ".$cid.", '".$quiz_ques[$i][0]."', '".mysql_real_escape_string($quiz_ques[$i][1])."', '".mysql_real_escape_string($quiz_ques[ $i][4][0][0])."', '".mysql_real_escape_string($quiz_ques[ $i][4][0][1])."', '".mysql_real_escape_string($quiz_ques[ $i][4][0][2])."', '".mysql_real_escape_string($quiz_ques[ $i][4][0][3])."', '".mysql_real_escape_string($quiz_ques[ $i][4][0][4])."', '".mysql_real_escape_string($quiz_ques[$i][3])."', '".mysql_real_escape_string($quiz_ques[$i][2])."', 2, 2, ".time().", 'respondus', '1') ";
      $result = $db->sql_query($sql);         
   }

$count_import = $db->sql_affectedrows($result);
      if (!$result) {
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();   
      }else{   
         echo "A total of $count_import question was successfully written to the database! <br>";
      }
 
View user's profile Send private message Visit poster's website ICQ Number
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Thu Jul 24, 2008 12:41 pm Reply with quote

You are looping. Therefore you are always going to get 1 (if it was successful). You need to count inside the loop and display the result outside the loop.

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©