Getting MYSQL Result Into Single Variable
I have a MYSQL query running that returns a single string of data but it is returned as an array.
What I need to do is store that single piece of data in a variable. I know it's probably a really simple process but it has been irritating me for far too long.
the result I get when I use print_r($result) is:
Array ( [ADDDATE(񟭇-04-05', INTERVAL 6 DAY)] => 2007-04-11 )
I can't figure out how to store the 2007-04-11(the result) into a single variable named $end_date.
View Complete Forum Thread with Replies
Related Forum Messages:
Result Mysql As Variable
I have an select on which the user choose property, arrival and departure dates for calculating the price, works perfect. But I need to put in some sort of error if the person choose dates higher than end date in the database, What I want to do is this, but don´t work of course: sep_fin is an datecolumn in the database if ($salida>"sep_fin") { echo "¡ There are no prices yet!"; } elseif ($row = mysql_fetch_array($result)){
View Replies !
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);
View Replies !
Refering To Single Result
I have a query which will only return one result. I have only ever used a while($row = mysql_fetch_array($rsl)) {} loop to retrieve results. What is the best way to reference a single result?
View Replies !
Single Variable Memory
I'm doing various things to a very large string in a variable and want to display the final size when I'm done. I can't use get_memory as that takes in a ton of other factors as well. Is there a way to get the mem usage of a single variable at any specific time? I guess I could do strlen*8 to get byte size but is that right?Add: actually I guess it would be just the strlen() for bytes size...*8 for bit size.
View Replies !
Create Single Variable
I have a simply loop that is getting the 'player' field from a table, and then echo'ing out all of them. What I want to do is be able to place all the names in one variable so that i can include that single variable in a another echo statement be used in creating a bubble tooltip. while($row = mysql_fetch_array($player_data)){ echo $row['player'] . ' <br /> ' }
View Replies !
Single $_Post Variable
I'm making a "controller" page which takes the value of the "name" variable of a submit button and, based upon the name, it will include the proper content. I'm having a problem getting the contents of this $_Post index into my trigger variable. Here's the snippet: if (isset($_POST['submit'])) { $buttonHit = $_POST['name']; } else { $buttonHit = "step1"; } The input button on this page looks like this: <input type="submit" name="step2" value="Make Reservation" />
View Replies !
Make All The Elements In A Array Into A Single Variable
I have an array which is generated by the result of an SQL query... What I am trying to do is take that array and insert it into a different table in a single field, so what I am trying to do is make all the elements in a array into a single variable I can use to insert into a field with each array element seperated by a comma. This would be easy if the array had the same amount of lines each time but it dosent, sometimes the array has 1 element sometimes it has 5....any ideas??
View Replies !
Convert CURL Result Into A Variable
I have am XML query sent through cURL. The query that is sent returns another xml file which contains more info (for credit reports i.e., you send a name, ssn etc and get back the result) The problem is the reult comes back like this: "Firstname lastname ssn otherinfo .. . . . ." I think the explode function would work well with this but first I need to convert the cUrl result into a a variable.. Code:
View Replies !
Single Mysql Query
i thought that everytime I call this function to makes a query to the database when i already have the results. So i modified the function to query only if the result ($row) doesn't exist.below is the code, like i said it still works but can anyone tell me if i am still querying the db each time i call the function? function State($db, $sel, $row){ ############################# if (!$row){ $db = new MYSQL(); $sql = "SELECT state FROM states ORDER BY state ASC"; $query = $db->Query($sql); } ############################## OpenSelect($sel); while ($row = $db->FetchRow($query)) { $state = ucwords($row[0]); echo "<option>$state</option>"; } CloseSelect(); return $row; }
View Replies !
Single Mysql Select
I have a simple array named j12stuff that is a list of words. Can I use one mysql query to select all words from a table that matches the words in the array that are nouns? The point is to use mysql to reduce the array list to nouns only.
View Replies !
Escaping Single Quotes For MySQL
here's my SQL statement: SELECT item_id, artist, title, format, type FROM music_main WHERE artist = 'Bleu Collar' AND title = 'Makin' The Rounds' PHP is telling me this is invalid. What PHP function would I use to escape the single quote in the title?
View Replies !
Question Re Getting A Single Value From A Mysql Database
If I run a mysql query that gets a single field from a row in a database table, what is the easiest way to get the value from the result? I normally do something like this: $query = "SELECT name FROM users WHERE id = 1" $result = mysql_query($query); list($name) = mysql_fetch_row($result); Obviously this is one less line to write than $row = mysql_fetch_row($result); $name = $row['name']; Is there a simpler way than using the list function with a single parameter?
View Replies !
PHP/MYSQL Single Entry Linking
What I am trying to do is very simple, but I can't seem to figure it out. I store prett much everything, aside from my layout, in a mysql database. I want to add tutorials to my website, and I already have the form to add tutorials ready, and the database for tutorials ready. Now, what I want to do is this - On tutorials.php, I want to provide a link with all the entries in the tutorials database, with only the name and author, and for the name to be a link. When you click on that link, it goes to another page that shows the actual contents of that SINGLE DATABASE ENTRY.
View Replies !
Mysql Error Of Single Quotes
My host recently upgraded from 3.2353 to 4.1 of Mysql. Ever since then, any text fields that have an apostrophe or single quote causes this error. If we remove it, the sql processes correctly. Code:
View Replies !
Single Quote ' Mark From To MYsql
I built a form for my users to fill out, and while testing it out some people told me the they couldn't used the sinlge quote such as in the word "couldn't" When a user types in a single quote, I want the php script to take the single quote and pass it to the Mysql DB so that the correct information can be propperly displayed at a later date. Does anyone have any ideas on how to do this without having my user type a back slash before each and every single quote mark ?
View Replies !
PHP MySQL Single Iteration For Data Manipulation
How do I cycle through a MySQL query result one row at a time so that I can do some work on each individual row, instead of having the whole query scroll by. I need to have the ability to post each row to a form and then work on it, posting the results, then go on to the next row.
View Replies !
Select Single Column From Mysql Into Array
Is there a way to select a single column from a mysql database and directly put the results into an arrray? Here is the workaround below, but I would like to elimniate the array_push step: $uids=array(); $res = mysql_db_query("db", 'select uid from tbl;', $link); while ($row = mysql_fetch_row($res)) { array_push ($uids, $row[0]); }
View Replies !
Hyperlinking A Single Field From A MySQL Query
I've created a database that has the following fields: id (int) lastname (varchar) firstname (varchar) etc etc I'm able to query the DB and produce the FULL field list results as I need them (in DESC order), but my question is how do I generate the field 'id' into a hyperlink that will be formatted as mysite.com/query.php/id=(id number)?
View Replies !
Search For Keywords In A Single MySQL Column
I am looking for a quick and easy way to take user entered keywords in a search field and search through a field in my MySQL table for matching words. I will have a field in the database called "Keywords" and they will be separated by commas. I know I can use: $search_array = explode(" ",$searchwords); to parse their submitted search terms into individual words, and $keywords_array = explode(",",$keywords); to break out the database field into individual words as well. I just cant think of the easiest way to compare here. Am I on the right track or have I lost my mind?
View Replies !
Like To Have The Variable "theme" Defined In A Single External File
i have many pages (page1.php .. page100.php) and each of them include some fixed subpages (top.php, bottom.php). each subpage (top.php, bottom.php) uses a variable ("theme") defined in its "parent" (one of the pageX.php). this variable is also used (not only defined) in the parent page itself. i would like to have the variable "theme" defined in a single external file, instead of defyning it for every page. is it possible? sorry for the probably stupid question, im new to php.
View Replies !
Trying To Unset Single Session Variable Unsets Entire Session
I have all the data being stored in session variables, so when the student puts in his student ID, it passes it from one page to the next. After the student votes, I use a function called logout that checks if the vote was counted, then uses session_unset($_SESSION['studentID']) and I also have a place that passes an error through session to let the user know of various problems with their login, such as if they have already voted. if voting is disabled, or if there are no candidates to vote on. The problem I am having is when I use session_unset, it unsets ALL session variables, not just the ones I want. php.net says not to use session_unregister if register_globals is disabled, which it is. What else can I do? I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session.
View Replies !
Search Multiple Fields In A Single Table In MySQL
I am trying to create a search facility for my website and need to be able to search multiple fields in a single table in MySQL, I am using dreamweaver, and my PHP and SQL knowledge is minimal, I don’t have a problem being able to search a single field in the database and displaying the results as dreamweaver generates the code for me. The table I am trying to create the search for is called LEWISHAM and the fields within the table I need to search are; towna, townb, townc, postcodea, postcodeb, postcodec. If someone could please help me or point me in the right direction where I could learn more about searches or give me some tips to help that would be fantastic.
View Replies !
Combining 2 Fields In A Single Mysql Select Query
i want to combine 2 fields in a single select query fields. pageheader name values. abcd <div id="d"></div> i want to merge/combine the pageheader and name in a single select query so that it can retrieve the pageheader with some styles which i have stored in another table.
View Replies !
Build A Category Tree From A Single MySQL Table
I have following table for my categories: ID | name | parent 1 | Music | 0 2 | Rock | 1 3 | Hard-Rock | 2 4 | Heavy Metal | 2 5 | Progressive Rock | 2 6 | Jazz | 1 7 | Pop-Jazz | 6 8 | Acid-Jazz | 6 etc... I would like to write a function that displays these categories in a tree view like: Music - Rock - - Hard-Rock - - Heavy Metal - - Progressive Rock - Jazz - - Pop-Jazz - - Acid-Jazz Can someone help me here?
View Replies !
Need To Update Multiple Mysql Records With A Single Form Submit
I have a wish list like a shoping caty based on a mysql databse where i retrieve records with php I need to update the quantity which is in a text fields : input type = text name = quantity[] value = $quantity input type = checkbor value = $id name = id[] I need to update quantities based on the primary id represented with id with a single submit.
View Replies !
Insert Multi Rows With A Single Mysql Function Call?
For this table --------------------------------------- | id | foo | bar | -------------------------------------- I understand that we can insert a row to the table per call, like this sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', '$string_2')"; mysql_query($sql_query, $db_handle); if I want to insert multi rows(the following example inserts two rows) at the same time, the following example works, but can I merge this two insertion into a single mysql operation (to achieve efficiency)? sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', '$string_2')"; mysql_query($sql_query, $db_handle); sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', '$string_2')"; mysql_query($sql_query, $db_handle);
View Replies !
Last Row Of Result MySQL
I am making a wrapper class for MySQL functions and I want to be able to return the last row from a query. here is the function in my class PHP Code: function getLastRow(){ $this->lastRow = mysql_data_seek($this->result,$this->numRows-1) return $this->lastRow; }//end getLastRow I am using mysql_data_seek and pointing it to the last row, but it is not returning anything.
View Replies !
MySQL Result Resource
I want to build a function that, depending on the input, will either return the results from a MySQL query or do something else and return one of several messages. My problem is checking the return value to see which is returned. Is there a php function that checks a variable to see if it is a valid MySQL result resource? I looked through the manual and couldn't find anything.
View Replies !
Returning 1 Result From MySQL
I know the usual way of receiving results from MySQL, useing a while loop e.g. $sql = "SELECT * FROM users WHERE email='joe@hotmail.com'"; $result = mysql_query($sql,$connection); while ($row = mysql_fetch_array($result)){ echo $row["firstname"]; echo $row["lastname"]; echo $row["email"];} BUT, if I know they only 1 result is going to be returned, is there a way to do this without using a while loop? So if I only wanted to get only the firstname of the person with email joe@hotmail.com. can I do this without a while loop or do I have to use one?
View Replies !
Total Result Php Mysql
PHP Mysql limit the result to 5 I can display the 5 results using a do & while which it ok. I want to list the total or all the results without using a do or while this is so I can combine the results and remove duplicate words from the total results I.E. Do & While row result 1 this is the top 2 this is the bottom 3 this is the middle 4 this is the end 5 this is the finish This is what I want to do: result this is the top this is the bottom this is the middle this is the end this is the finish modified result:: this is the top bottom middle end finish
View Replies !
Invalid MySQL Result
I keep getting the following two errors: Warning: Supplied argument is not a valid MySQL result resource in /home/xxx/public_html/articlepro/newarticle.php on line 75 Warning: Supplied argument is not a valid MySQL result resource in /home/xxx/public_html/articlepro/newarticle.php on line 84 Here's the code which I think is causing the problem. PHP Code:
View Replies !
MySQL (DB) Result Sorting
I'm doing is taking results (fetching rows) from my mySQL database. But what I want to do is sort the results according to last name. So basically the table structure looks something like this: id (primary key) fullname A example rows could be: 1 John Smith 2 Mary Jane Now what I want to do is sort the results in PHP based on last name. I'm using the Pear DB for connecting to my mySQL database. Based on the example rows I gave, Mary Jane would go first, and then John Smith. How would I go about doing this? I was beginning to split the result based on spaces, and the last word to explode, but how would I truly do this?
View Replies !
Modifying MySQL Result - But Not The DB
How can I modify a MySQL data set returned by mysql_query? I am basically doing a while loop over the rows, changing one field, and then doing a mysql_data_seek back to the beginning of the set before returning it. However, later calls to mysql_fetch_assoc still return the orginal data, meaning that (I assume) I am changing a copy of the data rather than the result set itself. Taking the reference (i.e. $record =& mysql_fetch_assoc($result);) did not help. I have read a large quantity of the posts in the php.net site, googled, and read my PHP books - but have come up short on this one. Yes, I know it's better to simply modify the DB. However, I'm working with an existing code base which is very complicated, and want to cherry pick one very well tested feature by making a change in the result set only under special circumstances.
View Replies !
Mysql Result Into Array?
I have a shopping cart script sending info to a processor. I need to send the qty's and item name's in some sort of string via a single variable to the process form. i.e. (3) Hipster Turnips, (6) Butter Milk Baby Brains, (2) Super Freaks Code:
View Replies !
Result From Mysql Into Foreach?
when using mysql_fetch_array($result) I usually toss that into a while loop like so while($row = mysql_fetch_array($result)){ ... } however I was wondering if there was a way to put it in a foreach statement like so foreach(mysql_fetch_array($result) as $row){ ... } Is that legit? Will this work?
View Replies !
Linking To A MySQL Result
I had it the other day but now altered the code for my real database and it stopped working. Here is the first page which lists the 10 most recent news stories: <?php require ('get_connected.php'); $sql = mysql_query ("SELECT title, story_id FROM news ORDER BY story_id DESC LIMIT 0, 10"); while ($row = mysql_fetch_assoc($sql)){ echo "<a href='view.php?id={$row['story_id']}'>" . ucwords(strtolower($row['title'])) . "</a><br>"; } ?> And here is the page that should be displaying the news story based on story_id selected by the user.....
View Replies !
Reverse Mysql-result
Is there any way, to reverse the result of a mysql query? Explanation: If i have eg. 20 records, all with their own id of course, select 5 with limit, and order them DESC by ID, it should give me: 20, 19, 18, 17, 16. That's all ok. But now i want 16 to appear first, 17 second, etc.
View Replies !
Mysql Result Set As An Array
the question is, is there a way of assigning each value returned from the sql query and assinging them to a single array. for example i have a a query like so; $table = "sales_table";         $query = "select treatments from $table where date between  ད/08/2006' and ཕ/08/2006'"; $result = mysql_query($query); because the values stored in the treatments field are imploded as a single string when the user submits the form the value looks like; 1, 22, 33. Code:
View Replies !
|