PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Donovan
Client


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

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

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 Back to top

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.
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum