Query Result Navigator Function
I've just updated this, and I thought I'd also say that not only can this provide a page navigation for MySQL or other database results, but can be used to navigate other lists.. such as a file list. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes. Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:
Using Query Result To Do Another Query In Loop
I have 2 tables, one called users2 and one called books. Books has a field called UserId, which is the ID of the user that added the book to the database. My problem, is that i need to take this ID from the book table, and use it to get some information from the user table. Here is my code to get the ID from the book table: Code:
Linked Result From A Query
I'm trying to create a query that will return a linked record from a database that will take me back to an update page with that record so I can change things in the record. I'm having trouble finding simple code to do this.
Echo A $result Of Query?
Trying to have an echo display a result from a query. Not such a hard concept. Yet I am having trouble. What good is the data without analysis. Here is what I am using to try and grab result. Have been told it looks correct, must be missing something small. When this runs, alternate echo displays in browser. So you know: 'testdata' is the table 'score' & 'id' are columns or fields. Almost think it is missing a table structure to display in. Looking for player name column and score column (for the sake of example). Code:
Paging Of Query Result
This script used to be working in splitting query result into pages. But now, PREV 1 2 3 4 NEXT links is not working anymore. Any idea how to fix this ? or what is wrong with this script ? Code:
Limit Query Result According To A Criteria
I have the following code which doesn't work: "SELECT COUNT(*) AS total FROM $table_name WHERE certain criteria HAVING total<=100"; The query above doesn't work and i get zero results. In general the query take lots of time mainly because the criteria is not specific enougth and I get many many hits. I want to stop the query after getting the first 100 hits according to a certain criteria. When I use LIMIT 0,100 and not HAVING i get result from the first 100 records in the table but my table contain few million records.
Easiest Way To Print The Result Of A Query
I am using the following code: $host =""; $username=""; $password=""; $database="123"; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT SUM(rcountry) FROM 123 WHERE sessid = '$PHPSESSID'"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); Whats the easiest way to print the results of the query? I just need the value returned by this section: $query="SELECT SUM(rcountry) FROM 123 WHERE sessid = '$PHPSESSID'"; I will be using the value in a mathmatical problem later on, but for now I just want to print it out and I am unsure as to which variable to echo.
Variable Interpolation From Sql Query Result
I have data in a MySQL table like: the variable is: $var and an assignment in a file like: $var = "some text"; but when I print the output of a query for the data it prints: the variable is: $var rather than: the variable is: some text
Multiple Result Sets With One Query
I need to query the DB and find records that coorespond to a given month and then display the data. $sql="select * from $tbl where month='january'"; ....... through december My question is this -> is it better to create 12 different queries or create one query and use an array (or somethiing else) to create basically 12 result sets? To me - 12 queries seems like it would be taxing on the db.
Same Mysql Query Doesn't Always Return A Result
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query doesn't return any result. We have tried on our server and we always get a result. BUT, trying on the hosting server, many times the query doesn't return any result and doesn't get any error. Any idea ? does Union have any problem ? how to check if the query failed ? My hoster said that sometimes the table can be locked (if the server is overloaded) and then mysql doesn't return any result, but this seems to me an aberration. the query takes about 0.0050 sec to execute when it doesn't return any result, and 0.030 when I get results
Moving A Query Result Into An Array
I have read all the array stuff done searches for examples, but am still not clear if there is a way to do a query from a MySQL table and move those vaules into an arry. I am sure it can be done, but I thought I would find a function that would do it. Am I just overlooking something? $resultID = mysql_query("SELECT DISTINCT slot FROM items"); while(list ($slot) = mysql_fetch_row($resultID)){echo"$slot";} So anyone have a good way to move the result into some array?
Strange Result From Table Query
I have a simple query that I am restricting to the first 4 character, however instead of the first 4 characters I am getting only the characters from the end of the field. The information in the field resembles: 4285-002 My result should be: 4285 What I am getting is: -002 The following is the code to pull the dat from field 'Dest': $dest=odbc_result($rs1, 'Destination'); $deststrcount=1; $deststr = $dest; $deststr = str_split($deststr,4); foreach($deststr as $destv){ if ($deststrcount<="1"){ $desttext=$destv; $destnew = "DEST[1,$deststrcount] $desttext"; $strcount=$strcount+1; }
Query Giving Array As Result
I just started PHP and getting the following error when trying to read and echo something from my DB. I get Array as an result of a working SQL query (I tested it in PHPMyAdmin SQL Query) and it should be something else. Array doesnt return in the database i selected, but still it's here. <? $host="localhost"; $user="xxxxxxxxx"; $password="xxxxxxxxxxx"; $dbname="mohaaleague"; $connection = mysql_connect($host, $user, $password) or die ("Kan niet verbinden"); $clan = "Belgian Fun Clan"; $db = mysql_select_db ($dbname,$connection) or die("Je Stinkt"); //SELECT clan FROM clan WHERE clan='Belgian Fun Clan' $query = "SELECT clan FROM clan" or die("Query Mislukt"); $result = mysql_query($query) or die("Query Mislukt1"); $row = mysql_fetch_array($result, MYSQL_ASSOC) or die("Query Mislukt2"); extract($row); echo($row. "<br>"); if ( $clan == $row ) { echo "het werkt"; } else { echo "het werkt niet"; } $disconnect = "mysql_close"; ?>
How To Get Mysql Query Result Into Temp. Txt File
I did a lite search in the archive but didn't find anything specific to my problem. Here is what I am trying to do: I've got a table with about 25k entries of company addresses. I need to be able to pull specific data out of the table and put it in a temporary text file and then display the result in the browser for the user to save locally. The query part and the format of the data is all simple enough but I am having trouble figuring out how to get the data from the query into a temporary text file and then displaying that file. here is what I whipped up but it obviously doesn't work: Code: <? $tmpfname = tempnam("/path/to/file/", "FOO"); $list = mysql_query("select * from FH_LIST where State='AK'"); while ($list_results = mysql_fetch_array($list)) { $data = blah blah blah; fwrite($tmpfname, ".$data "); } fopen($tmpfname, "r"); fpassthru($tmpfname); ?> I get an error message saying: Warning: Supplied argument is not a valid File-Handle resource (referring to $data).
MySQL Result Is Empty, But The Query Is Correct
I have written a script that grabs info from a database, and outputs it to a form. I figured I'd tidy things up a bit, and use a function to handle the queries, where I had previously hardcoded almost the same query several times. Code:
Selecting A Random Row Of A Mysql Query Result?
Let say I have a mysql query, which might yield more than 1 row when queried. How can I set up the query, so that it RANDOMLY selects one of the results? I know that I can do a LIMIT 1 command, but this will always yield the first row.
Result Query - Producing Extra Results?
what am i doing wrong here? $startrow=0; $limit=20; $qry = mysql_query("SELECT bodycare.*, haircare.* FROM bodycare, haircare WHERE bodycare.avail='true' AND haircare.avail='true' LIMIT $startrow, $limit")or die(mysql_error()); it should return 6 results between bodycare and haircare. instead it returns 8, - 4 repeats of the first haircare product and 4 of the second haircare product. There are only 2 haircare products in total and 4 bodycare, but the bodycare aren't turning up at all why? can you help me fix it?
Pulling Only 3 Digits From A Query Result Issues
I'm been playing with this for a few days and I can't seem to come close to getting this to work. Here is the situation. End users use their zip code to search for businesses. Well I want the search to show more then just what is in their zip code but really in their area. Easiest way I have found to do this is displaying all businesses that start with the same 3 digitals as their zip code. Example: there are businesses in Joplin, MO (64801) and in Neosho, MO (64850). When someone types in 64801 (Joplin) I want it to show the businesses in Neosho (64850) also.
Can I Put A Mysql Query Result Directly Into A Multidimensional Array?
I have two joined tables: Departments - which contains the department description and a key Positions - which contains position data What I'm attempting to achieve is to display the department title in one table cell and then list all the positions associated with that department in the cell under neither the title. I need to generate a table two column table with as many rows as required, depending on the number of departments, which is dynamic. Do this I'm trying to turn the result of my SQL query into multidimensional array e.g. dept = VioP positions = "designer", "engineer" etc, which I can do then use to generate the table. I've done a search on the forum and looked around the manual and I'm stumped on how to achieve this, a point in the right direction would be greatly appreciated. The query I'm using is below. PHP Code:
Adding Result Row To Mail Function
I have an email script that will pull the addreses from my club membership database. That part works fine. the problem I am having is being able to include row results inside of the actual email message. My message variable is something like this: Code:
MySQL Result To Real Array In Function
I'd like to create a function which input is the result of a mySQL query. The output should be exactly the same, only not a mySQL result array, but a 'real' array. So it should also get the fieldnames returned by mySQL and use those as keys. I can't get things to work properly: it should return a multidimensional array, like $result_array[1] = array( [field1] => field1 value, [field2] => field2 value, etc. ) somehow my result is (with code below) $result_array[1] = array( [0] => field1 value, [field1] => field1 value, [1] => field2 value, [field2] => field2 value, etc. ) +++++ code ++++++ $get_res= mysql_query(QUERY); if( $res = mysql_fetch_array( $get_res ) ) { do{ $result[] = $res; }while( $res = mysql_fetch_array( $get_res ) ); }; foreach( $result as $key => $value ){ print_r($value); };
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
Function To Test If Mysql_fetch_array($result) Pointing Last Record?
I try to perform multiple insert statment, but the problem is in the below codes, the last sql concatenation ends with ",". I wonder if there is any php function to test if the $result set contains the last record. ------------------ //Get topic id of vote_topic from last insert record $sql_topic_id = "SELECT topic_id FROM vote_topic ORDER BY topic_id DESC LIMIT 1"; $result = mysql_query($sql_topic_id,$conn); $row = mysql_fetch_array($result); //Get all student info from stuinfo $sql_strn = "SELECT strn from stuinfo"; $result1 = mysql_query($sql_strn,$conn); //Dump all student strn into vote_status. //Multiple insert statement? How? $sql2 = "INSERT INTO vote_status (strn,topic_id) VALUES "; while ($row1 = mysql_fetch_array($result1)){ $sql2 .= "VALUES ('".$row1[strn]."','".$row[topic_id]."'),";} mysql_query($sql2,$conn); ---------------------
How To Use My Md5 Function In A Query?
The little problem I have is its not returning the password only the hash form of it. Can someone show me where to insert the md5 function. I tried everywhere I can think of.. Code:
Query: Mail() Function
I'm having some trouble trying to send mail out when I retrieve the emails from a DB. I really don't know whats going on, but I have tested this on 'normal' email and this works fine but when it comes to a email from a DB it doesn't work. PHP Code:
Trying To Perform Query With Function
I'm trying to create a piece of code that gets rows from a database, formats them as "|1|2|3|4|..", and then inserts them into the database. Here's my code:
Turning A Query Into A Function?
I'm having is trying to integrate it with an existing php script. It looks like the only real way to insert it is as a function, other methods create various syntax errors or the query doesn't produce any results. However the code by itself works fine. So I figured if I turn it into a function place that function in the php file, then call upon it then it would probably work properly. Code:
Database Query From Within A Class Function
My application is object orientated and each object requires a cooresponding "PageID" in the tables "Page" and "PageContent" as well as a few other necessary elements to display properly as a web page. Some page elements are contained in their own tables, but are associated with the"Page" and "PageContent" tables by the "PageID" that cooresponds to the page the element should be displayed on. I have written a script that allows me to create a new page by inserting data into fields on the "Page" and "PageContent" tables, but it only works as long as the "PageID" in each table is auto_incrementing in sinc. I wanted include a method for members to sign-up for the site and I fould a script named "Authlib v1.94" that seems to work pretty well on its own. However, I hacked the code to redirect the data to an existing member table and cut out some of the validation. My intital tests on the hack have been satisfactory. If any of you are familiar with the "Authlib v1.94" code you may be aware there's a file named backend.php included in the script. It is a class file that includes some pretty nice validation functions for dealing with registering new members, logins, etc. The register function of the authlib class validates user input from the regestration form. If all the checks pass, it goes on to create a new entry in the "Member" table. (Keep in mind that I redirected the data to this table and hacked the code a bit.) The code looks something like this: PHP Code:
Call To Undefined Function: Query()
Im getting insane by solving a problem .... I try to define a function which uses a code-snippet from another file. My base are the codes from the great book "WebDataBase-Book by H. Williams & D. Lane". So I try to use $result = $connection->query("LOCK TABLES visitkarte WRITE"); if(DB::isError($result)) trigger_error($result->getMessage(), E_USER_ERROR); which works in another .inc very fine. Look at my .inc for the function VKDataInDB <?php require_once "db.inc"; require_once "DB.php"; require_once "authenticate.inc"; require_once "visitsontheweb.inc"; // Dieser Errorhandler ist extrem gefährlich da er das root-passwort der DB ausgibt! //set_error_handler("customHandler"); function VKDataInDB(&$connection) { //Book Page 641 $connection=DB::connect($dsn, true); $cust_id=getCust_id($_SESSION["loginUsername"]); // Lock Table -- 636 $result = $connection->query("LOCK TABLES visitkarte WRITE"); if(DB::isError($result)) trigger_error($result->getMessage(), E_USER_ERROR); //Query for the highest ID $result = $connection->query("SELECT max(vk_id) FROM visitkarte"); if (DB::isError($result)) trigger_error($result->getMessage(), E_USER_ERROR); $row = $result->fetchRow(DB_FETCHMODE_ASSOC); // Die nächste verfügbare vk_id errechnen $vk_id = $row["max(vk_id)"] + 1; //selbst erstellt $sql = "INSERT INTO visitkarte cust_id = '{$cust_id}', vk_id = '{$vk_id}', erstelldatum = NOW(), sessionid = '{SID}', vorname = '{$_SESSION['vorname']}', nachname = '{$_SESSION['nachname']}', titel = (), plz ='{$_SESSION['plz']}', ort ='{$_SESSION['ort']}', tel1 ={$_SESSION['telefonnummer']}, mobil=(), strasse={$_SESSION['strasse']}, homepage=(), email={$_SESSION['email']}, kategorie={$_SESSION['kategorie']}, hintergrund=(1), "; //Write data mysql_query ($sql) or mysql_error(); // Unlock tables $result=$connection->query("UNLOCK TABLES"); if(DB::isError($result)) trigger_error($result->getMessage(), E_USER_ERROR);....
Calling A Function If A Query Is Not Successfull
I am using MySQL-Max (the transactional version of MySQL) in an application I'm working on. We've created a class that handles all the database access stuff, to make it easier to update the information for different users using the same app but on different databases. The class itself does not issue the begin; and commit; statements to commit the queries between begin and commit to the database, as a transaction can have up to 50 inserts. So to write stuff to the db we would use something like: Code:
To Use Insert Query In A Javascript Function?
Am doing a page in which the data's to be updated on every click.. After updation the control should back on the actionpage with updation, i have some values in the javascript function(these are the datas upadting in the database..) I tried with ajax, but the control is getting lost after the first updation(first click)
Is It Possible To Use Php User Function In A Single Global SQL Query?
This string does not work in php: $sql="UPDATE mytable SET myfield=myuserfunction(myfield)" What I want is my function to evaluate each field and put the new value in the field. For example, this works: $sql= "UPDATE mytable SET myfield=myfield+3"; Stores myfield+3 in each myfield, but with a function it does not work.
Function Names Stored In Db; Called Based On Query
I'm wondering whether something like this is possible: 1. I want to store an id# / function-name pair in a database - e.g. 0001 / functionA(), 0002 / functionB(), 0003 / functionC(), etc. 2. Based on some query, some number of these id / function name pairs are returned. 3. The returned function names are called in a script. More background on my question: I'm building an intranet for my company. There are various departments within my company, each of whom will have their own section of the intranet. I've built various online tools that may be of use to some number of these departments. I want the departments to be able to decide which tools they want to appear on their "home page" within the intranet. In my imagination, each time I create a new tool, I register it in a db table. Each department uses an online form to flag the tools they want to appear on their page. The form they edit updates a db table, linking their department with the id number of the requested tool. The script that creates their home page queries the table, determines the tools they've asked to view on their home page, and calls the appropriate functions that will display these tools.
Displaying Result 1-8, Then Result 9-17 Etc.
I dispaly the results from the database like this. <? while ($row = mysql_fetch_array($prod_result)) { $small = $row[0]; echo"<td align=center><img src="produkter/hardware/decks/$small"></strong></td>";}?> But if there are more than 8 results, I wnat to dispaly the first 8 on one page, then the next 8 on the next page...How can this be done?
Nesting Result Loops Within Result Loops Possible?
I'm looping through a query, and inside the while result output, I am trying to loop through a second query (created from the 1st query's row results). I have checked that both queries return info. I can see that the 1st while result output works fine, but when I get to the inner while result output, it never returns any rows (nothing in the while loop evaluates). So, IS it possible to nest one query's output loop within another, or am I doing something wrong?
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"; } }
Empty Query, Query Fail
i am doing a user authentication but my problem is that when i type in user name and password it is Code:
SQL Last Result
When querying and doing a loop I want to specify that the last result of the loop does not include a horizontal line. How would I do this?
Outputing Result Once Only
Hi, I have a php script that looks up mysql records, on the basis of keywords entered by the user. The records are in tables making up a message board system, and the search works both for 'top-level' messages, and for replies. The results lists the 'top-level' message (ie the entire thread), even if the search matched text in a reply. However, I am having a problem making sure the thread is not listed more than once if the search matches several replies in the same thread. At the moment, the search looks up all the rows containing the search text, then the message starting the thread if the search has matched a reply, and the results are output in a while loop. I have tried making a long string containing all the id's of the displayed rows, usingsomething like $displayed .= _$row[id]_ in the loop, and then ereg("_$row[id]_", "$displayed", $array) earlier in the loop to see if this message's thread id is already listed, and skipping it if it is. However, I can't seem to get this to work. Also, this seems like a really inefficient workaround. Is there a better way to do this?
Result Using Two Variables
Probably a real simple solution but I can't for the life of me work it out. I have: $pollitem_1 $pollitem_2 $pollitem_3 $pollitem_4 if I do a for loop for the amount of items, is it posiible to have a variable for the number after the _ ? e.g....
|