[PHP-DB] Getting array values into a query
I've been attempting to take the values from an array pulled from a session to supply the variable in a WHERE clause. list() provides only the first value as expected. implode() the last. Any suggestions or should I just load the values I want in the session through a query on the previous script and call it directly to the function I want to use? Michael Conway [EMAIL PROTECTED] (703) 968-8875
[PHP-DB] Sessions and Temporary Tables
I'm trying to create a temporary table through a query call in php and have no guiding documentation to refer to. I assume it can be created as any other query call. I would use CREATE INSERT but the insert data is coming from a while loop. I understand that the temporary table requires registration as a session to ensure it is dropped after the session is closed. Does this mean I would need to simply register the name of the table. All aspects of the code are apparently working fine. No errors. When I use a SELECT statement and attempt to display the contents of the table, I only get the html headers for the table but no data. When I attempt to DESCRIBE the table directly from the mysql command line - it does not exist. Michael Conway [EMAIL PROTECTED] (703) 968-8875
[PHP-DB] Array problems
I find myself stuck in coming up with a way to cycle through this array of db results for porting to a graphing script that I did not write. My latest attempt to get around this problem is below. Outside of the $graph-SetDataValues(array( ));, echoing $array[$i] produces the desired results for three sets of two bar graphs with the corresponding title. However, inside the $graph function, I get only the last expected set of bar graphs and title. I originally iterated through each anticipated result from mysql_fetch_array($result) and plugged each of these values into an array calling the columns individually. I got the desired graph, but, of course this is bad programming and not useful for queries producing a greater number of rows (I simply needed to know it worked). Any help would be appreciated. __ $query = 1st SELECT code; // Run the query created above on the database through the connection if (!($result1 = @ mysql_query ($query, $connection))) showerror(); $query = 2nd SELECT code; // Run the query created above on the database through the connection if (!($result2 = @ mysql_query ($query, $connection))) showerror(); while ($row_1st= @ mysql_fetch_array($result1)) ($row_2nd = @ mysql_fetch_array($result2))) { $field1[$i]=$row_1st[column1]; $field2[$i]=$row_1st[column2]; $field3[$i]=$row_2nd[column1]; $array[$i]=array($field1[$i], $field2[$i], $field3[$i]); $graph-SetDataValues(array( $array[$i] )); } $graph-DrawGraph(); ? Michael Conway [EMAIL PROTECTED] (703) 968-8875
RE: [PHP-DB] Re: Passing variables through a page
Sessions are better. If you want to use the header to pass the variable: header(Location:5-14_select_area.php?department=$department); (use an ampersand for adding additional variables as mentioned by Mark. You should call a clean function from an include file (add the document root directory in the php.ini file so you can place the file in a different directory and PHP always knows where to find it when you include it without having to reference the entire document root - very handy) to prevent someone from altering your intended input (this is why sessions are better). ?php //include.inc function clean($input, $maxlength) { $input = substr($input, 0, $maxlength); $input = EscapeShellCmd($input); return ($input); } ? Then for the 5-14_select_area.php file: ?php //5-14_select_area.php include_once 'include.inc'; if(!empty($department)) { $department = clean($department, 15); } if(!empty($level)) { $level = clean($level, 15); } your queries follow .. ? Hope that is what you were looking for. Michael Conway [EMAIL PROTECTED] (703) 968-8875 -Original Message- From: Mark [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 07, 2003 10:29 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Re: Passing variables through a page If you use sessions, you can pass the variables without having to wory about interim pages. Another option (I don't know if it will actually work) is to put the variables in the the URL of the location redirect. Something like: $loc=http://www.yourdomain.com/nextpage?var1=$var1var2=$var2;; header(location: $loc); --- Michael Mauch [EMAIL PROTECTED] wrote: Alex Francis [EMAIL PROTECTED] wrote: I have a page (dept_select) with two drop down lists populated from a table in a MySQL Database. If one item is selected in either of the lists I need to go to one page (5-14_select_area.php). If any other item is selected I need to go to another page (add_new_resources.php) but I need to pass the selected items to add_new_resources.php. I don't think there are many other possiblities, at least if you don't want to use JavaScript (and I hope you don't). Instead of the redirect, you could perhaps use require() to include one of the two possible pages, and thus avoid one server-client roundtrip. At the moment I have created a page between dept_select.php and the other pages and added the following code to it: ?php if ($department==5-14 Curriculum) { header(Location:5-14_select_area.php); } elseif ($level==5-14 Curriculum) { header(Location:5-14_select_area.php); } else { header(Location:add_new_resources.php); } ? The Location header requires an absolute URI, e.g. http://your_host/path/your_file.php. I'm not sure whether this is a database question ;-) Regards... Michael -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. -Stolen from the now-defunct Randy's Random mailing list. *** __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Questions regarding primary keys, updates, and autoincrement
I have been working on an e-business project and have a product table and manufacturer table that are linked via barcode and a manufacturer ID (both primary keys in the tables mentioned). For now, I have been setting the manufacturer's ID manually, primarily for that rare instance where a manufacturer and its products are dropped from the database, but the number should be reused. Is it better or possible (without complications) to use autoincrement and simply delete the product information and manufacturer information while leaving the ID column intact for a later update operation with a new manufacturer and its products? I suppose only one table (the linking table?) should be set to autoincrement and that ID number used to populate the remaining tables depending upon that number for insert operations. The code is probably simple, but my head is already swimming. I suppose what I am looking for is best practice advice from seasoned db administrators. A second question, which may be moot if autoincrement is the best way to go, is why I keep getting an duplicate key error despite using IGNORE in my mysql update scripts. Keep in mind that the update is completed anyway (even without using IGNORE) but the abort prevents an acknowledgement script which is essential in unregistering sessions crucial in future update operations. Thanks. Michael Conway [EMAIL PROTECTED] (703) 968-8875
[PHP-DB] Restarting Mysql
I'm debugging a script that locks tables as part of an INSERT script (using Linux 7.1). Mysql frequently locks out the tables involved when there is an error (never gets to UNLOCK command. I have been rebooting until now. Using % mysqladmin shutdown works. safe_mysqld doesn't. Any suggestions on getting around the reboot? Thanks. Michael Conway [EMAIL PROTECTED] (703) 968-8875
[PHP-DB] Preserving the string
I have a problem using barcodes. They are variable in length (up to 13 integers). I had to add them to the tables a strings (varchar(13)) to preserve the leading zeros that are not uncommon. The problem comes with inserting these barcodes into other tables (passing them using href). When using a shopping cart application and inserting the barcode from the product table into the items table (to store the user's shopping cart contents), the leading zeros are lost. Needless to say that using the original tables with the true barcodes to verify the contents of the user's cart for purchases and pricing subsequently fails. Is there a way to ensure the string is preserved in its entirety when added to a new table using scripts? Michael Conway [EMAIL PROTECTED] (703) 968-8875
[PHP-DB] Opening files
I am trying to use text and images from separate files to populate descriptions and images for specific queries. I have used something like echo img src=$row[image]; with little success (parse error expecting , or ; - on the line in question). I assume that I would have to use fopen for the text but have not found a suitable example. Any help would be greatly appreciated. Thanks. Michael Conway [EMAIL PROTECTED] (703) 968-8875