Advanced Mysql Query
There are currently two queries in one of my scripts. One is:
SELECT * FROM foo
the other is:
SELECT var FROM bar WHERE something = 'somethingelse'
Is is possible to use a join statement and combine these two into one query? My reason is that I'm trying to speed up the script, and hopefully combining the queries will do that.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
MySQL Advanced Query Woes
I'm trying to figure how to begin on this. I have a mySQL db with a number assigned with user_id. There are multiple records for each user_id with different numbers. I can retrieve all the records or select by user_id and add the results. How do I grab all the records, sort by user_id, add the numbers while user_id = user_id, and sort the results from highest to lowest?
Advanced Search With Relevance Using Php And Mysql
I am working on a classifieds site that allows users to search for ads using many options. For example in the rentals area the user can select how many bedrooms, bathrooms, if pets are allowed, etc. There are currently 9 fields that i am allowing them to search on. I already found a great class on this forum that will make the dynamic mysql select statment, but i was unable to find much info on relevance displaying the best matching result first and the second best second and so on. I found a couple of tutorials but they were talking about matching a single word and the only relevance was that they were listing results higher depending on which result has the search string the most times. What i am trying to do is order relevance by having the top match be the one that matches closest to the 9 selections the user entered. So i would want any exact matches of all 9 fields at the top and then the list of matches would get less and less exact as you go farther down into the results. My initial thought was to make more than one mysql select, having the first select match all the searched fields exactly, and then the next select would do the same thing except one of the fields would be changed to find all of that one field that are not equal to what the user entered. example: PHP Code:
PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work... thank you for your reply. $today= date("Y-m-d"); $qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'"; $result_6 = mysql_query ("$qq"); if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY $qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(Ƈ',Ƈ',Ƈ',Ƈ',Ƈ','$today')"; $result_6_2 = mysql_query ("$qq_2"); if (!$result_6_2){ $err_msg_sql_6= mysql_error(); $err_loc_6="$PHP_SELF"." // Query6: update totals_r"; } }
PHP Saying Error In Mysql Syntax, But Written My Mysql Query Browser!
I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>function.extract]: First argument should be an array in functions.inc.php on line 31 Notice: Undefined variable: price in functions.inc.php on line 36 Notice: Undefined variable: price in functions.inc.php on line 39 Notice: Undefined variable: total in unctions.inc.php on line 39 I'm assuming the last three are caused by this problem as price should be passed to the cart, and total is worked out using it. However although I know mySQL code it was the MySQL query browser that actually generated the code and I cannot see a way to view or debug the code. The db has one table in it which is made up of id, name, subname, desc, and price. The code in the php file that is being referred to is:
Advanced Regex Help
having a few problems with a script im developing for www.cockneyizer.com the script translates websites into cockney rhyming slang, ive got the translation bit working but grabbing images of the server isnt flawless, in addition, sometimes links dont get converted to link back to the cockneyizer translation url heres the code, if you have any ideas of how to make it work better please <?PHP // remove cockneyizer translate url from $file $file = str_replace("http://www.cockneyizer.com/translate/.php?file=", "", $file); if (!eregi("http://", $file)) { echo "Please enter a valid URL (missing http://)"; } else { $fp = @fopen("$file","r"); if (!$fp) { echo "Core Blimey, no such page mate"; } else { $input = implode("", file($file)); include('dictionary.inc.php'); while(list($text,$image) = each($replace)){ $input = str_replace(strtolower($text), strtolower($image), strtolower($input)); } $input = preg_replace("/name=movie value=(["'])(([a-zA-Z0-9/.-\_^'^"])+)(["'])/", "name=movie value=1$file/24", $input); //flash $input = preg_replace("/src=(["'])(([a-zA-Z0-9/.-\_^'^"])+)(["'])/", "src=1$file/24", $input); //images $input = str_replace("'//", "'/", $input); $input = preg_replace("/background=(["'])(([a-zA-Z0-9/.-\_^'^"])+)(["'])/", "background=1$file/24", $input); // background images $input = str_replace("'//", "'/", $input); $input = preg_replace("/([^w/])(www.[a-z0-9-]+.[a-z0-9-]+)/i","$1http://$2", $input); //make sure there is an http:// on all URLs $input = preg_replace("/href=(["'])([w]+://[w-?&;#~=./@]+[w/])/i","href=" http://www.cockneyizer.com/translate.php?file=2", $input); //make all URLs links $input = str_replace("'//", "'/", $input); echo $input; } } ?>
Advanced PHP Debugger
We 've installed ADP. But I have a problem. All generated trace file are empty (only 1 byte). Any idea what the reason could be ? Right/Permission issue ? I'm not sure cause the file is created without any problems.
Advanced PHP Graphs
I have to create graphs which you can zoom into and have more controls. I dont want to use a Java Applet and would love to use PHp and any of its library. I guess such thing can be done with PHP and Flash and/or Javascript etc. Please guide me. A point to a tutorial or an example will be highly appreciated.
Advanced Php Counter
I am looking for a advanced php counter. I mean not to increase when I hit 'Refresh' button of the browser and NOT to use SQL database. All the PHP counters I found on the web use a text file that is modified (open, and increase value of the content) when the 'index.htm' is requested by browser (and of course if I request twice from the same browser, same machine it will increase).
Advanced OO Topic
I notice a strange behavior in PHP4 and wonder if anyone can explain it. Essentially, when I extend a class from a built-in module, I can add and access variables but can not access new functions I create within the extended class. This has only happened attempting to extend classes from ming, but I suspect it may be a universal problem (?). That is: <?PHP class foo { } class bar extends foo { function bar() { print "bar"; } } $bar = new bar(); $bar->bar(); //PRINTS "bar" ?> Works as expected, however, in: <?PHP class foo extends SWFSprite { var $x = 10; function bar() { print "bar"; } } ?> running: <?PHP $foo = new foo(); print $foo->x; //WORKS; PRINTS "10" $foo->bar(); //RETURNS "Undefined Function" FATAL ERROR ?> Can anyone explain this behavior? Will it be fixed in PHP5? Is it related to the Zend engine? Any workarounds?
Advanced PHP Pagination
Is there anyone who could help me create an advanced pagination code? The basic: 1. Data to paginate will be coming from msyql database. 2. 10 or 20 items per page. etc, etc... The problem: Limit the number of page numbers to 5 when pages reach more than 5 pages. Example: Total pages: 10 sample page listing output: start of pagination 1.) << 1 2 3 4 5 >> displayed when last page number is clicked (5) on start of pagination 2.) << 3 4 5 6 7 >>
Advanced Search
Im looking to do one of the more advanced searches where you have a form you can narrow the search by username, user type, date entered, etc. Everywhere I've looked all I can find is the basic searches. Can someone point me in the right direction or show me some code.
Advanced Form
I don't know how it's called, but I want to ask how to make a form which able us to make bold, quote, link or change font color by using [].. like in this forum.
File Uploads - Advanced
Is is possible to tell the OS what type of file to browse for? By default the 'Files of type' is 'All Files *.*' I'd like to set this so that it defaults to JPG file types.
Advanced E-mail Action.
I want to include a reference number from a table in an e-mail. Would I just query the database and have this code, PHP Code:
Email Validation (advanced)
so i know this can be done and i'm pretty sure PHP can do it, i'm just not sure if i need to set up a cron or something. I need a way to be able to send out emails when someone subscribes to a service (this i know how to do) and then when they recieve the email they need to respond to it, then when i recieve their response, their membership is confirmed.
Upgrading Php On WIN 2000 Advanced
I am currently using php 4.04 on a WIN 2000 advanced server and I want to upgrade. I downloaded the win32 4.3 installer and think its just a matter of running the installer to complete the process. Is there anything else I need to configure (besides the php.ini) to keep my existing scripts running correctly? I am running multiple sites on one domain so I don't want to screw up the upgrade and cause any downtime.
Advanced Search Replace
im developing a script which grabs remote html files and shows them on the local server, ive written some code which changes the path of image files to point to the files on the remote server, this code can be seen below: Code:
Advanced Dropdown Menu
I want to populate a dropdown menu with countries that are in one column of my table. I know how to do that, but I can't find how to eliminate multiple items. Some countries appear several times in different rows, but I only want each available country to be shown once in my dropdown list.
Advanced Email Validation
I need a script which checks if an email address exists. I've been testing a few scripts, but all of them only validates the domain, for example, the script says this email exists; foo_this_email_does_not_exist_123456789@hotmail.com Just because the domain exists. For example, Is it possible to check if the foo_this_email_does_not_exist_123456789 account exists on Hotmail's server? Or foo_account at usa.net's server?
Advanced Registration Forms
I'm trying to design a registration form so that when the user fills the form fields if he made a mistake i.e (forgot to fill the last name field) and then returned back to the form page he finds all the fields he has filled existing only the one with the mistake highlighted. So is there a way to design such a form using php?
Advanced Form Jiggerypokery?
Can any of you mySQL/PHP masters help me? What I wish to do is have a piece of text saying 'You have already filled out this form' when a user has previously filled out a form and submitted it. Our site (http://www.pickawin.net) uses quite a few forms and users have requested the functionality to be notified if they have already filled out a certain form on the site.. It is a PHP-fusion installation, using a mySQL DB. I understand it would require (something like) the form, once filled out and submitted, to create an entry against the user's name in the mySQL DB and the an entry for the form they have just filled out - then when the user goes back to the page, for a bit of script to be called to show whether they have prevously filled out this form or not.
Advanced XMLHttpRequest Usage
Please understand that I know how to code in both javascript and PHP and know how to use AJAX very well. I have an entire scheduling system set up with employee management and shift requests using the XMLHTTPRequest object. That said, here is my question/dilemma: Within said scheduling system, I have a span that is filled using the xmlhttprequest object. That span, once filled, is able to call javascript functions from the parent document (i.e. the page that is loaded into the span can call functions in the page that contains the span). However, if I would like to be able to access objects within the AJAX loaded span. Is there a way to do this? A specific basic example: page1.php contains a span with id="test_span" page2.php contains a table, with a cell that has an id='cell1' page2.php is loaded into test_span using AJAX page1 calls a javascript function that uses "document.getElementById('cell1') and changes its color...nothing happens (no javascript errors either)
PHP Mail And WIN2k Advanced Server
I am running Win2k Advanced server and php and I am having trouble getting the mail function to work. I have modified my php.ini file to reflect the SMTP server name but when I run my php program that uses the mail ( ) function I get the following error: Warning: Failed to Connect in C:pathsubmit.php on line 33. Anyone know what I need to do here to get this to work? I am not currently using the default WIN SMTP server. I know the smtp server name is correct and I can telnet to the server port 25 from the outside. I either get a "failed to receive" or "failed to connect" issue. Is this a firewall issue? Are there any other ports that need to be open for the mail function to work?
Advanced Search Template -- About Programming.
I know nothing about programming but I am building a website (written with php) that allow people post some info. Is there a site I can get some templates or php scripts for an advanced search function? The Advanced Search function shall able to search any posted info by a postal code/zip code within certain kms and be able to search by map by clicking to US/Canada map to get to state, then to cities than to towns....
Super Advanced Max Array Function
i'm out here looking for a super fast function to find the max in an array. iterating through the entire array is just too slow. the max function won't work either because my arrays look like this: array( array(price1, item_id1, quantity1), array(price2, item_id2, quantity2), array(price3, item_id3, quantity3)) i'm trying to find the highest price...anybody have any genius ideas?
Advanced Search - Listing Multiple Results
I created a seach function to search a database and retrieve the information based on the input. However only the first matching result is shown. The code is working fine but i want to show every matching result, one after another. Therefore, for example, if the user types into "country" the word "USA" every event will be shown. I have included the code i have used so far. Code:
Advanced Email / Excel Spreadsheet Writer
I have to run a script that generates a report into an excel document then emails the document simultaneous to the user with the spreadsheet attached! Although it needs to write a document for each users specific details in the database and mail that user his specific spreadsheet with his details in! Heres a sample of what im trying to do. Code:
Query MySql Using PHP
I've created my first search form and it seems everything is working pretty well. However, since I am very novice in scripting in general, I'm having one problem that I can't seem to unearth an answer to. Perhaps someone could easily offer the answer: my query asks to select a 2 char state code or a 5 digit zip code in order to obtain results desired. In testing, if I enter a state code, it brings up only the state requested. However, when I enter a zipcode, I get the wrong results. I'm sure its the "LIKE" that is throwing this off. Here is the query portion of the script: $result = mysql_query ("SELECT * FROM fish_dealers WHERE Zip = ´$Zip%´ OR State LIKE ´$State%´ "); Can anyone give me a clue?
Mysql Query
I have wrote a Select statement, that checks if the user and password and returns a value, however can i add something to the statement that would allow me to get the userID from the table users, so that i can write the value to a cookie, is it possible. PHP Code:
MySQL Query
I want to have a field where I store a list of what categories that particular row falls under, I don't know which format to do or how I would query it. For example, row1 might belong to categories 1, 3 & 7 - I'd want to be able to query all rows belonging to 3 and get row1.
AND And OR In MySQL Query
I've build a query from a php form where people van select more results for a cell wich can only contain one value Here's my query: SELECT * FROM person WHERE color_eye = ('brown') OR color_eye = ('black') AND color_hair = ('Blonde') Everything after the "OR" will be ingnored. So how can I tell MySQL I want all the brown and blacked eye?? Without the AND it works fine, but in real the query is way longer with multiple AND's.
Mysql Query
I have a code that installs some tables into a mysql database. Heres the code, but it keeps coming up with the error "Install failed (ID 1)" I have tried tons of things, even looking at other installers and mimicking them, but nothing. PHP Code:
Php/mysql Query
I want to display the users name on the pages when they have logged into my site. i have done it one way that is to take what they type in the login form and post it on the page and that works fine. only one problem and its more of a preference than a problem but the way i did it takes exactly what they type say "username" and posts that so if they type "UsErNaMe" it will post it like that. i want to show the name exactly as they make it when signing up. im guessing i have to query the data base... mine being MYsql. PHP Code:
Mysql Query
How can I get rownum using MySQL queries , In Oracle one can you in this way SELECT rownum as srno, fname FROM tablename suppose If there are 45 records and if i use while for the srno should display 1, 2, 3, ... 45 query like SELECT rownum as srno, fname FROM tablename I dont want to use php counter, i want it from query
Mysql Query
I'm running a sports pool and I'm trying to display stats from the results of the picks. The table is 'results' and the fields are 'pick_number', 'game_number', 'user_id', 'points' and 'date' There is one record for each users' pick. 0 points are given for a loss and 1-4 points are given for a win. I've already created a query that gives me the top players by overall points but I'd like to expand that to include the number of points won just this week, overall winning % and winning % this week. Can I do this in one query and then display in an HTML table? $query = "SELECT user_id, SUM(points) AS points FROM results GROUP BY user_id ORDER BY points DESC";
Mysql Query
1) i have a database divinelive_messages table with a sessid column 2) i need to find out rows from the database, which only show that sessid in there once.
Mysql Query With * And +
im trying to return all results that come from or went to certain extensions on our phone logging system but i don't want to return any that have a src or dst that contain a * or a +. This is the where statement i have that is not working Code:
Getting MySQL Query
I took some info out of my database. I want to display an error page if their are no rows in the database. How would I go about doing that. I have this: $query = I execute my query here. Taken it out so you don't connect to my database Muahahahhaah $row = mysql_fetch_row($query) if ($row == '') { echo 'Their is nothing in the database!'; }else{ echo 'Yes, the database does home info in it.';} What would I put to make this work?
MySQL Query
Whats wrong with this query: SELECT from, subject, message, time FROM user_messages WHERE username='$username' ORDER BY timestamp DESC I get this error: QuoteYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, subject, message, time FROM user_messages WHERE username='Drezard' ORDER B' at line 1
MySql Query
I'm having some difficulty formulating query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field. My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng) Here is my code:
Need Help With Basic Php Mysql Query
$z = "goodBMW"; the word goodBMW is no where to be found in in the table times. but it will echo every single row thats in that table and it doesend sort between Group 1 and Group 2 where the hell is my query wrong.
Problematic MySQL Query
Would anyone be able to help me with the following MySQL problem. I am trying to extract all of the users who are not on vacation for a given date. I am using a NOT IN statement, however, I need to have a more advanced query than a simple one. What I need to do is as follows SELECT users.user_id,...
MySQL Query Quandry
I have a simple need to go into a 4 column table and based on the content of the first 3 print the content of the 4th. In other words if column1 = a, column2 = b, and column3 = c then print "dog" from column4. This will be the action for a short form that allows the user to make 3 choices that will determine a link. I have this from another script that I'm trying to modify: mysql_select_db('search_links'); $query = "select * from links "; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo '<p>Number of books found: '.$num_results.'</p>' for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo '<p><strong>'.($i+1).'. Title: ' echo htmlspecialchars(stripslashes($row['type_prop'])); echo '</strong><br />Author: ' echo stripslashes($row['area_code']); echo '<br />ISBN: ' echo stripslashes($row['price_range']); echo '<br />Price: ' echo stripslashes($row['saved_link']); echo '</p>' } The above query prints the entire table and I would like a query that limits to the form choices indicated above.
PHP: MySQL UPDATE Query
I need to have a page where the user can update his info and/or delete his record. I haven't tested the DELETE query yet. When I open the page it shows all the info stored in the database. When I change something and hit the update button I get the message that the record was successfully updated, but nothing really hapens. If you want to see what's happening go to URL , click on the 'directory' link The user ID is 'scooby', and password 'dooby'. If it does not work, try the following combination: user ID: 'sunny', password: 'trout' . Then click on the 'edit profile' link and try to change something and see what happens. I am attaching a php file of the 'edit profile' page, the one I am having trouble with so you can see the entire code.
Mysql Date Query
I need to check if one script was run later than one hour ago - I had a problem with cron and want to put in a safety code. On successful running of the script I remember the date in db CREATE TABLE log(id INT NOT NULL auto_increment, ttime DATETIME, other_info TEXT, PRIMARY KEY(id)); The sql query that I use now is: SELECT HOUR(CURDATE() - ttime) as h FROM log ORDER BY h LIMIT 1; However I have a problem - it returns sometimes value NULL (which is always first). If I use the following syntax: SELECT HOUR(CURDATE() - ttime) as h FROM log WHERE h IS NOT NULL ORDER BY h LIMIT 1; I get the error: Unknown column `h` in `where clause`. What can I do?
Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets if values from a form with combo box's in. SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY $thesearchtype_search. Everything works fine except I want to add a select "any" from the shape combo box. I really need a way of cutting out the last " AND hottubs.shape = '%s' " if the $_GET['shape'] = 'any' Will this work using a variable as shown below?? IF ($_GET['shape'] != 'any' ) { $shape = AND hottubs.shape = '%s' } SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search I have only been doing php about a month so go gentle!
MySQL Query On The Same Page.
here it is: i have a table with lets say 2 fields, first_name and last_name. When user enters index.php he gets database records sort by first_name (ORDER BY first_name). Now i ave made two links above those records. They are: sortb by firts name and sort by last_name. My question is, what code should be written for the link sort by last name if i wanna show the same records already displayed but sorted by last_name??? And how do i make that if user has clicked sort by last name that thislink is disabled (not underlined, just bold text) and if he clicks on sort by first name that this link becomes text.
|