Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
cc:'d to poster From: "Chris MacKenzie" <[EMAIL PROTECTED]> > > Either one of the unknown queries in edit_exam_question.inc > > is truncating the data or the url parameter is truncated, or > > dbconn.inc is the culprit. > > I've attached the two missing files, so this should help to diagnose > what I've stuffed up. > O.K. Now we know what is likely going on. In dbconn.inc we have ... $conn1=mssql_pconnect($dbservername,$dbusername,$dbpassword); // 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 administrator."; exit; } $result=mssql_select_db($dbname,$conn1); // first use of $result - pconnect will always use this handle if(!$result) { print "Cannot Select SQL Database."; mssql_close($conn1); exit; } In edit_exam_question.inc we have ... include('dbconn.inc'); $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 something // 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 $result=mssql_query($sql,$conn1); // 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 $results print "No Records Found."; mssql_close($conn1); // with msssql_pconnect() this line is irrelevant exit; } $result1=mssql_query($sql1,$conn1); 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."; mssql_close($conn1); // 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 exit; } # 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 $result2=mssql_query($sql1,$conn1); if(!$result) { RED FLAG #2 // // rinse lather repeat print "No Records Found."; mssql_close($conn1); // irrelevant, but if you were using mssql_connect() instead of mssql_pconnect // 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? exit; } $numrows = mssql_num_rows($result); $numrows1 = mssql_num_rows($result1); # $numrows2 = mssql_num_rows($result2); //[snip] $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. Pan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
pan wrote: > >Ah, sorry I didn't make it terribly clear. I meant that I only ever get > >a maximum of 255 chars returned. > > O.K. - then that makes it seem a truncation problem and not a > data definition problem. > > minor thing: in edit_exam_question.php there is > " print 'Select Correct Answer:'; " > > What's the You might want to add the 'readonly' attritbute to > that textarea - lessens chance of unwanted post variables. > You seem to be using that textarea only for displaying the > retrieved question_text These pages are for the "admin" user to be able to edit/delete any question or possible answers, As such I left the text area rw so that they could change it. > Either one of the unknown queries in edit_exam_question.inc > is truncating the data or the url parameter is truncated, or > dbconn.inc is the culprit. dbconn.inc only holds servername, username and password. I've attached it and the other missing file to this message - with differing passwords of course :-) > Three chances at answering the problem, not enough data. > Except for the url parameter passing - but only id and > question_id get passed so no chance on the parameter formatting Yes, I thought I'd keep url passing down to a minimum and only ever pass record id's. > ooops ... files attached only reiterate the problem and do not serve to > further illuminate the path to happiness. I've attached the two missing files, so this should help to diagnose what I've stuffed up. -- Rgds, Chris MacKenzie Windows: "Where do you want to go today ?" Mac OS: "Where do you want to be tomorrow ?" Linux: "Are you coming or what ?" "; mssql_close($conn1); exit; } $result1=mssql_query($sql1,$conn1); if(!$result) { print "No Records Found."; mssql_close($conn1); exit; } # 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 :-( $result2=mssql_query($sql1,$conn1); if(!$result) { print "No Records Found."; mssql_close($conn1); exit; } $numrows = mssql_num_rows($result); $numrows1 = mssql_num_rows($result1); # $numrows2 = mssql_num_rows($result2); # # It doesn't matter if no rows are found as an empty table will be # presented to the web browser, which looks better than some # ugly text based error message anyway. # #if(!$numrows) { # print "Cannot load data into array."; # mssql_close($conn1); # exit; #} ## TODO # I might add some code to alternate the background colour of the table cells # from a light grey and white to make it easier to read the table when a large # amount of data is returned or the page is printed to a hardcopy. $row = mssql_fetch_array($result); ?> "; mssql_close($conn1); exit; } ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP-DB] select and sort question
Why don't you sort in your SELECT statement? SELECT * FROM newsitems where ID='1' ORDER BY newsdate DESC - Original Message - From: Kirk Babb <[EMAIL PROTECTED]> To: <> Sent: Saturday, April 27, 2002 3:56 PM Subject: [PHP-DB] select and sort question I have a db table which holds news in the following manner: ID (auto-increment), newsdate (DATE), newstitle, and newstext I have been displaying them by ID, and would like instead to sort them by date (descending). Since I'm using Flash I have been doing mysql_fetch_array for each ID query and then separating the fields out for placement in the dynamic text fields (has to be done for formatting), like so: $news_details1 = mysql_query("SELECT * FROM newsitems where ID='1'"); $headlines1 = mysql_fetch_array($news_details1); then populate the fields with echo "&newstitle1=" . $headlines1["newstitle"] etc. Can I do this in a better way (more efficient)? and sort by date? I haven't done any sorting before, and if it pulls all the data into an array wouldn't that really be a 2D array? How do I handle that? Thanks for any help or suggestions, Kirk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] select and sort question
There are many ways to sort by date. I use something like this SELECT * FROM newsitems WHERE newsdate=(whatever date you want); For selecting records for the current date I use php's date function to get the current date in the right format. $current_date = date("Ymd"); SELECT * FROM newsitems WHERE newsdate=$current_date; I also use php's mktime function to create past and future days formated for mysql date field. $yesterday = mktime (0,0,0,date("m") ,date("d")-1,date("Y")); $date_yesterday = date("Ymd",$yesterday); SELECT * FROM newsitems WHERE newsdate=$date_yesterday; Some of what you've written leads me to believe you might want to use ORDER BY in your sql. If you want to pull all the newsitems from the db and then order(not sort) them by date date (descending) you need something like this SELECT * FROM newsitems ORDER BY newsdate DESC; Hope this helps, Mike Kirk Babb wrote: > I have a db table which holds news in the following manner: > ID (auto-increment), newsdate (DATE), newstitle, and newstext > > I have been displaying them by ID, and would like instead to sort them by > date (descending). Since I'm using Flash I have been doing > mysql_fetch_array for each ID query and then separating the fields out for > placement in the dynamic text fields (has to be done for formatting), like > so: > > $news_details1 = mysql_query("SELECT * FROM newsitems where ID='1'"); > $headlines1 = mysql_fetch_array($news_details1); > then populate the fields with echo "&newstitle1=" . > $headlines1["newstitle"] etc > > Can I do this in a better way (more efficient)? and sort by date? I > haven't done any sorting before, and if it pulls all the data into an array > wouldn't that really be a 2D array? How do I handle that? > > Thanks for any help or suggestions, > > Kirk > > > > -- Mike -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] select and sort question
I have a db table which holds news in the following manner: ID (auto-increment), newsdate (DATE), newstitle, and newstext I have been displaying them by ID, and would like instead to sort them by date (descending). Since I'm using Flash I have been doing mysql_fetch_array for each ID query and then separating the fields out for placement in the dynamic text fields (has to be done for formatting), like so: $news_details1 = mysql_query("SELECT * FROM newsitems where ID='1'"); $headlines1 = mysql_fetch_array($news_details1); then populate the fields with echo "&newstitle1=" . $headlines1["newstitle"] etc. Can I do this in a better way (more efficient)? and sort by date? I haven't done any sorting before, and if it pulls all the data into an array wouldn't that really be a 2D array? How do I handle that? Thanks for any help or suggestions, Kirk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Newbie and having to convert from idc/htx format
On 4/27/02 1:52 AM, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: I'm not too familiar with idc/htx but I have used PHP, IIS, MS SQL and Linux and had great results. Here are some ideas that might help you: -Try installing PHP on your current server (IIS) now you can convert sections of your web site one at a time. Then you can migrate to a Linux / Apache server with (hopefully) little trouble. -Avoid the PHP's MSSQL_CONNECT, use ODBC instead. Just my experience but I got ODBC to work easily, I never could get MSSQL calls to function properly. Also if some day you decide to use another database vendors ODBC will still work (perhaps with some tweaking). -You can still use stored procs (I use them exactly they way you describe) at minimum you can: $my_sql = "my_procedure '$foo', '$bar'"; $my_result = odbc_exec($conn, $my_sql); -The best documentation is: http://www.php.net/ but I expect you've already fount that. -I don't remember what ODBC driver I'm using but it just worked and I've never needed to mess with it since installing it. Good luck, Frank > From: Robert Webb <[EMAIL PROTECTED]> > Date: Fri, 26 Apr 2002 10:23:11 -0400 > To: [EMAIL PROTECTED] > Subject: Newbie and having to convert from idc/htx format > > Ok, I have been somewhat tasked here to try and do a web conversion from > the idc/htx format of Microsoft to a more portable format. I am looking > and using php for my scripting. My current scripts are very simple. Here > is my setup. > > Microsoft IIS using idc/htx frontend > MSSQL backend database > All sql queries, inserts, etc.. are handled as stored procedures. > IDC files only pass data to the sql server via odbc. > > As you can see we have setup the sql server to handle all the processing > of data. The web server only passes data put into the forms across to > the sql server. > > Here are my questions. > > 1. What odbc would you recommend under Linux to connect to the mssql > server. > > 2. Where would be a good place to go to get a feel on how I would write > the code to pass the variable data over to the sql server. > > 3. Is this even easily obtainable. Or should I just start trying to > re-write the entire site. > > Also I am including below a sample of what our idc file looks like. > > *Of course names have been changed to protect the guilty. ;-) > > Datasource: Contacts > Template: view_entry.htx > SQLStatement: DECLARE @typesearch varchar(50) > +select @typesearch = '%R1%' > +if @typesearch = 'name' > +Begin > +execute sp_corporate_wide_database_search '%name%', '%classification%' > +End > +if @typesearch = 'company' > +begin > +execute sp_main_company_search '%name%', '%classification%' > +end > > > I am on a tight schedule with this. Otherwise I would be only digging > into any manual I could find first. > > > Thanks, > Robert > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
cc:'d to poster >Ah, sorry I didn't make it terribly clear. I meant that I only ever get >a maximum of 255 chars returned. O.K. - then that makes it seem a truncation problem and not a data definition problem. minor thing: in edit_exam_question.php there is " print 'Select Correct Answer:'; " What's the Well, yes. The table in question is specified as such: > > CREATE TABLE [dbo].[tbl_exam_questions] ( > [question_id] [int] IDENTITY (1, 1) NOT NULL , > [question_text] [char] (400) NOT NULL , > [correct_answer] [int] NOT NULL > ) ON [PRIMARY] > data defintion seems to pass muster > I'm only using a very simple query (select * from tbl_exam_questions > where question_id=x;) and using the microsoft client tools such as query > analyser and ms sql enterprise manager, both return the full string. > O.K. the data is in the db and some tools can show you what you expect to see. That is good and bad news; good that the data is there in proper form eager to be retrieved; bad in that your code may be performing horrible vivisection experiments on the poor unsuspecting data. So - let's look at the .inc files that do the actual queries ... > I've attached the two related php files that deal with the process, I > can't see anything too horrible (other than my coding style) :-) ooops ... files attached only reiterate the problem and do not serve to further illuminate the path to happiness. more data::better answers Pan (side not to bob parker: huh? you have your attributes mixed up) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql results to a session variable?
I am just wondering if there is a way to pull the results from an mysql query into an session variable that can be passed from page to page. If there is a way to do this could someone please point out a good tutorial on this "specific" function or maybe an example of how to accomplish this. Any help would be great. thanks in advance, Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] conroling url variable when reading csv file
On Saturday 27 April 2002 22:51, chidambaram wrote: > Hi All > > i am reading a file named index.csv through a php script > i want make a php script such that > > for example http://www.chida.com/in.php?topic=flu&col=1,2 > > the php script should read the index.csv and variables fromthe url > and display according to it.In the above example it should read csv > file and display only the columns 1,2(under topic) of the csv file. > could anyone help me with the php code and please suggest me site > which has the same type of code snippets. > thanks in advance > > this is the code i have written but it doesnot work propery as i > expect *How* didn't it work properly? -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* You have an unusual understanding of the problems of human relationships. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] conroling url variable when reading csv file
Hi All i am reading a file named index.csv through a php script i want make a php script such that for example http://www.chida.com/in.php?topic=flu&col=1,2 the php script should read the index.csv and variables fromthe url and display according to it.In the above example it should read csv file and display only the columns 1,2(under topic) of the csv file. could anyone help me with the php code and please suggest me site which has the same type of code snippets. thanks in advance this is the code i have written but it doesnot work propery as i expect "; $row++; for ( $c=0; $c<$num; $c++ ) ; if($HTTP_GET_VARS['topic'] = "fluent") { print $data[$c] ; } else{ } } fclose($fp); ?> Thanks E.chidambaram For live cricket scores download Yahoo! Score Tracker at: http://in.sports.yahoo.com/cricket/tracker.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
pan wrote: > i.e., do you know the db.table.field in question is a column type meant > to hold the data you expect? You seem to be indicating a consistent > return of 255 when you ask for 400 - seems to be a clue about the > field specification. Ah, sorry I didn't make it terribly clear. I meant that I only ever get a maximum of 255 chars returned. -- Rgds, Chris MacKenzie Windows: "Where do you want to go today ?" Mac OS: "Where do you want to be tomorrow ?" Linux: "Are you coming or what ?" -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
pan wrote: > > From: "Chris MacKenzie" <[EMAIL PROTECTED]> > > I've come across an interesting problem. I'm trying to retrieve some > > text data (in this case a question up to 400 chars), but each time I > > perform a select statement I only receive the first 255 chars. > > > > What's the go here, is this just another microsoft thing ? > > > > Based on the paucity of data in your problem description I would > be inclined to trust the machine and ask what makes you think there > should be more than 'char(255)' worth of characters to retrieve? > > i.e., do you know the db.table.field in question is a column type meant > to hold the data you expect? You seem to be indicating a consistent > return of 255 when you ask for 400 - seems to be a clue about the > field specification. Well, yes. The table in question is specified as such: CREATE TABLE [dbo].[tbl_exam_questions] ( [question_id] [int] IDENTITY (1, 1) NOT NULL , [question_text] [char] (400) NOT NULL , [correct_answer] [int] NOT NULL ) ON [PRIMARY] I've also used a strlen to measure the string length on submission to the db via a form post, and I've done the same on the returned string (also via a form post). On submission the test text I entered was 271 chars, after retreiving the text I only get 255 chars each time. I'm only using a very simple query (select * from tbl_exam_questions where question_id=x;) and using the microsoft client tools such as query analyser and ms sql enterprise manager, both return the full string. I've attached the two related php files that deal with the process, I can't see anything too horrible (other than my coding style) :-) -- Rgds, Chris MacKenzie Windows: "Where do you want to go today ?" Mac OS: "Where do you want to be tomorrow ?" Linux: "Are you coming or what ?" edit_exam_question.php Description: application/unknown-content-type-php_auto_file update_exam_question.php Description: application/unknown-content-type-php_auto_file -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
Pan, It looks as if you may be using FORM with method=get. If so try method=post to get the full data Bob Parker On Saturday 27 April 2002 20:35, you wrote: > From: "Chris MacKenzie" <[EMAIL PROTECTED]> > > > I've come across an interesting problem. I'm trying to retrieve some > > text data (in this case a question up to 400 chars), but each time I > > perform a select statement I only receive the first 255 chars. > > > > What's the go here, is this just another microsoft thing ? > > Based on the paucity of data in your problem description I would > be inclined to trust the machine and ask what makes you think there > should be more than 'char(255)' worth of characters to retrieve? > > i.e., do you know the db.table.field in question is a column type meant > to hold the data you expect? You seem to be indicating a consistent > return of 255 when you ask for 400 - seems to be a clue about the > field specification. > > More data::better answers. > > Pan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Not Inserting Data
Thank you all for your suggestions on why my code is not working. WILL TRY EVERYTHING AND LET YOU GUYS KNOW. Keep up the great work Neil
Re: [PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
From: "Chris MacKenzie" <[EMAIL PROTECTED]> > I've come across an interesting problem. I'm trying to retrieve some > text data (in this case a question up to 400 chars), but each time I > perform a select statement I only receive the first 255 chars. > > What's the go here, is this just another microsoft thing ? > Based on the paucity of data in your problem description I would be inclined to trust the machine and ask what makes you think there should be more than 'char(255)' worth of characters to retrieve? i.e., do you know the db.table.field in question is a column type meant to hold the data you expect? You seem to be indicating a consistent return of 255 when you ask for 400 - seems to be a clue about the field specification. More data::better answers. Pan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Maximum field length with PHP 4.1.2/MSSQL v7 ?
Hi All, I've come across an interesting problem. I'm trying to retrieve some text data (in this case a question up to 400 chars), but each time I perform a select statement I only receive the first 255 chars. What's the go here, is this just another microsoft thing ? -- Rgds, Chris MacKenzie Windows: "Where do you want to go today ?" Mac OS: "Where do you want to be tomorrow ?" Linux: "Are you coming or what ?" -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Install SAPDB with Apache and PHP
I got SAPDB (7.3) to compile with the apache (1.3.24) and php (4.1.2) under AIX (4.3.3) without failures and it seems to run. It is quite easy after all, but I had to do a lot of research to get the knowledge: ---START--- cd apache /configure cd ../php /configure --with-apache=../apache --with-sapdb=/usr/sapdb/depend make make install cd ../apache LIBS=/lib/libposix4.so export LIBS /configure --activate-module=src/modules/php4/libphp4.a make ---STOP--- For me it worked without configuring the LIBS path. Done so, I got a compile error. But the guide up there was for Solaris. The basic thing to know is the path to use for the --with-sapdb statement. Benjamin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php