doing SELECTS and keeping the array intact with php
Hi all, this has been bugging me for some time now. I want to do a mysql select then using php while ($a_row = mysql_fetch_array($result)) { do something to get a small portion of the data } and that works fine. Then later I need to access $result as a complete array again. Is there a way I can keep $result array intact and still take a couple values out beforehand. I can get it to work, by doing the select twice, but thats less than ideal. Thanks enormously if you can help Jules -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
filter input
Hi all, I want to insert some text into my database, but I'm worried about bad data - metacharacters etc. So I need to filter the input and remove bad characters. Which characters should I remove? What is bad for mysql? does anyone know a good subroutine (or webpage telling me all about it) for reference. I did have a good(ish) php way of doing this, but need perl this time. Thanks anyone kind enough to help Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: select statements
Thanks very much Jed, I did as you suggested but theres a problem somewhere I implode like so $toString = implode($toArray, ","); then perform query... $result = mysql_query("SELECT emailAddress FROM subscribers_html WHERE mailingGroup IN ('$toString')"); I have checked that $toString has the values that I expect, and it does (a list of words seperated by commas). this returns 0 rows If I use NOT IN instead of IN it returns all rows. Theres obviously a catch somewhere. I have scoured my books and the web, and everything looks correct to me? Obviuosly it isn't though. Can anyone see where i'm going wrong. I don't like asking the list for help unless I have exhausted my own reading supplies, but today i'm stuck What should I be looking for on the web? I can't find specific details of WHERE value IN on the web. Searches for such phrases seem pretty useless! Thanks for your time Jules - Original Message ----- From: "Jed Verity" <[EMAIL PROTECTED]> To: "julian haffegee" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, September 06, 2002 3:42 AM Subject: Re: select statements > Hello, Jules, > > You can use the "value in (a,b,c)" format. If necessary, implode your array > and do something like this: > > SELECT emailAddress FROM subscribers_html WHERE mailingGroup value in > ($toText); > > Check the documentation, if necessary, for usage of implode and "value in". > > HTH! > Jed > > On the threshold of genius, julian haffegee wrote: > > > Hi all, > > > > I have a database of names and email addresses, that I want to email. > > > > $result = mysql_query("SELECT emailAddress FROM subscribers_html WHERE > > mailingGroup='$toText'"); > > > > The select statement needs to return a row when mailingGroup='$toText', but > > $toText is an array. How should I write this select to say where > > mailingGroup is an element of the array $toText. Currently it works for > > arrays with 1 element only. > > > > I could turn the array into a string, but I wondered if there was a clever > > MySQL way of doing it all as a select > > > > Thanks for your help! > > > > Jules > > > > > > - > > Before posting, please check: > > http://www.mysql.com/manual.php (the manual) > > http://lists.mysql.com/ (the list archive) > > > > To request this thread, e-mail <[EMAIL PROTECTED]> > > To unsubscribe, e-mail <[EMAIL PROTECTED]> > > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > > > > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
select statements
Hi all, I have a database of names and email addresses, that I want to email. $result = mysql_query("SELECT emailAddress FROM subscribers_html WHERE mailingGroup='$toText'"); The select statement needs to return a row when mailingGroup='$toText', but $toText is an array. How should I write this select to say where mailingGroup is an element of the array $toText. Currently it works for arrays with 1 element only. I could turn the array into a string, but I wondered if there was a clever MySQL way of doing it all as a select Thanks for your help! Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
order by date
This must be a regularly appearing problem, which is why i'm surprised I can't find a webpage on it.. I have $result = mysql_query("SELECT title, url, description, author, date_format(date,'%D %M %Y') AS date FROM documents_tbl, url_tbl WHERE documents_tbl.title_id = url_tbl.url_id ORDER BY date DESC"); Everything works fine, but the ORDER BY bit sorts all dates as 9th, 8th 7th etc rather than 31st, 30th and so on. can anyone tell me where to look to read all about it. Thanks Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
pattern matching (in text field)
Hi all, I currently have $result = mysql_query ("SELECT title_id, title FROM documents_tbl, url_tbl WHERE (documents_tbl.title_id = url_tbl.url_id) AND keywords LIKE '%$temp%' AND title_id != '$myrow[title_id]'"); this works to an extent, but 'keywords' is a text field and if $temp is for example 'stem' I want it to match stem, and maybe stems but not system I thought keywords RLIKE '[\s|^]$temp%[\s|s|$]' this would allow for a word at the start , end, surrounded by whitespace, or plural. Obviously this does not work (why else would I ask you all?). Can anyone tell me what simple concept I have overlooked! thanks Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: site search
Thanks Kim and Georg, but I want to do this myself! Ok it may be hard, but i'm confident I have taught myself an awful lot by having a 'difficult' project on the go so, bearing that in mind, can I re-ask my question! thanks again incidently I am making a SITE search, not a web search engine Jules > > > Hi everyone, > > > > I want to build a MySQL site search. Can anyone help with my 'overview' > > > > I have written a perl programme to open each html file, cut out all the tags > > and create a hash of hashes each word is a key, then the secondary key is > > the filename, then the value is the number of occurances in that document. > > > > So how should I make my SQL tables? I thought a 2 column > > (filename:occurances) table for each word would be the best way, but thats A > > LOT of tables. I'd get perl to do all the writing, and I'm sure I could get > > it to work this way. > > > > But is this the best way? I'm fairly new to MySQL so please be explicit! > > > > thanks for your time > > > > Jules > > > > > > - > > Before posting, please check: > >http://www.mysql.com/manual.php (the manual) > >http://lists.mysql.com/ (the list archive) > > > > To request this thread, e-mail <[EMAIL PROTECTED]> > > To unsubscribe, e-mail <[EMAIL PROTECTED]> > > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
site search
Hi everyone, I want to build a MySQL site search. Can anyone help with my 'overview' I have written a perl programme to open each html file, cut out all the tags and create a hash of hashes each word is a key, then the secondary key is the filename, then the value is the number of occurances in that document. So how should I make my SQL tables? I thought a 2 column (filename:occurances) table for each word would be the best way, but thats A LOT of tables. I'd get perl to do all the writing, and I'm sure I could get it to work this way. But is this the best way? I'm fairly new to MySQL so please be explicit! thanks for your time Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
where
Hi, I have recently gained access to mysql (new isp), and am converting my old text databases to sql ones. I had a text database with a field 'keywords'. I have entered them as one field, What I want to do is submit a query where I can ask if this field CONTAINS rather than equals a string. Can you use regular expressions in this way? I want to have something like $result = mysql_query ("SELECT title, keywords, description FROM documents WHERE keywords='$word'"); but with keywords 'contains' '$word' a bit like keywords =~ m/$word/g in perl How would you all go about this? should I set my database up differently? Thanks very much! Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: date_format
Thanks this works the difference was the 'AS datefield' what is this bit doing? I searched for AS (in the SELECT description in my book) but it does not mention it; though I have seen it in examples. I like to understand why I use the code I do... I looked at http://www.mysql.com/ but can find no mention. Am I searching for the wrong thing? I searched for AS in the documentation thanks again Jules > > You may want to try: > > $result = mysql_query("SELECT title, description, url, author, > date_format(datefield, '%M %D %Y') AS datefield FROM documents"); > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
date_format
Hello, i'm new to mysql, so please bear with me... My database has a field called datafield as datetime. I want to display just the date #1 this works but gives the full datetime $result = mysql_query ("SELECT title, description, url, author, datefield FROM documents"); #2 All I have read on the web/books suggests that this is what to do $result = mysql_query ("SELECT title, description, url, author, date_format(datefield, %M %D %Y') FROM documents"); This just leaves out all dates. Can anyone see where I'm going wrong Thank you so much Jules - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php