[PHP-DB] Re: Ranges query gone wild
Boaz Amit [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a MySQL table where a product price ranges are set according to quantities. For instance for a certain product you'd have (besides id columns): range_begin | range_end | range_price 0 | 35 | 1.5 36 | 70 | 2 71 | - | 3 Where '-' is always the character that means '..and above' and closes the entire range field. So in the above example a quantity of 71 and above has a price tag - $3. First danger signal: duplication of data (or, storage of data that should be a result of calculation). For a given product, range_end = (range+1)_begin - 1 Second danger signal: needing a 'bad data' type. In some cases, may be necessary to have a separate valid-data field, but better to simply not allow bad data if at all possible. Instead, remove the redundant field: range_begin | range_price 0 |1.5 36 |2 71 |3 and the query becomes SELECT range_price FROM price_ranges WHERE product_id = '$product_id' size_id = '$size_id' range_begin = '$quantity' ORDER BY range_begin DESC LIMIT 1 -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Ranges query gone wild
(repost: first try bounced) Boaz Amit [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a MySQL table where a product price ranges are set according to quantities. For instance for a certain product you'd have (besides id columns): range_begin | range_end | range_price 0 | 35 | 1.5 36 | 70 | 2 71 | - | 3 Where '-' is always the character that means '..and above' and closes the entire range field. So in the above example a quantity of 71 and above has a price tag - $3. First danger signal: duplication of data (or, storage of data that should be a result of calculation). For a given product, range_end = (range+1)_begin - 1 Second danger signal: needing a 'bad data' type. In some cases, may be necessary to have a separate valid-data field, but better to simply not allow bad data if at all possible. Instead, remove the redundant field: range_begin | range_price 0 |1.5 36 |2 71 |3 and the query becomes SELECT range_price FROM price_ranges WHERE product_id = '$product_id' size_id = '$size_id' range_begin = '$quantity' ORDER BY range_begin DESC LIMIT 1 -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Efficiency question
Micah Stevens [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] $data = mysql_fetch_assoc(mysql_query(select * from some_table limit 1)); would be faster than: $pointer = mysql_query(select * from some_table limit 1); $data = mysql_fetch_assoc($pointer); but I'm not sure, php may optimize this. Anyone know the answer? It will be faster by one store and one fetch... the database query probably takes 1000 times as long. I don't think the difference is worth the time you'd take to change it. -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Now, how about Roman Numerals?
George Pitcher [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] That's great, but what about the reverse: Roman to Arabic? George in Oxford // NOTE: the order of the table is // important! I will use greedy parsing, // so (for example) IX and IV must precede // I to parse correctly. $RomanTable = array( M = 1000, CM = 900, D = 500, CD = 400, C = 100, XC = 90, L = 50, XL = 40, X = 10, IX = 9, V = 5, IV = 4, I = 1 ); function MatchClause($needle, $haystack) { // These two tests are probably just paranoia, // but - hey, I'm paranoid. ;-) if (strlen($haystack) 1) return false; if (strlen($haystack) strlen($needle)) return false; return( strncasecmp($needle, $haystack, strlen($needle)) == 0 ); } function RemoveClause($needle, $haystack) { return( substr($haystack, strlen($needle)) ); } function RomanToInt($str) { global $RomanTable; $sum = 0; do { $done = true; foreach($RomanTable as $clause = $value) if ( MatchClause($clause, $str) ) { $sum += $value; $str = RemoveClause($clause, $str); $done = false; break; } } while ($done == false); return($sum); } NOTE! This algorithm is sufficient but not complete - it will correctly translate all legal Roman-numeral strings, but cannot detect illegal strings. -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Now, how about Roman Numerals?
Richard Hutchins [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Here's a rundown of what the script is doing based on your input: If you pass in the number 155, here are the calculations: $m = $num / 1000; //$m will be equal to .155 $c = ($num % 1000) / 100; //$c will be equal to 1.55 $x = ($num % 100) / 10; //$x will be equal to 5.5 $i = $num % 10; //$i will be equal to 5 [snip] Yes, that's exactly the problem... I assumed integer-only input and casting. Here is a fixed (tested) version: ?php function RomanDigit($dig, $one, $five, $ten) { switch($dig) { case 0:return ; case 1:return $one; case 2:return $one$one; case 3:return $one$one$one; case 4:return $one$five; case 5:return $five; case 6:return $five$one; case 7:return $five$one$one; case 8:return $five$one$one$one; case 9:return $one$ten; } } function IntToRoman($num) { $num = (int) $num; if (($num 1) || ($num 3999)) return(No corresponding Roman number!); $m = (int) ($num * 0.001); $num -= $m*1000; $c = (int) ($num * 0.01); $num -= $c*100; $x = (int) ($num * 0.1);$num -= $x*10; $i = (int) ($num); // echo m = $m, c = $c, x = $x, i = $i ; return( RomanDigit($m, 'M', '', '') . RomanDigit($c, 'C', 'D', 'M') . RomanDigit($x, 'X', 'L', 'C') . RomanDigit($i, 'I', 'V', 'X') ); } ? and my test script: ?php include(to_roman.php); $test = array( 8, 19, 155, 980, 9.8, -3, 3999, 4000, abc, , array() ); foreach($test as $num) echo $num =gt; .IntToRoman($num).br/; ? -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Now, how about Roman Numerals?
David Shugarts [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Second poser today: How to use either a MySQL select statement or PHP to produce a roman numeral, starting from an arabic (INT) number in a database? In PHP: function RomanDigit($dig, $one, $five, $ten) { switch($dig) { case 0:return ; case 1:return $one; case 2:return $one$one; case 3:return $one$one$one; case 4:return $one$five; case 5:return $five; case 6:return $five$one; case 7:return $five$one$one; case 8:return $five$one$one$one; case 9:return $one$ten; } } function IntToRoman($num) { if (($num 1) || ($num 3999)) return(No corresponding Roman number!); $m = $num / 1000; $c = ($num % 1000) / 100; $x = ($num % 100) / 10; $i = $num % 10; return( RomanDigit($m, 'M', '', '') .RomanDigit($c, 'C', 'D', 'M') .RomanDigit($x, 'X', 'L', 'C') .RomanDigit($i, 'I', 'V', 'X') ); } -- Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada v3.1 GCS/E/AT d- s+: a- C+++ L+$ P+ E- W+++$ N++ K? w++ M PS+ PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Help needed
Spiderwebb [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I dont know if this is possible in PHP (Newbie) im working on a project where each product has 3 diffierent prices depending on the amount sold so say for example 1- 100 price A 101-299 price B and above 300 Price C. What I need to be able to do is increment an mysql database field each time an item is sold then look at that field to decide which price variable to write to the price field of the database. Could someone point me in the right direction where I could solve this or to someone who could First, how are you storing the price points? I would consider a separate pricing table linked to the item table like so: table ItemForSale id integer auto_increment name varchar(30) descr varchar(200) table PricePoint id integer auto_increment item integer ordersize integer priceper float then for a given item and number of items ordered, you can retrieve the applicable price-per by SELECT priceper FROM PricePoint WHERE item=$itemID AND ordersize=$number ORDER BY ordersize DESC LIMIT 1 Each item can have an arbitrary number of price points at any number-of-items. Note that this assumes the priceper always decreases with increasing ordersize for a given item. Second, I don't understand why you reset the cumulative price-point every time you process an order; for selling, surely the price- point only applies to a single order rather than cumulatively, and for purchasing or reporting, I would expect to calculate it dynamically at the time the report is generated. Have I missed something? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: please help.. serial number generator
Rainydays Sunshine [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I need to create some kind of 10 digits serial number where I can generate and check that it is valid. Sort of like a checksum.. How many unique values do you need, and how hard-to-fake? I would consider something like 7+3 digits - the first seven digits are generated more or less randomly, and the last three are checksums... this gives you 10 million valid combinations, and a one-in-a-thousand chance of any random number being valid. Obviously, the quickest way to increase security is to increase the number of digits. Each checksum can be any formula you can imagine, for example // Expects: // d (digits) - array [0..6] of integer in [0..9] function checksum1($d) { // scrambler array $s = array( 24, 78, 63, 501, 88, 89, 53, 14, 34, 266 ); return( ( ( $s[$d[0]] * $s[$d[6]] * 5) % 29 + ( $s[$d[1]] * $s[$d[5]] * 7) % 31 + ( $s[$d[2]] * $s[$d[1]] * 11) % 37 + ( $s[$d[3]] * $s[$d[2]] * 13) % 41 + ( $s[$d[4]] * $s[$d[0]] * 17) % 43 + ( $s[$d[5]] * $s[$d[4]] * 19) % 47 + ( $s[$d[6]] * $s[$d[3]] * 23) % 53 ) % 10 ); } Hope this helps... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Query from Hell (for me anyway)
Chris Mackenzie [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I've been trying to solve this for hours now with no end in sight, I'm hoping that someone here might be able to help me. I've got four tables set out as shown below: tbl_student_details id student_idname study_mode --- 1 12 Joe Smith 1 2 123 Jane Smith 1 tbl_study_mode id txt_study_mode 1 Full Time 2 Part Time 3 Online tbl_student_history_answers idquestion_id p_answer 119 Network Management 219 Web Site Production 319 Web Site Management 420 Network Management 520 Web Site Production 620 Web Site Management tbl_student_history_info id student_idquestion_idanswer_id --- 11219 1 21220 6 3123 19 5 4123 20 6 Basically I need to pull out student_id, name and course selected for all students who elected full time study - and their response to question 19 and 20 First, this has a normalization problem - question-id is redundant in either tbl_student_history_info or tbl_student_history_answers. I will assume it removed from tbl_student_history_answers. There are two ways of factoring this, depending on exactly how you plan to use it. If you will always only want questions 19 and 20, you can hard-code those into a per-student query, like so: SELECT tbl_student_details.student_id, tbl_student_details.name, tbl_q19.p_answer AS a19, tbl_q20.p_answer AS a20 FROM ( tbl_student_details JOIN tbl_study_mode ON tbl_student_details.study_mode=tbl_study_mode.id) JOIN tbl_student_history_info AS q19_info ON tbl_student_details.id=tbl_student_history_info.student_id) JOIN tbl_student_history_answers AS tbl_q19 ON q19_info.answer_id=tbl_q19.id) JOIN tbl_student_history_info AS q20_info ON tbl_student_details.id=tbl_student_history_info.student_id) JOIN tbl_student_history_answers AS tbl_q20 ON q20_info.answer_id=tbl_q20.id) WHERE tbl_study_mode.txt_study_mode='Full Time' AND q19_info.question_id=19 AND q20_info.question_id=20 This is actually a poor way of doing things, but it makes your final PHP code much simpler. If you will ever want to use this query to look at answers to a different number of questions - say, questions 19, 20 and 21 - you would be better to do a per-student/per-question query, like so: SELECT tbl_student_details.student_id, tbl_student_details.name, tbl_student_history_info.question_id, tbl_student_history_answers.p_answer FROM ((( tbl_student_details JOIN tbl_study_mode ON tbl_student_details.study_mode=tbl_study_mode.id) JOIN tbl_student_history_info ON tbl_student_details.id=tbl_student_history_info.student_id) JOIN tbl_student_history_answers ON tbl_student_history_info.question_id=tbl_student_history_answers.id) WHERE tbl_study_mode.txt_study_mode='Full Time' AND tbl_student_history_info.question_id IN ( 19, 20 ) ORDER BY tbl_student_details.student_id ASC, tbl_student_history_info.question_id ASC This will return several records per student, one for each question you want to know about; the ORDER BY is useful to make all records for a single student consecutive so your PHP code can process it easily. Hope this helps. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Nested SQL query problem...
Srinivasan Ramakrishnan [EMAIL PROTECTED] wrote in message 004701c206df$5a00f100$[EMAIL PROTECTED]">news:004701c206df$5a00f100$[EMAIL PROTECTED]... The slabs do not continue for an infinite number, hence I may only have slab pricing for 1-10, 11-100, and 101-200 with the assumption that if there are no higher slabs and I wanted say the rate for 500 licenses, I would use the highest slab unit available, in this case the 101-200 slab. ... looking at this, the 'high-limit' value seems redundant (it's always next_highest_minimum - 1); I would suggest getting rid of it, ie Table slabPricing: slabID INT AUTO_INCREMENT productID INT slabStart INT slabRate FLOAT(10,2) For example, what is the cost of 500 licenses of Product_ID 143 ? SELECT slabRate FROM slabPricing WHERE productID=143 AND slabStart=500 ORDER BY slabStart DESC LIMIT 1 ... this will retrieve the per-piece rate for the largest applicable slab. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Can you SUM(IF) from two different tables at the same time?
Richard Davey [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... In the 5th line I changed thread.id to thread.threadid so the name was correct but the same error occurs. Ok, I was guessing at your field names... to give a perfectly satisfactory result but have no idea if this is perversing SQL again or not! (grin) When retrieving information from a database, you should expect to get a variable number of records where each record has the same structure. Instead, you were hard-coding a query to get a single record with information about a number of different groups. If you wanted to change the number of groups returned, you would have to change the structure of the query. By getting a record for each group, the structure of the query does not change if you decide to look at a different number of groups - just the data you give to the WHERE clause. (it at least makes more sense now I guess). As soon as I add the where IN clause it errors. umm... try putting the WHERE clause before the GROUP BY? Can anyone recommend ANY good books on SQL query design? I don't want (or care) about database administration, I just want to know what constitutes a good database design and lots and lots of query examples/tutorials. try a Google search for 'database normalization tutorial'; that should get you started. also check out the documentation at www.mysql.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Complicated query on very simple database - pointers sought
George Pitcher [EMAIL PROTECTED] wrote in message 03b701c20190$8f53fe00$630db092@HLATITUDE">news:03b701c20190$8f53fe00$630db092@HLATITUDE... My database (2 fields: Customer, Order date) contains over 15000 records dating back to 1999. I want to be able to show, in a web page, the following information Month Customers placing orders Orders placed Average Orders/Cust Average over prev 12 months. ... if you know 'orders placed' and 'number of customers', 'average orders per customer' is easily calculated; and 'average over prev 12 months' doesn't fit well into this query, would be better done in PHP. How about SELECT MONTH(orderdate) AS month, YEAR(orderdate) AS year, COUNT(DISTINCT customer) AS customers COUNT(customer) AS orders FROM mytable GROUP BY year,month ORDER BY year,month ASC then in PHP, // month-to-name $months = array(, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec); // for running 12-month average $sum = 0; $sum_num = 0; $item = array(); $index = 0; // for printing start-of-year-only years $prevyear = 0; echo \ntabletheadtr .thYear/th .thMonth/th .thCustomers placing orders/th .thOrders placed/th .thAverage orders per customer/th .th12-month average/th ./tr\n/theadtbody; while($row = mysql_fetch_array($res)) { // check whether to print year value if ($row['year'] == $prevyear) $yr = ; else $yr = $prevyear = $row['year']; // get month-name $mon = $months[$row['month']]; // calculate this-month average orders per customer $avg = $row['orders'] / $row['customers']; // update 12-month average $items[$index] = $avg; $sum += $avg; $sum_num++; if ($sum_num 12) { $sum -= $items[$index-12]; unset($items[$index-12]); $sum_num--; } ++$index; $twelvemonth_avg = $sum / $sum_num; // print table row echo \n\ttr .td$yr/td .td$mon/td .td{$row['customers']}/td .td{$row['orders']}/td .td$avg/td .td$twelvemonth_avg/td .\tr; } echo \n/tbody/table; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: last 10
Crosswalkcentral [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... How can i obtain the last 10 entries that are in mydatabase that have a certain colum set to 1? SQL does not guarantee to return your records in any specific order unless you use an ORDER BY clause. I would suggest reversing the ORDER BY and using LIMIT to take the *first* ten records, ie SELECT * FROM mytable WHERE mycolumn=1 ORDER BY mydate DESC LIMIT 10 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: DROP tables with prefix match
John Hughes [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I need to rebuild a PHP-mySQL site that has an extensive table structure. Is there a way to DROP all tables that start with a certain prefix? First, use SHOW TABLES FROM db LIKE prefix% to get the table names, then iterate through with DROP TABLE tablename The result will look something like ?php $con = mysql_pconnect(localhost, user, pwd) or die(Error connecting: .mysql_error()); $res = mysql_select_db(dbname, $con) or die(Error selecting database: .mysql_error()); $query = SHOW TABLES FROM $dbname LIKE '$prefix%'; $res = mysql_query($query, $con); while ($row = mysql_fetch_array($res)) { $query = DROP TABLE {$res[0]} $ex = mysql_query($query) or echo(Error dropping table {$res[0]}:.mysql_error()); } ? If you are going to use this repeatedly, I would make this a two-stage endeavor: the first step queries the database and returns a check-box form with all the returned table-names; when submitted, the checked tables are dropped. Hope this helps -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Spaces Problem php mysql
Paul [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a form on one server which takes a name in one field, intentionally including spaces as a full name. That value shows up as a form variable as I intended when I display it on the same server. It is sent to another server and written to a mysql database there. At that time, only the first word in the field is written. When the value is returned by the same php script that received and wrote the database, the only thing left in the field is the first word. Length of the word seems to have nothing to do with this. I've been pounding my head (and the keyboard with searches) over this. Do I have to take the first entry apart with string functions to get my desired end, which is the entire name in one field in the database? ... make sure the value is enclosed in quotes when you try to insert it into the database, ie INSERT INTO table ( name ) VALUES ( '$name' ) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Help : search for a word and its number
If I have records like this ID Content 1 John have a red book, and a yellow book. He give a yellow book to Tina. 2 Luke doesn't have any book at all, he always borrow it from John. 3 John like swimming. Can I search this records (table) for a word book and also number of book occurences at every record? From table above, the result would be ID Number 13 21 I use Oracle 8.1.7. I'm not an Oracle expert - you may be able to do the whole thing in SQL - but as a first approximation: SELECT ID, Content FROM MyTable WHERE Content LIKE '%book%' then for each returned record, echo $id. .substr_count($content, book); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: selected problem
Its Me [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... i have the file: edit_profile.php Just curious: why do you have May 15th and October 6th listed as locations? ?php if (!isset($location)) $location = ; $locations[] = array( = Choose City, Abou Redes = Abou Redes, Abou-Zabal = Abou-Zabal, Al Arish = Al Arish, Al Mahala = Al Mahala, // ... etc, etc... Zafrana = Zafrana, Zagazik = Zagazik ); echo \nselect name='location'; foreach($locations as $value = $text) echo \n\toption .($location == $value ? selected : ) . value='$value' .$text ./option; echo \n/select; ? NOTE: 1. That is a pretty God-awful long list; is there any way to subdivide it logically? Maybe use a pair of Javascript-coupled selection-boxes - use the first box to specify the first letter of the desired name, then the second box provides (a much shorter list of) all destinations beginning with that letter. 2. If your option-value and option-text are always identical, there is no need to specify the value separately (it defaults to the text). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Capture content
Ciprian Trofin [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... price of the stock on a daily basis. My friend checks the Bucharest Stock Exchange page, or other relevant page, and updates the price of the stock, for future reference. I think there is a easier way, that is making a script to load the remote web page containing the updated stock price. You need to look at the curl extension. // get the page... $ch = curl_init(http://url/path.html;); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $pg = curl_exec ($ch); curl_close ($ch); // $pg now contains the source for the page Then you need to examine the contents of $pg and look for ways to grab the values you need out of the string with the ereg* or preg* functions. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Capture content
Ciprian Trofin [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I think there is a easier way, that is making a script to load the remote web page containing the updated stock price. A second possibility: they may also make the data available as XML (or be willing to do so). Contact the site webmaster and ask! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Exclude indentical values
SELECT BlaID, MAX(BlaInfo) AS Info FROM mytable GROUP BY BlaId Prodoc [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... ok, sorry about that :-) Table: BlaID BlaInfo 20 4 17 8 20 9 15 81 20 12 20 23 17 0 Result: BlaID BlaInfo 15 81 17 0 20 9 I don't realy care about the value's I get in BlaInfo as long as I get one of those value's... I asume this is a very simple instruction but I just started using php+mysql so I don't know the propper words I could use to do a search :-) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: complicated transtable problem
Andy [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi there, I am still struggling with following problem: There are two tables in mysql 1. city fields: ID, countryid, provinceid, city containing 2.5 million entries. 2. province fields: ID, countryid, provinceid, provincename (scratching head) Now, surely that's not normalized... shouldn't it be table Country : id, name table Province : id, country_id, name table City : id, province_id, name Now there are some cities without a valid province id in the other table. ... meaning that they link to a non-existent entry? Or to an incorrect entry? Or what? Where did the data come from? Would it be possible to get cleaner data to work with? I would like to: 1. delete those province rows (all belonging to this country) in the province table Not sure I follow here... could you give some sample data? Are you wanting to delete all provinces of a given country which contain no cities? 2. set the province_id to in the city table. This would be simple with a database which supported multi-level SELECTs. However, we will work with what we have. SELECT city.ID FROM city LEFT JOIN province ON city.province_id = province.id WHERE province.provincename IS NULL ... and use the results to build the query... UPDATE city SET province_id=NULL WHERE id IN [your comma-delimited list here] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Newbie attack...
Everything is working great except the fact that when I put some php code into the 'text' field, in order to run en extra sql command in the page, it hangs and just prints the code as if it was just text. (shrug) so far as the database is concerned, it *is* just text. If you want returned code evaluated, you will have to explicitly evaluate it. Possible approaches: 1. Search for php code in your content: split the string appropriately and evaluate as needed. I would avoid this because it's a lot of extra work, and because it's quite possible to write 'interleaved' PHP code that requires several blocks working together; evaluating a single block at a time will just get you errors. 2. Evaluate all your content. You would have to be very careful about letting people contribute content, and it might be a bit slower; but it's very very simple. 3. Have markers in your content, referring to PHP code from another table. Would be a bit slower (have to do multiple queries to retrieve code as needed), but more secure - people can safely contribute to the HTML content table, you can let them reference standardized PHP fragments. 4. Half-way between #2 and #3: add a flag field to your database table, if the flag is set the content must be evaluated, otherwise it is plain HTML and can just be echoed. People can contribute content, but the flag stays off until you double-check any PHP code for safety. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: viewing records
he will have access to the first record, which I'm displaying in a form. My question is: can another user view the same record at the same time? It depends entirely on where and how you get the data. Of itself, there is nothing to prevent the same record being displayed to any number of users. if the answer is yes, is there any way to prevent this? It is possible, but I am not at all certain it is the right thing to do... I would be more concerned about data corruption, and a better way to prevent that is to keep a copy of the original data and compare it to the 'official' version before updating. This way, any number of people can view the record, but only one can update it; anyone who tries updating it after that can be warned and prompted to modify their own data appropriately. This also avoids problems with people locking records and then leaving, or leaving their browser at the page for 6 or 8 hours during which time no-one else can access that record. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql joining 101
Matthew Crouch [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Here's an easy one that I can't find laid out for me anywhere: I want a self join that pairs up the id numbers of a table in every permutation e.g. i have id #s 1, 2, and 3 i need this result: 1 2 1 3 2 1 2 3 3 2 3 1 clear enough? Uh... haven't tested it, but seems likely: SELECT a.id, b.id FROM mytable AS a JOIN mytable AS b ON a.id != b.id 1. this could easily return a very VERY large result. 2. are {1,3} and {3,1} really different, or should you use ...ON a.id b.id ? This would cut the size of your returned query by half. 3. there are probably much better means of accomplishing whatever you're trying to do. Just getting the list of ids and intersecting them in PHP sounds like a better approach to me. More information about what you're trying to accomplish would help. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Database search question
How can I accomplish the following? I have a table called search, I have 3 fields, city, country, type I also have an imput box where you can type in a search word. What I need is, say you type in hotels germany, I need the search to break up the sentence and then search each 3 fields in the DB looking for a match. So, for example: it would find hotels in type and germany in country, see that they belong together and then display those results - how can I do this? I know I need to splitup my search phrase into individual words to search, but i'm stuck. Two possible approaches spring to mind: 1. Search all three categories for each keyword, ie 'hotel germany' would turn into SELECT * FROM mytable WHERE (country='hotel' OR type='hotel' OR city='hotel') AND (country='germany' OR type='germany' OR city='germany') 2. A translator table: two text fields, 'phrase' and 'search', filled with something like: phrase | search 'germany' | 'country=\'de\'' 'states' | 'country=\'us\'' 'brazil' | 'country=\'br\'' 'hotel' | 'type=2' 'bed' | 'type=1' 'b\b' | 'type=3' 'london' | 'city=31854' 'paris' | 'city=22059' ... you can then use a search through the translator table to build the select statement that actually does the query. Both of these have drawbacks, mainly that the tables they nominally reference are severely non-normalized; I suspect the proper approach should be a series of queries for each term among a set of normalized tables, followed by a final constructed query... but you get the idea. Another point: single-word searches could be a problem, stumbling over 'New York' or 'bed breakfast'; it might be worth amending the search to also try consecutive-word pairs. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: int or tinyint
Just a simple question (I think). When should I use tinyint over int. and what is the difference between the two? MySQL manual section 7.3 (data types): tinyint (8bit), range is 0 to 255 (unsigned) -128 to 127 (signed) int (32bit), range is 0 to 4294967295 (unsigned) -2147483648 to 2147483647 (signed) Basically, only use tinyint if you are desperate to save some space and you know a value will never, ever be outside its range; otherwise use int. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] using multiple checkboxes to delete from db
You can go one better than this, even... use PHP to construct a single SQL query using the IN( ) comparator, ie: ?php // NOTE: this assumes that 0 is never a valid id; I just // stuck it in to make the comma-delimiting come out right $query = DELETE FROM tablename WHERE id IN ( 0; foreach($_POST[del] as $val) $query .= ', '.$val; $query .= ' )'; [connect] [query] [close connection] ? Olinux [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... to make it a little better, make one connection to the db before you loop and then close the connection [connect] foreach loop [close connect] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: calculations based on checkbox value
Here is some code, which I modestly suggest is superior for the following reasons: 1. Includes simply scaffolding (ie a sample form). 2. Code is separated into functions, rather than one monolithic block. 3. Somewhat improved word-counting. == html head style body { font-family: Verdana,Arial,sans-serif; } /style /head body h2Price-An-Ad/h2 form New ad text:br / textarea name='ad' style='width:400px; height:300px;'/textareabr / input type='checkbox' name='deduct' value='true'Make deductionbr / Run length select name='weeks' option value='1' selectedOne week option value='2'Two weeks option value='4'One month /selectbr / input type='submit' value='Calculate' /form ?php if (isset($ad)) { $ad = stripslashes($ad); $words = count_words($ad); $price = calc_price($words, $deduct, $weeks); echo Priced text: .div style='width:400px;'pre$ad/pre/div .$words words, .(isset($deduct) ? with : no). deduction, for $weeks weeks comes to .sprintf(\$%01.2f,$price); } function count_words($text) { $count = 0; $tok = strtok($text, ); while (is_string($tok)) { if (strlen($tok) 0) $count++; $tok = strtok( ); } return $count; } function calc_price($words, $deduct, $weeks) { // base price $price = 5.00; // additional cost for more than ten words if ($words 10) $price += ($word - 10) * 0.20; // favored-customer deduction if ($deduct) $price -= 1.50; // by number of weeks to appear $price *= $weeks; return $price; } ? /body/html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Relational database
Ron [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Is there a way under mysql to identify the last record in a table so that I can pull information that I need from that entry. Um... sort backwards then use the first record (ie LIMIT 1)? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Is this possible?
It looks to me like you should be dividing the data differently; something like (quantity, item, option, price) VALUES (1, '6inch', '', '29), (1, '6inch', 'meny', 51), (1, 'footlong', '', 45), (1, 'footlong', 'meny', 66), and so forth... Raymond lilleødegård [EMAIL PROTECTED] wrote in message 001d01c1af34$621b96e0$31c7d450@amd">news:001d01c1af34$621b96e0$31c7d450@amd... My table look like this: Pricetable: (varetabell) (varenr, type, pris) VALUES (1, '6inch', 29), (1, '6inch meny', 51), (1, 'footlong', 45), (1, 'footlong meny', 66), (1, 'salat', 39), (1, 'salat meny', 51), (2, '6inch', 49), (2, '6inch meny', 69), (2, 'footlong', 75), (2, 'footlong meny', 96), (2, 'salat', 49), (2, 'salat meny', 69), -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Ensuring users don't overwrite each other (NOT a newbie question)
Oliver Cronk [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Thanks for that answer, you filled in some of the blanks for the table / logging solution, but I am now looking at row locking instead of a seperate table (and then doing things similar to what you outlined). Just a thought - if you have the user form echo a copy of the original data back (ie in addition to the modified data), you can compare it to the existing data and warn the user if the data has been changed in the interim. You must make the [compare-and-modify-if-unchanged] atomic, but that's okay, because it's all in the same script anyway - it becomes reasonable to do it as a transaction. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: MySQL/PHP and the case of Good Lord, that's a lot of statements
The problem is, somewhere in the middle of this script (more like closer to the beginning) the script just *dies*. I say that because there's no error message, no warnings, no footer content that's included after the processing is done, nothing. It just dies in the How long does this take to run? Could it be timing out? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: how to make a dropdown list with sql content
Venomous [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I need to make a dropdown menu from my mysql database but i don't no how to come about It's the meaning that i don't get weird things in my database for instants PI 300 or pi 300 think about what your generated output should like like: something like SELECT OPTIONFirst Item OPTIONSecond Item OPTIONThird Item {...} /SELECT So your PHP should do something like echo \n SELECT; while($row = mysql_fetch_array($conn)) echo \nOPTION.$row[item]; echo \n /SELECT; Exactly what appears in the list will depend on what you echo in the loop. Hope that's what you were looking for... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: calculate size of remote url
Chidambaram [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi i have to calculate the size of a remote url ex:http://www.ee.iitm.ernet.in/index.html i have written a php script but it returns only the size of html page it doesnot include the images size in that file could anyone help me in this regard Is this for interest, for once-in-a-while data collection, or for run-on-every-request production code? You would have to parse the HTML file, extract the names of all the images (and CSS files, applets/ActiveX components, and javascript/vbscript inclusions) called, fully qualify the names, remove duplications (which would be served from the client's cache), request the files and check their sizes, then add it all up with some additional time for each request. Alternatively, you could wave your hands and come up with some sort of fudge factor; if you want to be a bit more accurate, set your super-complete-script to try a couple thousand random URLS and scatter-plot the results, HTML-only page size vs. total page size - less reliable but far simpler and faster. If the result is within 20% for 80% of the time, I would be happy. Note that any kind of generated or active page may vary wildly in size anyway - your approach would only work on totally static pages. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Retrieving data woes
Andres Sulleiro [EMAIL PROTECTED] wrote in message 002001c18193$eacb4450$[EMAIL PROTECTED]">news:002001c18193$eacb4450$[EMAIL PROTECTED]... I have a db table that has these columns: id, date, time, title, body some of the rows can have the same date and want to output the data according to date. Like so: dateA timeA1, titleA1 bodyA1 timeA2, titleA2 bodyA2 dateB timeB1, titleB1 BodyB1 In your SQL request, sort by date. When printing the output, keep track of the previous date - only print the date if it changes. Something like $conn = mysql_pconnect($host, $usr, $pwd); mysql_select_db(mydb); $sql = SELECT id,date,time,title,body FROM mytable ORDER BY date DESC; $res = mysql_query($sql); $date = previous date; while($row = mysql_fetch_array($res)) { if ($date != $row[date]) { $date = $row[date]; echo br$date; } echo p.$row[time]. .$row[title]; echo br.$row[body]; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Multiple lines in database.
Chris Soyars [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Ok I need to beable to print to HTML each line on its own right now I would have in the database: A B C D and it will print A B C D Help! Need this for school. Um, br maybe? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Searching MySQL using LIKE
Jason Wong [EMAIL PROTECTED] wrote in message news:000301c1428d$f11b3a80$[EMAIL PROTECTED]... The obvious first thing to do is to screen your keywords. Do not search on common words such as: and, if, the, in etc. An easy way to do this is to set up an array of words to exclude. Then you can parse your input string and use array_diff() to return only the non-excluded words, ie ?php // Assume we get $searchphrase from a form // Strip all non-alpha text from string; // anyone know a more convenient f'n for this? // NOTE: this list is quite incomplete. // NOTE: can also use this step to convert // accented characters to their plain counterparts. $conv = array( 0 = , 1 = , 2 = , 3 = , 4 = , 5 = , 6 = , 7 = , 8 = , 9 = , ! = , = , \n = , \t = , . = , = , = , \\ = , ); $searchphrase = strtr(strtolower($searchphrase), $conv) // Parse input string into an array of words $use = explode( , $searchphrase); // Add any other too-common words that occur to you. $excl = array( 'i', 'you', 'he', 'she', 'it', 'am', 'is', 'be', 'are', 'to', 'from', 'if', 'the', 'this', 'that', 'in', 'of', 'at', 'a', 'an', 'and', 'or', 'not' ); // Filter out too-common words $use = array_diff($use, $excl); if (count($use) == 0) { echo No valid search terms; exit(); } // The FALSE is a dummy term so I don't // have to muck about deciding whether an // OR is needed for each search term. $query = 'SELECT * FROM table WHERE FALSE'; foreach($use as $term) $query .= OR keywords LIKE '%$term%'; ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Parsing of db results by PHP
Robert Gormley [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi all, I have a MySQL db which contains table test, field test... one of the entries is ? external($url, $text); ? Where external() is a function i've written which outputs simple text. I want to be able to put calls to this function into the database, and have them parsed on rendering... With the above example, the raw code is just spat to the browser, and doesn't hit the interpreter. Either trim the string and eval(), or change the database to store just the contents of $url and $text and do the call to external() in your PHP code. Personally, I think the second is preferable (by the principle of orthogonality ;-). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: php question - newbie
Chris Ross [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Our website was running PHP Version 4.0RC1, then our host decided to upgrade to version 4.0.6. Once they did this our site no longer worked every time we went to a php page it would give an internal error. Now our host tells us its because we have old php code is this possible. Now they went back to version 4.0RC1, but I'm confused. I'm new to php, but that would be strange if the updated it and it didn't support old code. If this is the case can someone point me in the right direction so I can find how to change my code to be compatible? ... the text of the error and a snippet of the relevant code would be very helpful. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Checkboxes with mySQL
Cilfa [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... $query = mysql_query(UPDATE articles SET pr='1' WHERE id='$p[id]'); But it does nothing! How can I insert multiple values (from the checkbox array) at one time in a database? UPDATE articles SET pr='1' WHERE id IN ( ...list... ) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Use the User Input Critia as part of Query! (Mysql)
Jason Wong [EMAIL PROTECTED] wrote in message 021701c13489$245b1f40$[EMAIL PROTECTED]">news:021701c13489$245b1f40$[EMAIL PROTECTED]... - Original Message - From: Jack [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, September 03, 2001 10:35 PM Subject: [PHP-DB] Use the User Input Critia as part of Query! (Mysql) $query=select name,department,Leave_From,Leave_To, Leave_Total,Reason from leaverequest where Staff_Number=?print($StaffNum);? and authorized is null; Try something like: $query=select name,department,Leave_From,Leave_To, Leave_Total,Reason from leaverequest where Staff_Number ='$StaffNum' and authorized is null; Also, for security, you would be wise to cast $StaffNum to int before using it: $StaffNum = (int) $StaffNum; $query = SELECT .name,department,Leave_From,Leave_To, .Leave_Total,Reason .FROM leaverequest .WHERE Staff_Number=$StaffNum .AND authorized IS NULL; HTH -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: A timed refresh ?
Dave Carrera [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have an array of which shows an image in a place on my page which shows the next on the list when the page refreshes, this works fine. What I want to do is have the image refresh on a 5 second timed interval. So: I have a list of images i.e..: image_1.gif image_2.gif image_3.gif Which I want to refresh every 5 seconds I would suggest using JavaScript for this; something like html head script language=javascript !-- img = 0; max_img = 0; delay = 5000;// 5 seconds imgnames = new array( 'image_1.gif', 'image_2.gif', 'image_3.gif' ); images = new array(); function preload() { var i = 0; for (name in imgnames) { images[i] = new Image(); images[i].src = name; i++; } max_img = i; } function start() { setInterval(replaceImage(document.images[abc]), delay); } function replaceImage(hImg) { if (++img = max_img) img = 0; hImg.src = images[img].src; } -- /script /head body onload='preload(); start();') img name='abc' src = 'image_1.gif' /body /html (This is just off the top of my head; it is untested and probably not cross-browser compatible, but it should point you in the right direction). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Really weird problem: cross-server databasing *g*
Markus Mayer [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Forgot to mention ... the only way to access the database on B is to connect to localhost there. I would write a script on B that accepts parameters and returns the results in easy-to-parse form (ideally, the final result you want, with unique delimiters like ajlmdyour results/ajlmd). Then the script on A calls the script on B, parses the page, and gets the results. No pop-ups. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Database Function
Georgie [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a simple php script that searchs a MySQL database and returns results that I made myself and I'm trying to implement code that splits the results into x amount of pages, buts it really tricky. ... if you want X results per page, look at the LIMIT clause for your SQL statements. If you actually meant X _pages_ (... I don't see where this would be useful, but hey...) I would check the number of returned results with mysql_num_rows(), calculate the start-row offset, and then mysql_data_seek() to the place you want. Either way, it's actually pretty simple. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: go to another URL
Andrius Jakutis [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hello, What is the command in PHP coding, to order go to another URL? header(Location: newurl); Note that this must be sent before any of the message body. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Can DBA(Database Abstract) function can work under Win2k?
Donald Fei [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... My PHP runs under: Windows 2000 Professional + Apache/1.3.20 + PHP4.0.6 + MySql3.23.32 when i compile the following code: ?php $db=dba_open(database.db,c,db2); ? There is the error: Fatal error: Call to undefined function: dba_open() in D:\Inetpub\WebSite/dba_test.php on line 2 Thank you! make sure the line 'extension=php_dba.dll' is uncommented in php.ini -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Can DBA(Database Abstract) function can work under Win2k?
Hugh Bothwell [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Donald Fei [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... My PHP runs under: Windows 2000 Professional + Apache/1.3.20 + PHP4.0.6 + MySql3.23.32 when i compile the following code: ?php $db=dba_open(database.db,c,db2); ? There is the error: Fatal error: Call to undefined function: dba_open() in D:\Inetpub\WebSite/dba_test.php on line 2 Thank you! make sure the line 'extension=php_dba.dll' is uncommented in php.ini ... and if you uncomment it, you have to restart the web server become it becomes effective. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: Photo Album Schema
Sheridan Saint-Michel [EMAIL PROTECTED] wrote in message 00f601c12ca3$8bb26420$[EMAIL PROTECTED]">news:00f601c12ca3$8bb26420$[EMAIL PROTECTED]... From: Hugh Bothwell [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sheridan Saint-Michel [EMAIL PROTECTED] wrote in message 03a901c12c02$c60d4640$[EMAIL PROTECTED]">news:03a901c12c02$c60d4640$[EMAIL PROTECTED]... I don't know if having multiple users associated with a single image is at all beneficial, and I can see where it might cause all sorts of problems. For example, you and I both have the same image in our album (we are both assciated with it in the DB). What happens when I change the description? Do you change the description field, thus changing the description on both our pages? Do you now have to create another entry in your Image table? Just to be nitpicky: I don't see where this would be useful - allowing users to share/transfer pictures? - but it's not overly difficult either. Just split the information between an Image table and an ImageOwner table. He suggested a DB redesign to allow a Many to Many relationship between users and images. I was trying to show that there was no reason to do so and at least one good reason not to do so =) Yes, I followed that - I'm just playing Devil's Advocate here. I would rephrase your conclusion as 'no reason to do so, but no reason not to if you really feel the need'. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: TopSpeed
Guilherme Bresser [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have one problem.. TopSpeed don't support ODBC.. :-\ This is the only method I've seen for languages other than Clarion. http://www.softclaim.com/odbc_interface.htm If there ARE any other methods, I'd love to hear about them! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: It's just a logo..
Wisam [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Do you know What's a logo worth: PRICELESS. Do you have a logo ? Do you have what it takes to design one ? To do it in Flash ? Do you heve what it takes to put it on your website ? on your stationery Business card ? On literally hundreds of products ? Do you know What's a literate ad worth: PRICELESS. Do you have what it takes to design one? Obviously not. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: I am really stuck
Matt C [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... 1) I would like to pull all entries out of a table that have dates that haven't occured yet. Basically forget anything before the current day. How do I do that? DELETE FROM table WHERE timestamp $now 2) I enter news into a table and would like to display a summary page. Basically it has a list of headlines under the date they were added. Monday 10th August *Item 1 *Item 2 Tuesday 11th August *Item 1 etc How do I do that? This is a wildly recurrent question, which really should be in the FAQ if it's not already (hint, hint...) Note: this is very PHP-like pseudocode; it WILL NOT run as written. // The query MUST BE sorted by the listby field, // so that equal values will end up together. $query = SELECT listbyfield, fieldB [, fieldC etc...] .FROM table ORDER BY listbyfield; $res = mysql_query($query); $lastseen = ; while ($row = mysql_fetch_array($res)) { // only echo the listby field if the value changes if ($row[listbyfield] != $lastseen) { $lastseen = $row[listbyfield]; printNewHeader($lastseen); } printEntry(); } ... you will of course have to define suitable stuff for printNewHeader() and printEntry(). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: Photo Album Schema
Sheridan Saint-Michel [EMAIL PROTECTED] wrote in message 03a901c12c02$c60d4640$[EMAIL PROTECTED]">news:03a901c12c02$c60d4640$[EMAIL PROTECTED]... I don't know if having multiple users associated with a single image is at all beneficial, and I can see where it might cause all sorts of problems. For example, you and I both have the same image in our album (we are both assciated with it in the DB). What happens when I change the description? Do you change the description field, thus changing the description on both our pages? Do you now have to create another entry in your Image table? Just to be nitpicky: I don't see where this would be useful - allowing users to share/transfer pictures? - but it's not overly difficult either. Just split the information between an Image table and an ImageOwner table. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Masking a reacuring result
Ron Gallant [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I am querying a list with a date field. I want to order the list by the date field and only show each days date once with the other fields showing. (row 1) 2001-08-19 - some text here. (row 2)more text under same date. My date does not show. (row 3) 2001-08-20 - Lots of text today. (row 4)Even more text here today. My date does not show. (row 5)Yes more text, date not showing. This seems to be a recurrent question in various guises; The idea is simple: sort by date (so all equal dates are together), then keep a temporary variable set to the last-seen date. When the date changes, output a new date value. == example.php ?php mysql_connect(host, user, pwd) or die(Error connecting: .mysql_error()); // return the 20 most recent items $query = SELECT mydate,mytext .FROM table .ORDER BY mydate DESC .LIMIT 20; $result = mysql_db_query(dbase, $query) or die(Error querying: .mysql_error()); // show results in a table $lastdate = ; echo \ntable; while ($row = mysql_fetch_array($result)) { extract($row); if ($lastdate == $mydate) $t = ; else $t = $lastdate = $mydate; echo \n\ttrtd$t/tdtd$mytext/td/tr; } echo \n\table; ? === -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Table results returning 2 sets of the same row
Ron Gallant [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... And my table results are shown 2 times per row. http://www.chizeledlight.com/test.php ... at a guess, you requested the same field twice in your SELECT statement. I don't like the sample code given because it just iterates through the rows rather than using their names - if you alter your SQL, it could change the column order, which is kinda non-intuitive. I also don't know how to specify the column I want the result from. Like $columnName. Try this instead: $query = SELECT field1,field2,field3 .FROM tablename ; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { explode($row); echo \ntrtd$field1/tdtd$field2/tdtd$field3/td/tr; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Filtering
Felipe [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Will PHP have any kind of active filter such as ASP's rs.Filer Criteria And what about searching as ASP's rs.Find Criteria ... that's what SQL is for; in fact, I wouldn't be at all surprised if these 'filters' get turned into SQL on the back end. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Table results returning 2 sets of the same row
Doh! I meant extract($row); Ron Gallant [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I get Warning: Wrong parameter count for explode() in /www/chizeledlight/test.php on line 39 when I use this code. The line in error is explode($row); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: saving to two tables at the same time
Crosswalkcentral [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a form of 1/2 customer data and the other 1/2 service info. that the custoemr fills out and when they submit it my php scrips adds the customer infor to the customer table but it will not add the service info to the service table? Try doing it as two separate queries. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Averaging Numbers
Jeff Oien [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm having a hard time learning how to get an average. I have a database that gets a number and inserts in into a MySQL database every 1/2 hour during the day. For the current half hour, I want to get the last 15 days numbers for the same time as the time it is now. I can retrieve and display the numbers fine, I just don't know how to go about putting these all into variables or an array or if I can do this within a query and then take an average for them. First, a modified 'do-it-in-PHP' solution to return the average of an arbitrary number of results: ?php $result = mysql_query($query); $num = mysql_num_rows($result); $sum = 0; while ($row = mysql_fetch_array($result)) $sum += $row[val]; $avg = $sum/$num; ? And two variants on 'do-it-in-SQL- and-just-get-the-answer': SELECT AVG(val) FROM table WHERE halfhour = $nowAsHalfHour ORDER BY date DESC LIMIT 15 or, alternatively, SELECT AVG(val) FROM table WHERE halfhour = $nowAsHalfHour AND date $nowMinus15Days ;-) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: show only some entries
Andrius Jakutis [EMAIL PROTECTED] wrote in message 003d01c125c2$fa6487a0$40722fd4@mano">news:003d01c125c2$fa6487a0$40722fd4@mano... 1. How to make, that I could get output of only those entries, which name(field) is John. SELECT * FROM table WHERE name='John' 2. How to make, that only 10 entries with John would be shown in the same page, and others would be on next page and so on. SELECT * FROM table WHERE name='John' LIMIT 10*($thispage-1),10 a href='myscript.php?{$thispage+1}'Next page/a -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: replace string - case insensitive
Lars B. Jensen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... depending on what you're replacing with what, a solution is eregi_replace. I do not advice to upper nor lowercase the source as it will change parts of data unwantedly. Yes, I agree; another solution is as follows: function alt_str_replace($search, $replace, $subject) { // Temporary copies of search string and subject string; // both shifted to lowercase to make the search case insensitive. $t_search = strtolower($search); $t_subject = strtolower($subject); // Initialize result string $res = ; // Initialize search vars $search_offs = 0; $shift = strlen($search); // As long as another match is found... while (($t = strpos($t_subject, $t_search, $search_offs)) !== false) { // Copy non-matching portion of string $res .= substr($subject, $search_offs, $t-$search_offs); // Add replacement value $res .= $replace; // Update search offset $search_offs = $t + $shift; } // Add trailing end of string $res .= substr($subject, $search_offs); return $res; } Hope that helps... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: reload page
Schleipp [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi everybody, I have created a webpage with two frames. One of this frames is a form in which the user can change some data, which you can see in the other frame. I want the latter frame being updated as soon as I send the form, which is changing the data, i.e. a reload of the frame containing the changed data. However, I do not know how to realize that with PHP. Does anybody have a suggestion? form action='evaluator.php' target='name_of_second_frame' ... /form -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: reload page
Russ Michell [EMAIL PROTECTED] wrote in message news:SIMEON.10108141609.F@k1c. anglia.ac.uk... I just needed a similar thing to occur in my app! Just reload the page using the header function: Once submit has been hit in one frame, pass a hidden value from Frame1 to frame2: input type=\hidden\ name=\refresh\ Then detect for it in the 2nd frame and refresh the page using the header() function: if (isset($refresh)) { header(Location: $PHP_SELF); } That seems like an (umm...) *unusual* method... When the form is submitted, it calls the target page - which then calls itself again? I don't see what this gains you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: reload page
Russ Michell [EMAIL PROTECTED] wrote in message news:SIMEON.10108141754.G@k1c. anglia.ac.uk... I don't see what this gains you. Well you asked if there was a way to refresh your target frame once a submission was made from an origin frame. This method would do that. The question was originally posed by Christian Schliepp, [EMAIL PROTECTED] (not by me). Then again, why does the second frame not already display the results of the submission?? As it get's called from the first (origin) frame. That was kinda my point. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: Show abbreviated article
Jon Farmer [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... From: Johannes Janson [mailto:[EMAIL PROTECTED]] Sent: 13 August 2001 12:15 To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: Show abbreviated article My question is this: how can I select only those first 20 words in the PHP code? SELECT LEFT(YourBlobFiekd, 20) FROM YourTable; NO! This will return the first 20 characters from the field not the first 20 words. To do that you need to use a regexp in the SQL or explode the result in php and use the first 20 elements of the array! ... you could significantly lower bandwidth requirements by returning, say, the first 150 characters and then explode'ing to make it 20 words. Another thought: if you want a string of close-to-standard length, maybe just return 100 chars and truncate to the last word boundary using strrchr(), instead of requiring a fixed number of words? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Interbase lob field on the web
Alex.Tesi [EMAIL PROTECTED] wrote in message 003901c123fa$1ff2da50$[EMAIL PROTECTED]">news:003901c123fa$1ff2da50$[EMAIL PROTECTED]... Hi i have a problem printing a lob field containing an image. The database i use is Interbase 6.0 I have a blob/lob field with a gif image inside an i like to print this image on the web. Can you help me? You need a script to return the image, and you need to pass the proper parameter from the calling page... === image.php == ?php // check that param exists if (!isset($img)) { // alternatively, you could set img to // point to an 'error, not found' image // from your database... die(Error: 'img' parameter not set); } // hacker prevention... $img = (int) $img; // connect to the database $conn = ibase_pconnect(host:dbase, usr, pwd) or die(Error: .ibase_errmsg()); // query for image $query = SELECT img_contents .FROM imgtable WHERE id=$img; $res = ibase_query($conn, $query); // make sure that exactly one result was returned $num_returned = ibase_num_fields($res); if ($num_returned == 0) die(Error: specified image $img not found); if ($num_returned 1) die(Error: $num_returned images found for $img); // return image // if you kept an image-type field in your // database, you could store and retrieve // various image types - gif, jpeg, bmp, png, // swf, svg, etc... header(Content-Type: image/gif); $row = ibase_fetch_object($res); echo $row-img_contents; ? = === mypage.html === html head titleExample.../title /head body pHere is image # 394302.../p img src='image.php?img=394302' align='center' /body /html === -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Group By problem
Sharif Islam [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I am trying to caregorize to group at the same time, but its not working. Any hints? Here's my code: $temp=Dummy; while ($row = mysql_fetch_array($result)) { if($temp !=$row[group_name]){ $temp=$row[group_name] ; echo bGroup:$tempbr/b; } $temp1=blah; if($temp1 !=$row[service_cat]){ $temp1=$row[service_cat]; echo Services:$temp1br; } $machine_name=$row[machine_name]; echo a href=view_server.php?machine_name=$machine_name$machine_name/abr; } This is displaying : Group:Group_Name Services:Email Machine_Name Services:Email Machine_name2 Services: Backup Machine_name Group:Group_name2 ... I dont want to print services multiple times. Just like the group name catagorize it. You don't show your SQL, but I assume it's something like SELECT grp,svc,mach FROM table ORDER BY grp,svc,mach then $grp=; $svc=; $firstmach = true; while ($row=mysql_fetch_array($result)) { if ($grp != $row[grp]) { $grp = $row[grp]; PrintNewGroup($grp); $svc = ;// force new-svc when switching groups } if($svc != $row[svc]) { $svc = $row[svc]; PrintNewService($svc); $firstmach = true; } PrintMach($row[mach], $firstmach); $firstmach = false; } Hope this helps... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Member authentication with PHP and MySQL
Cato Larsen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Sheridan Saint-Michel [EMAIL PROTECTED] wrote in message 00df01c12400$ad2a1220$[EMAIL PROTECTED]">news:00df01c12400$ad2a1220$[EMAIL PROTECTED]... From: Cato Larsen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 12, 2001 6:47 PM Subject: [PHP-DB] Member authentication with PHP and MySQL I'm trying to authenticate members by using php and MySQL. How do I make the authentication to go to site: members.php?charnick=$charnick Where $charnick is brung from the DB line who was authenticated? I would use either cookies or sessions for this. First Check for the cookie, and verify its contents. If there isn't a cookie then do the login prompt like you are doing now. One more thing... When I've set up the script and run it on my local server I get this error: 1. what error? 2. replying at the top of a message is poor form. I know Outlook Express wants to do this; it's just one more reason to hate the Evil Empire. 3. please trim the replied-to stuff to keep only attributions and relevant content. I don't like having to read 5k of old text just to make sure you haven't added anything to it... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Group By problem
- Original Message - From: Sharif Islam [EMAIL PROTECTED] To: Hugh Bothwell [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, August 13, 2001 11:50 AM Subject: Re: [PHP-DB] Re: Group By problem But its displaying the same as my code: The SQL was just for reference, to make sure we were both working on the same basis... I don't think you looked at the PHP code I gave, as it should produce exactly what you are asking for. Group:Desktop Service:BACKUP AITSBKUP Service:E-Mail AITSMAIL JEEVES Group:Unix Service:Database APOLLO Service:FIREWALL Console try defining style body { font-family: Verdana, Arial, sans-serif; } .group { font-weight: bold; font-size: 120%; color: #44; } .service { font-weight: bold; color: #77; } .machine { font-size: 80%; color: #77; } /style ?php function PrintNewGroup($grp) { echo br\nspan class='group'$grp/span; } function PrintNewService($svc) { echo br\n\tspan class='service'$nbsp;$svc/spanbr; } function PrintMach($mach, $first) { if ($first) echo nbsp;nbsp; else echo nbsp;|nbsp;; echo span class='machine'$mach/span; } ? $grp=; $svc=; $firstmach = true; while ($row=mysql_fetch_array($result)) { if ($grp != $row[grp]) { $grp = $row[grp]; PrintNewGroup($grp); $svc = ;// force new-svc when switching groups } if($svc != $row[svc]) { $svc = $row[svc]; PrintNewService($svc); $firstmach = true; } PrintMach($row[mach], $firstmach); $firstmach = false; } How's that? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: PHP4, MySQL, errors....
Cato Larsen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hey! Thanks for the help Mr. Bothwell. But now it seems I get a new error: ;-) The error of my ways is apparent - I typed that off the top of my head, and I got bit by my own bug - using unescaped double-quotes inside a double-quoted string. Try this: ?php $prof = Nano-Technician; // setup SQL statement $SQL = SELECT * FROM memberinfo WHERE prof='$prof' ; if (!($retid = mysql_db_query($db, $SQL, $cid))) { echo( Error: .mysql_error()); exit; } // header row, just to set column widths $contents = row(cell(, 150) . cell(, 200) . cell(, 200)); // for each character... while ($row = mysql_fetch_array($retid)) { $contents .= row( cell(img src='.$row[picurl].') .cell( bold( $row[tit]. .$row[charname] . quot;.$row[charnick].quot; .$row[charsname] ).br .bold(Contact: ).$row[email].br .bold(Level: ).$row[lvl].br .bold(Breed: ).$row[breed].br .bold(Profession: ).$prof.br .bold(Location: ).$row[loc].br .bold(AIM: ).$row[aim].br .bold(ICQ: ).$row[icq].br .bold(MSN: ).$row[msn].br .bold(Yahoo!: ).$row[yahoo].br ) .cell( bold(Born: ).$row[born].br .bold(Appearance: ).$row[appearance].br .bold(Position: ).$row[posn].br .bold(Characteristics: ).$row[charac].br .bold(Strengths/weaknesses: ).$row[streng].br .bold(Bio: ).$row[bio].br ) ); } // print it. echo table($contents); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: PHP4, MySQL, errors....
Cato Larsen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Just to have said it... Im green in both PHP4 and MySQL. Can anyone say what I've been doing wrong here, and how to fix it, or even better. Debug the whole shit! =) First, make sure PHP is actually running. Try this: ?php $str = PHP is not running!; echo substr($str, 0, 7) . substr($str, 11); ? For one thing, trying to echo unescaped double-quotes won't work, ie echo table leftmargin = 0;// no good! Use ' or \ instead. Second, all this variable-renaming seems like a waste of effort; just use the array directly. $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo(ERROR: . mysql_error() . \n); } If the connection fails, your script prints an error message, then continues trying to query... if (!$cid) { echo Error: .mysql_error(); exit; } ... or redirect them back to a different page. # setup SQL statement $SQL = SELECT * FROM memberinfo ; $SQL = $SQL . WHERE prof = '$prof' ; $sql = SELECT * FROM memberingo .WHERE prof='$prof' ; echo (PDTBMembers who are $prof s/BBR\n); dt should only occur in dl.../dl $apperiance = $row[apperiance]; 'appearance' $prof = $row[prof]; ? you already know prof; why query for it? First thing to do is write a couple of functions to take care of the formatting for you: // Generic tag-formatting routine // Ensures all tags are closed properly; // Also forces you to think about tag-clause formatting //so the final result is readable. function clause($preopen, $tag, $opts, $pretext, $text, $preclose) { return $preopen$tag $opts$pretext$text$preclose/$tag; } function table($contents) { return clause(\n, table, style='margin-left: 80px;', , $contents, \n); } function row($contents) { return clause(\n\t, tr, style='margin-top: 30px;', , $contents, \n\t); } function cell($text, $width=0) { if ($text == )// check for empty str $text = nbsp;; $opts = ($width 0 ? style='width: $widthpx;' : ); return clause(\n\t\t, td, $opts, , $text, ); } function bold($text) { return clause(, b, , , $text, ); } I would simplify your table, too, at least until you get it working; play with it after that. $contents = row(cell(, 150) . cell(, 200) . cell(, 200)); while ($row = mysql_fetch_array($retid)) $contents .= row( cell(img src='{$row[picurl]}') .cell( bold( {$row[tit]} {$row[charname]} .quot;{$row[charnick]}quot; .{$row[charsname]} ).br .bold(Contact: ).$row[email].br .bold(Level: ).$row[lvl].br .bold(Breed: ).$row[breed].br .bold(Profession: ).$prof.br .bold(Location: ).$row[loc].br .bold(AIM: ).$row[aim].br .bold(ICQ: ).$row[icq].br .bold(MSN: ).$row[msn].br .bold(Yahoo!: ).$row[yahoo].br ) .cell( br .bold(Born: ).$row[born].br .bold(Appearance: ).$row[appearance].br .bold(Position: ).$row[posn].br .bold(Characteristics: ).$row[charac].br .bold(Strengths/weaknesses: ).$row[streng].br .bold(Bio: ).$row[bio].br ) ); echo table($contents); (Note: this approach builds the whole table in memory, in order to print it out using the clause() function; it might be worth breaking that out and printing the table a row at a time if there are many rows in the table.) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Select Inner Join Question
Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm trying to display a summary list of calls with one attribute being CallType. I have CallType and CallTypeID defined in a table name calltypes. The problem I am having is taking the output of CallID defined in calls and having the script match the CallTypeID to the CallType. $display_calls_sql = SELECT CallID,CallDateTime,CallSubject,CallStatus FROM calls WHERE ContactID = $ContactID; $display_calltype_sql = SELECT CallType FROM calltypes INNER JOIN calls ON calltypes.CallTypeID = calls.CallTypeID WHERE CallID = '$CallID' ; $display_calls_sql = SELECT .CallID, CallDateTime, CallSubject, CallStatus, CallType .FROM .calls INNER JOIN calltypes ON call.CallTypeID = calltypes.CallTypeID .WHERE .ContactID = $ContactID; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: counting and displaying a how many figure
Dave Carrera [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi All I would like to know how to count how many downloads of a file I have on my site is downloaded and display something like file.name downloaded times on my page. I have this idea using mysql db. table files ID int autoincrment, file_name, URL, I believe this would utilise something like the count() function but I haven't used this yet Depends whether you want to track any additional information, like the IP of the downloader or a timestamp; if so, you need a separate table with per-download entries. If all you want is a count, I would just add a field to the file table... UPDATE TABLE files SET download_count=download_count+1 WHERE ID=$fileId. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: List Results Not Working
Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... echo .$list[CallID]. .$list[CallDateTime] ^^^ Try removing the leading ' . ' -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: dba_open
Patrick Callihan [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I don't seem to have the *.so modules available. When I added the line 'extension=php_dba.so' to php.ini, nothing changed. When I tried to use the dl() function, I just got an error message: Warning: Unable to load dynamic library './php_dba.so' - ./php_dba.so: cannot open shared object file: No such file or directory in /home/pat/html I did a 'find / -name php_dba.so' and came up with nothing. Thanks in advance for any help. Hugh Bothwell [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Patrick Callihan [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... HI, I have compiled php4 with the following command: /configure' '--with-mysql' '--with-apache=../apache_1.3.20' '--enable-track-vars' '--enable-tans-sid' '--enable-dba I haven't found any information on where to find/get/make php_dba.so; hopefully someone else can help with that. I would check the directory it's in; should be under php/extensions, I would think. I did find more info on building PHP on *nix; in order to compile dba support in, it looks like you need another switch: http://www.php.net/manual/en/ref.dba.php try adding '--with-gdbm' (for example - it changes depending on exactly which database you are using). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Multiple Entry
Sharif Islam [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Is there any way, I can get only one output.But somehow I have to incorpate it with the other data in that column, which doesn't have multiple entry. Any hint? thanks in advance. !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN html head titleSample code: Removal of duplicate categories by associative array/title style type=text/css body { font-family: Verdana, Arial, sans-serif; } .service { font-size: small; color: #00; margin-top: 20px; } .machine { font-size: smaller; color: #743A44; margin-left: 20px; margin-top: 5px; } /style /head body ?php $conn = mysql_connect(host, user, pwd); $result = mysql_db_query(db, SELECT .services AS svc, // set aliases for brevity .machine_name AS mach .FROM table );// ORDER BY is unneccessary // parse $list = array(); while ($row = mysql_fetch_array($result)) $list[$row[svc]][] = $row[mach]; // print echo \nul; foreach($list as $key = $machines) { echo \n\tli class='service'$keybr\n\t\tspan class='machine'; $first = true; foreach($machines as $name) { echo ($first ? : | ).$name;// could easily make this a hyperlink $first = false; } echo /span\n\t/li; } echo \n/ul; ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Limit Select Field Characters?
select * from table where date_format(timestamp, '%y%m%d') = '010801' Jeff Oien [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a timestamp field that looks like this 0109011754 but I only want to compare 010801 when doing a SELECT. Is there a way I can do this? Thanks. Jeff Oien -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Avoiding Multiple IDs
Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What is the best method for avoiding multiple ids for the same information. For example: I have a table name company that has unique ids. The CompanyID are tied to a table name contacts which have unique ids (ContactID). The problem seems to be that if I add a contact with an existing CompanyName then I will get multiple ids for the same CompanyName. When inserting a new contact, do a search for the company name. If it exists, use the existing id; otherwise, create a new company and get the new id. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: [Q] PHP on Linux, Oracle on Win32
Donovan J. Edye [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... G'Day All, I need to establish connectivity between a Debain Linux box running PHP 4.06 and Oracle 8i running on a Win32 box. Can someone point me at some FAQ's or other help. At present I have managed to get MS-SQL 2K going using TDS (Tabular Data Stream). Could TDS also be used for Oracle? ... I'm not an expert on Oracle by any means, but what is wrong with ora_logon(user@tns, pwd); using the standard PHP Oracle drivers? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Random question selection in PHP w/ MySQL backend.
Adam Lundrigan [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What i need to do is select 10 questions from a database (db: vpt, table: questions), and make sure that the same question doesn't appear twice. The questions need to appear in a random order each time the script is loaded. $mysql_connect(host, user, pwd); $result = $mysql_db_query(vpt, SELECT id, txt FROM questions .ORDER BY RANDOM() LIMIT 10 ); function makeQuestion($qid) { return ( input type='radio' name='q[$qid]' value=11 .input type='radio' name='q[$qid]' value=22 .input type='radio' name='q[$qid]' value=33 .input type='radio' name='q[$qid]' value=44 .input type='radio' name='q[$qid]' value=55 ); } function makeRow() { $str = \n\ttr; $num = func_num_args(); for ($i = 0; $i $num; $i++) $str .= \n\t\ttd.func_get_arg($i)./td; $str .= \n\t/tr; return $str; } echo \nform\ntable; while ($row = mysql_fetch_array($result)) echo makeRow(makeQuestion($row[id]), $row[txt]); echo makeRow(input type='reset', input type='submit'); echo \n/table\n/form; Voila - they get ten questions at random, in random order; when they submit the form, you get the question id back as the array key and the answer as the value. Hope that helps ;-) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: dba_open
Patrick Callihan [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... HI, I have compiled php4 with the following command: /configure' '--with-mysql' '--with-apache=../apache_1.3.20' '--enable-track-vars' '--enable-tans-sid' '--enable-dba The function dba_open() does not work for me. I get the following error message: Fatal error: Call to undefined function: dba_open() If you will use this in many of your scripts, edit php.ini - remove the ';' before 'extension=php_dba.so'. If you'll only use it in a few, look up the dl() function in the manual, http://www.php.net/dl -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Image Bank with php mysql!! ??!!
Koutsogiannopoulos Karolos [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I wan't your opinion regarding a program i am constructing. It is about an image bank for graphic studios or anyone else who needs a program that can insert his pictures or descriptions of it and be able to make a fast and reliable search. http://www.hotscripts.com/PHP/Scripts_and_Programs/Image_Galleries/more2.htm l What would be best.? Inserting the pictures in the DB or in the file system I would keep the image name in the database; save the original image in a dedicated directory with a numeric name like 4920185.jpg and then the thumbnail either with a suffix (like 4920185b.jpg) or with the same name in a thumbnails directory; store the number as the picture ID. The numbers should be large and pseudorandom, ie you don't want to make it easy for someone to write a script to leech all your pictures (it'll still be possible, but harder). Maybe use the database ID to seed a random number generator, and use the Nth generated number? Have a text field for keywords, a text field for description, a price field?, the author's name, email, and homepage. If you put the image directory below the web root directory, then the images can only be accessed via a script, and you can restore the original name at download (this solves the problem of name collisions). If you're going to sell the pictures, you should allow a buyer more than one download, in case they screw up or accidentally delete it on their system; I would have a table for 'current purchases' with a buyer ID and picture ID, and allow them something like access for a week, up to 20 downloads of that image. ? Also notice that it is a reference db and not an actual bank. I mean that there will be only photos of low quality and not the full picture which could be very large. (shrug) as above, keep the images in the filesystem; then it doesn't matter how large it is. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Storing last access
Olinux O [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi all, I would like to display messages that are entered into a database since the last time i checked it. [Much like web based email marks NEW messages.] What is the best way to do this? By adding an additional column to the Messages Table OR creating a new table with the field Table_Name and Last_Checked Adding a field to the table is a single-user solution; if you want this useable by more than one person, a second table is needed. There are two ways of going about this; if you want to know whether individual messages are read or not, you will have to keep individual user/message records; if all you want is messages since a given date, you can just add a 'last-read' timestamp to your users table. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Query displays one
Mike Gifford [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The problem is that I am only getting one response from this query rather than 5. I can't figure this out. What did I do to only get one response? Try removing the ORDER BY and LIMIT and run the query by hand - how many responses do you get? The search may only return one article. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: A Join Question
Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm trying to create a join statement that pulls out a CompanyName based on a given CompanyID that is tied to a specified ContactID. For example, if ContactID=1 then the corresponding CompanyName might be Smith, Inc. depending on what was entered. SELECT CompanyName FROM Company INNER JOIN Contacts ON Company.CompanyID = Contacts.CompanyID WHERE ContactID=$ContactID -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: new lines in text field
Kenn Murrah [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm trying to concatenate several values entered in my form, then write them to a TEXT field in my mySQL database. All is well, except that I want to each value to appear on a different line. I've tried \n and that didn't work. What am I doing wrong? You skipped a step here, between write it to my database and appear on a different line. I assume that you insert to the database, then pull it out and display it as HTML. '\n' doesn't cause a line-break in HTML. You can either use br instead of \n before putting it in the database (less portable), or look at the nl2br() function (I would prefer this option, personally). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Tree Display
Sharif Islam [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I am still trying to figure out how to do it. I want to display my result from the data base in tree/menu like system. Could you give us your SELECT statement and one row of returned data? So the result page will look like this: +Result1 (you click this , it will expand) -Item1 (you click this and get more info) -Item2 -Item3 The expanding tree bit is done in JavaScript, see http://kmserv.com/testbed/tree/smith_jstree.html for a simple tutorial. What you need to do is use PHP to write the JavaScript to create the tree according to your query results. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: draw graph
Sommai Fongnamthip [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Dear, How could I draw graph with gd by using PHP code with custom log scale? How 'bout: function drawLogGraph($arr) { $xoffs = 20; $yoffs = 180; $drawwidth = 160; $drawheight = -160; $logscale = -10;// height of a 10x division $logscalebase = 1;// '0' on your graph $numbars = count($arr); $perbar = $drawwidth / $numbars; $barwidth = 0.8; // ... fractional draw width $halfsp = (1 - $barwidth) * 0.5; $img = ImageCreateFromPNG(graphbackground.png) or die(Could not load background); for ($i = 0; $i $numbars; $i++) { $barleft = $perbar * ($i + $halfsp); $barright = $perbar * ($i + 1 - $halfsp); $bartop = (log10($arr[$i]) - $logscalebase) * $logscale; ImageFilledRectangle($img, $xoffs + $barleft, $yoffs + $bartop, $xoffs + $barright, $yoffs, 1); } return $img; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Making a new row in HTML tables
Umm... 31 entries, 1 x 31... You might be better to choose a standard width and pad the last row with empty cells. Ian Grant [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi, Can anyone help me with this - I have a database of people, that I want to print into an HTML table - how can I make the table wrap into an equal number of rows. i.e. if there are 4 entries, a 2x2 table, 6 a 2x3, 8 a 2x4, 9 a 3x3, etc. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: another php/mysql problem
Couple of comments: 1. What's with the $artist = artist; echo $mytable[$artist]; bit? This really doesn't seem to gain you much. 2. Descriptive variable names are a Good Thing(tm). 3. Prettyprinting 4. Why are the tables in different databases to begin with? 5. Don't pull any more than you need from the database. Try: ?php // expects $band as parameter mysql_connect(localhost,username,password) or die (Could not connect to MySQL!); $band_result = mysql_query( SELECT nospaces_bands, band_bands, id, email .FROM almavale_board.bands .WHERE nospaces_bands = '$band' ) or die(Error in band query); while ($band_row = mysql_fetch_array($band_result)) { printBand($band_row); $shows_result = mysql_query( SELECT artistname, venue, time .FROM almavale_board.shows .WHERE artistname = '.$band_row[band_bands].' ) or die(Error in show query); while($show_row = mysql_fetch_array($show_result)) printShow($show_row); $release_result = mysql_query( SELECT bandname, albumtitle, email .FROM almavale_releases.releases .WHERE bandname = '.$band_row[band_bands].' ) or die(Error in release query); while($release_row = mysql_fetch_array($release_result)) printRelease($release_row); } ? ... and you can implement printBand, printShow, and printRelease as you like. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: new data detect
Sommai Fongnamthip [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi, I decide to make real time application (like stock market or online news). How could I know when new data arrive to table and retrieve them to display or update in web page? You can't, actually, short of using server-side push; what you can do is periodically requery the server; either reload the page every so often, or (better) use a flag file - set it when data is changed - and check it in the background with JavaScript, then reload the page only when it is set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: enum !!
McShen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... how do i store multiple data in one field? i have a table like this +---+---+--+-+-+---+ | Field | Type | Null | Key | Default | Extra | +---+---+--+-+-+---+ | test | enum('a','b','c') | YES | | NULL| | +---+---+--+-+-+---+ insert into test values('a','b','c'); doens't work. please help Your query is mixed up; 'test' is the field name, not the table name, and I think you want to put the values into three separate records, not one... Try INSERT INTO tablename ( test ) VALUES ( 'a' ), ( 'b'), ('c'), (''); This should get you four records, with 'test' values of a, b, c, and null. If you want to store more than one value in the same record, you should be looking at sets, not enums. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: problem with form
Try setting form.action and using form.submit() to send it ('edit.php' is not valid javascript). Here: htmlheadscript!-- function submitTo(form, url) { form.action = url; form.submit(); } --/script/headbody form name=f action=submit.php input type=submit name=Submit value=Submit Request onclick=submitTo(document.f, 'submit.php') input type=submit name=Edit value=Edit Request onclick=submitTo(document.f, 'edit.php') /form /body Note that this includes a fall-back: if JavaScript is not supported, the form will be submitted by either button. Jennifer Arcino Demeterio [EMAIL PROTECTED] wrote in message 000a01c1092d$0c3baba0$[EMAIL PROTECTED]">news:000a01c1092d$0c3baba0$[EMAIL PROTECTED]... hello, hope anyone has an idea on how to fix this... form input type=submit name=Submit value=Submit Request OnClick=submit.php class=button input type=submit name=Edit value=Edit Request OnClick=edit.php class=button /form even i click on the edit button, it will still go to submit.php page, why is that? thanks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Homesite Server Mapping
Ken Sommers [EMAIL PROTECTED] wrote in message 001001c107e2$b84ad5c0$aa42500c@zeospantera">news:001001c107e2$b84ad5c0$aa42500c@zeospantera... Has anyone successfully mapped their browser to a Remote Server? Please show your: map from: C:\Program Files\Apache Group\Apache\htdocs\ Map to: http://127.0.0.1/ (http://localhost/ would do exactly the same thing more prettily, but would bug me about connecting before doing it.) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Re: Homesite Server Mapping
- Original Message - From: Ken Sommers [EMAIL PROTECTED] To: PHP DB Mailing List [EMAIL PROTECTED]; Hugh Bothwell [EMAIL PROTECTED] Sent: Sunday, July 08, 2001 5:30 PM Subject: Re: [PHP-DB] Re: Homesite Server Mapping Thanks alot, that mapping works for me too: I use From: C:\Program Files\Apache Group\Apache\htdocs\ To: http://localhost for local mapping Have you ever tried mapping to your REMOTE host? I have tried and failed too many times, what works for Remote mapping? any one ever done it? Thanks, Ken I've never actually tried that; I always work on my files locally and test them thoroughly before they get published. I suppose that 'from:' would be the FTP URL and 'to:' would be the HTTP equivalent; anyone care to try this? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: how to find biggest value of a field across 2 tables?
Noah Spitzer-Williams [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... i have two tables each with a same field and i would like to find which table has the bigger value in this field.. is there a way to do this with one select statement? i've tried things like: select max(t1.bannerid) as b, max(t2.bannerid) as a, IF(t1.banneridt2.bannerid,t1.bannerid,t2.bannerid) FROM user_banners as t1, user_banners_approve as t2 ORDER BY t1.bannerid DESC GROUP BY t1.bannerid but im not having much luck. Uh... either do a separate select for each table, or find a way to JOIN the tables? Better than that, if you're doing what it looks like you're doing - keeping two separate tables, one for approved banners and one for non-approved one? - make a single banners table with an 'approved' field... then it's simple. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] most efficient weighting system? URGENT
How many rows are you likely to have, and how dynamic are the weights? I think I'd add a cumulative sum column to your table, ie idweightcum_weight 11010 25 15 3318 42038 5240 then $query = SELECT id FROM table WHERE cum_weight = .rand(1,40). ORDER BY cum_weight LIMIT 1; Note that if you delete or update any row, the cumulative values become incorrect. It would be better to calculate cum_weight dynamically, but I'm not sure how; also, this could be computationally expensive. Another way to do this would be to repeat each row the appropriate number of times, ie id value 11 21 31 ... 101 112 122 ... 152 163 173 183 194 204 ... 374 384 etc. Then you could use $query = SELECT value FROM table ORDER BY RAND() LIMIT 1; Noah Spitzer-Williams [EMAIL PROTECTED] wrote in message 9hilnk$9pp$[EMAIL PROTECTED]">news:9hilnk$9pp$[EMAIL PROTECTED]... if i have several rows in a table and i want some to have certain weights what is the best way to pick a random row based on its weight? ex of table: idweight 1 10 25 33 420 52 therefore, since there is a total weight of 40, id 1 should be picked 25% (10/40) of the time, id 4 50% (20/40), etc... what is the best way to do this? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] TO_DAYS() equivalent?
How about this? define(SECONDS_PER_DAY, 86400); $now = (int) (time() / SECONDS_PER_DAY); Note that this may not match the time you get from your database server, depending on what time zones you're in. David W. Banks [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Is there some way to get the equivalent of select TO_DAYS(NOW()) out of PHP without querying MySQL (or whatever.) Some formatting character for the date() function that I'm just missing? Thanks, -Dave -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Passing XML
From: olinux o [EMAIL PROTECTED] To: Hugh Bothwell [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, June 29, 2001 10:25 PM Subject: Re: [PHP-DB] Passing XML Is this what you have in mind? $url = 'http://website.com/document.xml'; $str = implode('', file($url)); $str = contains the xml doc and retains formatting $url could be a doc on the local server as well. Sure, that would be one way to implement option #1; or, as in the XML entry in the PHP manual, paging through the file in 4k chunks (better if you're parsing large files); but passing the url as a parameter instead of defining it explicitly, ie http://myserver/script.php?url=http%3A%2F%2Fwebsite.com%2Fdocument.xml Or you could post the whole XML source to the script (this could be useful for interactive testing of an XML-generating script); or you could upload an XML file and have the script parse it (I'm really not sure how this would be useful, but you could :-) Also note, if you want to get XML back again, maybe you should look at the XSLT functions. --- Hugh Bothwell [EMAIL PROTECTED] wrote: I'm not sure how you mean; it depends on where the data is coming from. I count three ways you can do this: 1. pass the XML filename (or URL) to the script via GET or POST 2. pass the XML source to the script via POST 3. upload the file via POST and call the script More details on what you're trying to accomplish would help. Niel Zeeman [EMAIL PROTECTED] wrote in message 9heo93$q9j$[EMAIL PROTECTED]">news:9heo93$q9j$[EMAIL PROTECTED]... Hi there Is there anyway of passing a xml document to a php page as raw data. What I want to do is eg. send a page a xml document and recieve a response ( in xml ) from that page. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Executing several PHP scripts simultaneously??
Consider using set_time_limit() before each sub-script executes; this will time out on any individual script, but let you extend the limit on the master script. Lisa Elita [EMAIL PROTECTED] wrote in message 004901c0ffd5$90c63680$a6fc2bca@telkomnetnstan">news:004901c0ffd5$90c63680$a6fc2bca@telkomnetnstan... How can we execute several PHP scripts simultaneously inside a single PHP script? For example, let's say master.php has 10 tasks in different PHP scripts: 1.php, 2.php, ..., 10.php. Each task is independent (the input of each task is not determined by other tasks) so we can do the tasks in any order. But if 2.php is initiated after 1.php is done, and 3.php is initiated after 2.php is done, and so on, the master.php can be expired, causing the remaining tasks not executed. So how can we execute these PHP scripts simultaneously? Regards, Lisa Elita -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Which state and country?
Um... you could look at REMOTE_HOST to get their IP address and use that to look up the address of their server. If you assume they won't log in long-distance, that should give you their country and state, and maybe a useful approximation of their city. Lisa Elita [EMAIL PROTECTED] wrote in message 004a01c0ffd5$91a991a0$a6fc2bca@telkomnetnstan">news:004a01c0ffd5$91a991a0$a6fc2bca@telkomnetnstan... Hi all, How can we know from which state and country a hit came? Regards, Lisa Elita -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]