cc:'d to poster

From: "Chris MacKenzie" <[EMAIL PROTECTED]>
> > Either one of the unknown queries in
> > is truncating the data or the url parameter is truncated, or
> > is the culprit.

> I've attached the two missing files, so this should help to diagnose
> what I've stuffed up.


Now we know what is likely going on.

In we have ...
//  pconnect is not doing what you think it might be
// a persistent connection reuses open libnks and any
// mssql_close() calls are ignored ... it is *persistent*
// not even script end will close the bugger
// suggest change to normal mssql_connect()
// especially because pconnect reuses open links - it will not
// create a new handle, thus making your multiple use of result
// below a bit of a problem
// N.B. -  mssql_connect() called with identical arguments
// will not open a new connection - consequences below

if(!$conn1) {
 print "Cannot Connect to SQL Server. Please contact your system
// first use of $result - pconnect will always use this handle

if(!$result) {
 print "Cannot Select SQL Database.<BR>";

In we have ...

$sql="SELECT * FROM tbl_exam_questions WHERE question_id=$question_id;";
$sql1="select * from tbl_exam_answers WHERE question_id=$question_id order
by id;";
// why separate this data?
// wouldn't a single query be faster and perhaps pre-collate the data you
// need in a faster and cleaner fashion?
// from other code it seems you need a single row returned structured
// like [exam_question]:[answer_1]:[answer_2]: ... [correct_answer], or
// whatever corresponds to your table data defintion schema
// if everything is a simple as it seems then a straightforward left join
// is proably your ticket home

// second use of $result
// there may not necessarily be a problem here but it costs nothing
// to use $result_sql1 or some such

if(!$result) {
// things might clear up a bit if this $result is differntiated from other
 print "No Records Found.<BR><BR>";
// with msssql_pconnect() this line is irrelevant

if(!$result) {
//////// RED FLAG /////////
// ! $result != $result1
// why $result1 when next step is an if on $result ?
// this is where clearly delineated $result vars will help
// if you had $result_sql1 it might have been easier to
// write if(!$result_sql1) instead of msiwriting as above

 print "No Records Found.<BR><BR>";
// again irrelevant with mssql_pconnect()
// a single mssql_close() at end of script is suffcient
// for each connection
// collecting them together at the end is a nice way
// of making sure the barn door is closed after you've
// let out some of the herd, although end-of-script
// will close non-persistent connections

# Can't seem to find a good way to copy the returned array
# so I'll use a kludge and just re-submit the query.
# There must be a better way, but I'm pressed for time :-(
// see above about left join in a single query
// write a better single query and clear up the result vars
// include everything you need in one query
// faster and makes subsequent code simpler

if(!$result) {
//////// RED FLAG #2 //////
// rinse lather repeat
 print "No Records Found.<BR><BR>";
// irrelevant, but if you were using mssql_connect() instead of
// you might not be wanting every query reopening conn1 to the db
// withiout explicti connection call queries try to open a connection
// on their own - why not just open one connection for one query
// and close it at the end?

$numrows = mssql_num_rows($result);
$numrows1 = mssql_num_rows($result1);
# $numrows2 = mssql_num_rows($result2);


$row = mssql_fetch_array($result);
// there are some things that might be said about query result sets being
// retained in memory, but I don't think there's any need to go there
// try changing to mssql_connect()
// write a single left join query,
// clean up the ambiguities in re handle vars
// use a single mssql_close() at end of script

Not sure what else I can offer at this point.
Hope some of this helps you move on your way.


PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to