Arrays, Queries, Birthdays, ...
I have this problem that I cant solve.
I have created an agenda (http://28edegem.scoutnet.be/agenda.php) . The
agenda contains events and birthdays of the members. I query the events and
birthdays per month and sort them on date.
This method works fine for the events since they are all for the same year
(eg 2003) but doesnt work for the birthdays because someone born in
1980-06-23 will be sorted before someone born in 1876-06-05 . This is a big
problem because the person born on the fifth day wont be echo'ed . The
problem can be easily be solved by only requesting the month and day part of
the birthday. I'm not sure this is possible?
If the above doesnt seem to work I can always order the array myself. How
can I access a query array? I guess I can't use the fetch_row ?
View Complete Forum Thread with Replies
Related Forum Messages:
Using Arrays In Queries
How would I make a query like: SELECT * FROM productid WHERE $arrayelements[] are in invoice num. What I want is all the invoicenum in the array to be in the selection.
View Replies !
Arrays For Queries
I have a set of queries that I use over and over across multiple pages. What I was wanting to do is set up an array and call the query from that array. Does this make since? Here is what I have. multiple pages where the queries are needing to be -1 page named queries.inc.php PHP Code: <?php echo $values['queries']['subs'];?> to show the query that I want in that location. I know how to use this to echo just plain text values but not queries.
View Replies !
Multiple Queries Or Sorting Arrays?
I have two tables, one with info about users, and one with gamestatistics. On one page I do four queries to these two tables and present it in four separate tables (ie table one - names and scored goals, sorted by goals desc; table two - names and played games, sorted by games desc ...). I would like to run one query instead and fetch all the data needed, and then sort the array four times in different orders. Can this be done, and if so, how? What's the most efficient way to do this, multiple queries or sorting an array?
View Replies !
Birthdays
In a MYSQL database I have stored when the members were born in the form "YYYYMMDD". Now I want a method to select every member who has birthday from today and up to 30 days into the future. I would prefer if this could be done in a MYSQL query. Can anyone tell me how to do this? I have figured out some solutions that will work, but unfortunately not in December because the year will turn.
View Replies !
Get Upcoming Birthdays
I have a column in a mysql table which is formated as 'date' called DOB. I want to create a query that will get all birthdays cumming up in the next ten days.
View Replies !
Send Me An Email Of Birthdays
I'm not sure how this would work automatically but I was wondering how I can send myself an email say 2 weeks before a member in my database is about to have a birthday? I'm assuming the query would need to be running constantly so would it be possible?
View Replies !
Display Birthdays Coming Up In The Next Couple Of Weeks?
I wonder if someone could help a novice to create a bit of code that will display birthdays coming up in the next couple of weeks? I have a mysql database with a date of birth(dob) date field but unsure how to check that field against the present date I only have at present, and don't knoe if this is right? while ($row = mysql_fetch_array($result2)) { $dob=$row["dob"]; list($year, $month, $day)= explode("-", $dob); $birth_day = "$day"; $birth_month = "$month"; $birth_year = "$year"; } Obviously I only need the day and month values but is there a pre built function to do this for me?
View Replies !
PostgreSQL Queries, Storing Results Instead Of Multiple Queries
I have a script that does multiple SQL queries. So I have something like $result = pg_query($my_query); After this query I tend to loop through like this to get the result: while ($entry=pg_fetch_row($result)) { //do stuff } But my question is, how can I make a copy of the result? So I don't run the query more than once.
View Replies !
Do Queries On XML Similar To The Way That You Do Queries On MYSQL And Then Use The Results.
I am fairly familiar with PHP and MYSQL and I know a little about XML. I would like to know if it is possible to do queries on XML similar to the way that you do queries on MYSQL and then use the results. An example of a simple PHP/MYSQL setup. <?php $user="username"; $host="sqlserver"; $password="password"; $database="database"; $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to the server"); $db = mysql_select_db($database,$connection) or die ("Couldn't connect to the server"); $query = "SELECT * FROM database WHERE(Criteria)"; $result = mysql_query($query) or die ("Couldn't execute query."); while ($row = mysql_fetch_array($result)) { extract($row); echo"Set of instructions to carry out for each row in the result"; } ?> The question is, is it possible to do similar things with PHP/XML? Lets say that I have an XML file located at a certain URL and I want to run a query on it and use the results. 1. Is it possible? 2. What is the easiest way to do it? 3. How would I translate the above code to work with XML? 4. Is ther resource on the web on how to structure the queries?
View Replies !
Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried. This is what my array looks like: array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" } This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s). I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation). I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:
View Replies !
Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for. so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase. say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.
View Replies !
Unset Arrays In Arrays.
Am trying to create a simplified - prototype shopping cart. There are three pages - first two are forms that get sent to the self page. You can read the description in the beginning comments ....
View Replies !
Sql-queries Within Sql-queries
Is there any way to put an sql-query into another sql-query and get it parsed as an array? I want to fetch an array from my db and the content should preferably hold another sql-query, is that possible?
View Replies !
Must I Use 2 Queries
Not having access to any mysql NG, I try to post here: I've a query where I'd like to get the different values, but also a max for 2 fields: SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick, articleid, articlename... but I get the errro: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause I don't understand what I've to group....
View Replies !
Db-queries
some little questions relating LAMP (PHP 4.3.4, MySQL 3.x, Apache): I'm trying to build a community website which needs many db-querys for lots of concurrent users. Therefore I'm always using: $ergebnis = mysql_query ($sql) or die (mysql_error()); while ($row = mysql_fetch_array($ergebnis)) { $myvar = $row['column_xy']; } Is there a limit for db-connections under MySQL3.x? What happens if hundreds of users are accessing these pages simultaneously? I heard MySQL breaks down if there are more than 200 users!? Is there a better/more efficient way for the db-queries under PHP4? How efficient would it be to write all possible db-results into session-variables in order to keep the number of queries low? What about performance using many session-variables?
View Replies !
Using OR In SQL Queries?
I am trying to select data from a database that does not match two values eg: "SELECT * FROM table WHERE reason != 'reason1' OR 'reason2'"; so if there were 5 reasons, it would show all data matching reason3, reason4 and reason5 however....when i have done this its only using the first one because its including the other in the results count. What am i doing wrong?
View Replies !
If Queries
so i have the followng if query but it doesnt seem to be working. Basically i want to check to see if they person is at one of 2 places by checking the co_ord_y and co_ord_x. <?php if ($town == '1') { if ($co_ord_y != '14' && $co_ord_x != '20' || $co_ord_y != '19' && $co_ord_x != '15') { echo "You are no longer near a river."; DIE(); } } ?> Well everytime i get to one of the coords it throws the "You are no longer near a river."
View Replies !
Keep Queries
I have a web app I'm working on and I am wondering what all of you do for SQL queries and where you store them. I am using PHPs PDO class and currently am building on a MySQL backend. I have many queries that I will run at different sections of my code. I want to keep everything centralized (the queries) but am unsure (design wise) where to store them. I was thinking of putting all of the queries in an associative array so that they could be accessed by their name such as: $sql = array('GET_ALL_USERS' => 'SELECT * FROM users', 'SELECT_USER' => 'SELECT * FROM users WHERE id = ?'); Is there a better practiced way I should go about?
View Replies !
Cut Down On DB Queries
I have a table. five rows by 30/31 days. Each cell has a status level which it gets from a database. My current script works, but it queries the database to see the status of each cell So that means every time a month is displayed, it makes about 150 queries to the database. Is that bad/unacceptable? It's currently like this $rows = array('1','2','3','4','5'); foreach ($rows as $row) { for ($day=0;$day<$DaysinMonth;$day++) { $res = mysql_fetch_array(mysql_query("SELECT ... WHERE `row` = $row AND `day` = $day)); if ($res['level'] == 1) { do something } else if ($res['level'] == 2) { do something else } Is there a better way to structure this to cut down on queries? Or is it not an issue?
View Replies !
Two Queries Become One
I have my code which is a monthly archive, it first reads out the month and year and then it reads out all the entries from that month and year below it and then repeats. The code works fine and does the job, but I'm using two queries and was wondering how I would go about combining them?
View Replies !
Odd Queries
I recently came across some queries embedding in an address bar which I cannot identify. The page's url was "/index.php/Home". I haven't actually noticed these type of URLs before. I tried to use them in my PHP pages, however if I do, all my linked element no longer appear. I don't know anything about these types of urls.
View Replies !
Sub Queries
i have an insert query that puts data into a ticket table. but before i insert the data i want to get an id number from a different table based on a choice that was made in the form. Code:
View Replies !
Sql Queries
I have some general questions about MySQL and PHP, but really just MySQL. I'm trying to create a query, but I dont have any idea where to start. Actually, I know how to create simple query, but this one is more detailed and complex. Table Name: Story Table Columns: user_id, date, name, yrleft, cityfrom, countryfrom, yrcame, citycame, statecame, address, city, state, zip, AorV (audio or video), filename, instructor_approved I need to create two queries. One based on date in descending order, and one based on countryfrom in alphabetical order. For both of these queries, the instructor_approved field has to = Y for yes, and when I return results I need it to return everything in the table EXCEPT for the name.
View Replies !
Search Queries Help.....
Hello there I was wondering if I could possibly get some help./ I know basically what I want to acheive, but trying to work out the best way of getting there. I currently have a music database that I do not allow duplicate entries on artists name in.... But there is always the possibilty of mis spelling their name etc etc. Is there a way that I can perform a query to find all entries in database sort by relevance and pick the top result as the one they should have? Example:- If the user imputs :-blue dirt or dirt,blue But the correct Spelling for this one is actually :Blue Dirt How would I go about checking the entered data against the correct in more of a "Sounds Like" search envirnment?? any help or suggestions would be greatly appreciated.....
View Replies !
How To Reduce SQL Queries?
I know there's a way, but how do I reduce this script into one sql query? <? $dbcnx = mysql_connect('localhost','dbname','pass'); mysql_select_db('dbname'); $sql = mysql_query("SELECT ID FROM jokes ORDER BY rand() LIMIT 1") or die(mysql_error()); $result = mysql_fetch_array($sql); extract($result); $sql = mysql_query("SELECT joke FROM jokes WHERE ID='$ID'") or die(mysql_error()); $result = mysql_fetch_array($sql); extract($result); $sql = mysql_query("SELECT joketype FROM jokes WHERE ID='$ID'") or die(mysql_error()); $result = mysql_fetch_array($sql); extract($result); $sql = mysql_query("SELECT joketitle FROM jokes WHERE ID='$ID'") or die(mysql_error()); $result = mysql_fetch_array($sql); extract($result); ?>
View Replies !
Using MySQL Sub Queries In PHP CLI
I am using a sub query like the following in a cron file and its throwing a query error. ...eexpiry = (CURDATE() + INTERVAL (SELECT alert2 FROM settings) DAY)... Does that mean I cant use sub queries in PHP CLI?
View Replies !
Multiple Queries
I've made a database where I store facts from soccer matches. Every match report is stored with a unique id and the month of the year the game was played (I use date("my"). Each report is also given a "match code" wich tells what tournament the match was played in. I whant to display a complete list of all the matches played this season, wich month and wich tournament the matches took place in. So the question is; Is it possible to use a single query to get this information? My idea was to do a query on the "match code" and the month the game was played, but that did not work. Should i rather use the actual date the game was played? Could anyone give me an example of the query i'm looking for? Example: List all matches played in Premier League the month of august.
View Replies !
Multiple SQL Queries Under PHP
Im running multiple sql statements to bring in data from 3 tables in a single database. My first two sets of queries accesses the correct tables and returns the data to its correct position within the HTML document. Building the 3rd query though has given me an err about mysql_fetch_assoc(): Supplied argument is not a valid MySql Result Resource in (Page Location) - Now im assuming I should be using subqueries to compile my statements but im not sure how to bring them together. Here are my first two queries in order followed by the 3rd one that does not work.
View Replies !
Array Queries
in my project i'm go through diffrent parts of my sql tables and determining if a element is there or not. if the element is there then it'll add the ID of the row to an array: if($track != "default"){ $track_query = "SELECT id FROM music WHERE track = '$track'"; $track_result = mysql_query($track_query) or die(mysql_error()); while($row=mysql_fetch_array($track_result)){ $id = $row["id"]; //get the id of the row $tally_array1[] = $id; //put the id into the array}} what i'm hopeing i can do is once i've finished all my queries, the array will be full of duplicate id's and i'll be able to count how many times each diffrent ID occurs in the array, then extract each ID from the array in ascending order of occurance.i've tried to use print_r(array_count_values($tally_array1)); print_r(serialize($tally_array1)); but other than getting them to print to the screen i can't use them. I'd like to be able to parse things into variables.
View Replies !
Queries, Functions
i am getting one of those 'mysql_fetch_object(): supplied argument is not a valid MySQL result resource' errors with the following code. the query is valid, because if i echo itself outside the function it prints the results, but if i call the function i get the error. here's the code on my php file. PHP Code:
View Replies !
Sending SQL Queries
I see in a lot of documentation that a "proper" way to send a query to MySQL via PHP to return data to a website is something like the following format: Code: $query = "SELECT * FROM Pet"; $result = mysql_query($query); My question is, why make the query its own variable if you're just going to use it in the next line anyway, and assumingly you'll be making lots of different kinds of queries? Couldn't you just use something like: Code: $query = mysql_query("SELECT * FROM Pet"); And have a lot less code involved? I'm new to PHP/MySQL, so I'm just trying to figure out the best way to do things... but the former example doesn't seem to make too much sense to me - yet I see it used all over the place. Any tips?
View Replies !
NuSoap Queries
I'm new to using these classes, and have set up a simple ldap authentication server using it. I'm trying to extend this, but think I've come up with a bit of a problem, as I'm trying to pass a multi dimensional associative array across as a parameter. Can one of you guru's tell me... 1. Is this a problem, and 2. is there a way around it?
View Replies !
Php/mysql Queries
I finally got my totals to work for this survey, but now the queries are killing the database. With only 14 submissions to the database it takes 10 sec to query the whole thing. 100 survey submissions didn't even load after 5 min. How can I economize my queries? PHP Code:
View Replies !
Queries Outside Loops?
It was suggested to me that to speed up some code I have for a multiple select box that I place my queries outside my loops. I can't say I have the foggiest clue on how to do that. My original code looked like: PHP Code:
View Replies !
Objects And Queries
I have tried to join 4 tables with a SQL line and fetch the data as a object while($edit = mysql_fetch_object($result)) My problem is this, I need to lable a object somthing like this $edit->products.id but it doesn't seem to work very well the printed result is .id any suggestions?
View Replies !
Optimizing SQL Queries
I currently have a DB with several rows of submitted items in it. There are several items per user, but I am only interested in getting the first 3 for each user. The script from the previous coder calls each query seperately, but this is hard to maintain and I was hoping I could put this all in a single SQL statement instead. Right now the script queries for 3 rows from user #1 and stores in array, then calls for next 3 from user #2 and stores in array etc etc. I'm looking for a SQL statement like so: $sql = "SELECT first 3 items for each UNIQUE user ORDER BY date_added ASC"; (yes, sql is wrong, its just an example to show what I want!) I really hope this is possible, it would really cut down a lot of redundant code we have now. I did look at MySQL site and PHP site, but could not find anything that looked like it would do the trick.
View Replies !
Table With 3 Queries
I´m stuck with a problem I have to make a table with the information of three different queries. The table has 4 columns x n rows. The first and second columns must be filled with the result of the first query, the third, with the result of the second query and the fourth with the result of the third query. All queries has the same number of results and the count(result) > 1 I made different combinations of while's but no one seems to work.
View Replies !
Multiple Queries With PDO
I want to issue multiple queries in my script using PDO. All of of these queries will either retrieve one row with multiple columns or one row with one column, so I am using either fetch or fetchColumn to get the data. Now, I ran into an error message telling me: "General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll()." If there is only one row being retrieved (and I know this for sure), how is it that unbuffered queries are still active? And whats the most effective way to get around this? I can use fetchAll or loop with fetchColumn or call PDOStatement->closeCursor(); after each query data retrieval statement.
View Replies !
Using Variables In My Queries
I am having problems using variables in my my sql queries, and i dont know what im doing wrong. This works //Database Connection $query = "UPDATE INTO TABLE <table> WHERE id='102441019' SET color ='FFFF00'"; But the same thing using a variable does not //Database Connection $1="FFFF00"; $query = "UPDATE INTO TABLE <table> WHERE id='102441019' SET color ='$1'";
View Replies !
Sessions And Queries
I have a query that is returning results. the results are then posted on the page. Each result is different from each other. Next to each result, i want to place a button, that when clicked, will carry some of the fields from that specific result to another form,(on a different page/script) where some actions will be performed. Im thinking the best way to do this is to use sessions. How would i go about issuing a session variable to each result, and when that button is clicked, carry that 1 specific session over to the form, where i can carry on happy as Larry. Could i do example: While (there is data){ Post results variable = field(s) session['variable'] Link to new page}
View Replies !
Combine Queries
I was wondering how I would combine queries that are stored in an array? The reason is to be able to order the multiple queries from the same "ORDER BY" which will be obtained from an url parameter. Also, the reasons the queries are in an array is, because they use the "WHERE" clause to SELECT "WHERE year = '$year'", and there could be several years (the years are obtained from $_POST) and I don't think there is a way to do something like: WHERE year = '$year[0],$year[1]'.
View Replies !
Using Includes For Queries
I have two queries that I will be running at the top of each page on my site once the user is logged in to pull in different information about them and to show the company's information. Would I be better off having these at the top of each page in the code or having them in includes and calling the includes?
View Replies !
Combining Queries
I am trying to figure out if there is anyway to combine the 2 queries in my code. In the second query, I want to insert the businesses_id I retrieve from the first query into the table. Is there any way to select businesses_id and insert it with a text field in the form in one query? Code:
View Replies !
Database Queries
mysql_query("SELECT * FROM member WHERE name='$name'") or die(mysql_error()); Is a database search case-sensitive in the "WHERE name='$name'" part?
View Replies !
Joining Queries
I have been trying to figure out. I am writing a script to go along with some forums. basically I want to get a post and then do a LIKE search for a certain string in all other posts that are not in that topic or several other forums that are on the board here is what I got so far. Code:
View Replies !
Sum, Two Queries, Same Table
It's me with the funfair database again! Having more issues. Basically I am trying to create a 'daily report' page, where it shows the rides we have ridden today, and how many times we've ridden those specific rides to date, showing something like this: Day Four Big Wheel: 3 (4) Ghost Train: 5 (10) Table is currently set up like this: rides_id | rides_date | rides_one | rides_two | rides_three | rides_four | rides_five This is the code for the ridecount.php page, and everything works exactly how it should. The $rideid and $ridename are there so that I can use the same calling pages (get_rides_today.php and get_rides_total.php without having to have a different page for each ride) Code:
View Replies !
Timeout Queries
Is there a way with php/mysql to have a set timeout period for queries. My hosting provider is complaining about to many processes when my pages connect to my db. Sometimes they take a few minutes to complete and I want to just stop anything that is taking more than say 30 secs. Is there a way to do this. The php execution time is set to 30 secs. I thought that would do it but isn't. The mysql server is on another system from the php server also if that helps.
View Replies !
Running Queries
I have NO basic knowledge of PHP MySQL - Im good at dreamweaver and designing but im no good with this - I have to build a database for a Hotel that allows people to register and book rooms etc, however I can type it all in, Its just the connection from 'getting' the information from the Database to the HTML side.
View Replies !
|