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 Complete Forum Thread with Replies
Related Forum Messages:
Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ??? eg. <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> <? if (db_num_rows($qid_p) == 0) { ?> <li>No <? } ?> <? while ($prod = db_fetch_object($qid_p)) { ?> <p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b> <br><? pv($prod->description) ?> <br>$<? pv($prod->price) ?> <br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>] <? } ?> How to assign this code to a unique variable ???
View Replies !
Assign Function Output To Variable??
I've found some references to this topic at : http://forums.devshed.com/showthrea...ion+to+variable but it does not seem to be working for me. here's a snippet... <? PHP function listPeople ($getArray) { foreach ( $getArray as $val ) { echo "$val, "; } } $foo = listPeople($splitDirector); ?> The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.
View Replies !
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 !
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 Replies !
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); };
View Replies !
Warning: Mysql_result() [function.mysql-result]: Unable To Jump To Row 0
i want to grab the value of a sql entry. but the thing is, sometimes this value is <NULL>. i thought, no biggy, i'll just have an if statement: if (is_numeric(mysql_result($query, 0))) { //do something } else { //do something else using mysql_result($category_id_query, 0); } however, this doe not work. i get this error: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 is there a way to check to see if mysql_result() is <NULL> without throwing an error.
View Replies !
Assign Value To Variable
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering if a function exists where I can pass a variable name and a value, and the variable would be created. ie. somefunc("sn", "Shore") Would create the variable $sn and assign the value "Shore" to it.
View Replies !
Assign To Variable
I am trying to take data from the database and assign it to a variable but i'm not sure how this is the code ive been trying $sql = "SELECT Name FROM Names WHERE Name = 'Peter'"; while($row = @mysql_fetch_array($sql)) { $var == $row['Name']; }
View Replies !
Ways To Assign A Value To A Session Variable.
I am wandering which way to assign a value to a session variable exist. Which of the following examples will work. Example #1: session_start(); session_register("ex"); $ex = 2.0; Example #2: In first.php: session_start(); session_register("ex"); In second.php: $ex = 2.0; Example #3: In first.php: session_start();...
View Replies !
Assign Variable From Database Field
Is there a way to assign a variable from a database field? I'm thinking along the lines of $make = $row_rsList['make']; $model = $row_rsList['model']; then they'll switch out based on my SQL WHERE statement. This valid syntax?
View Replies !
Assign Userid To A Session Variable
When a user logs into my system, i assign their userid to a session variable [php] $_SESSION['userid'] = $myrow[0]; [php] and then a user logs out, i do the following [php] $_SESSION['userid'] = '' session_write_close(); [php] so, when a user clicks on a link to a page they should only see when logged in, i do the following test [php] if (isset($_SESSION['userid'])) { header('Location: members.php3'); } [php] but the logout does not seem to work for some reason? userid still seems to be set after running the logout script, any ideas? am i doing something silly?
View Replies !
Assign Function To Class....
Is it possible to assign some functions to a of a class? class loginClass { function initialize() {$something} } function CheckLogin() { $something } $login = new loginClass(); $login->onLogin = CheckLogin(); $login->initialize(); where the CheckLogin function will only be run during the initialize of the class, not during loading of the whole document.
View Replies !
Assign A New Value To A Variable Passed From An Html Form
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3. if ($question3!="select days") { $question2=$question2+$question3; } This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.
View Replies !
Multi-Dimensional Arrays - Assign Variable
It's a simple question, but I'm just not getting it. I have two files: <?php $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc... <?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc... I want to assign the value of "2324" to the variable $number. I've done this with arrays that start with number=>1, 2, 3, etc., but not successfully with specific values. What am I missing?
View Replies !
Assign Variable To A Block Of Html Code
Is it possible to assign variable to a block of html code? Something like this : $myblokvar = "<table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="images/bartitle_login.gif " alt="Login" width="475"...
View Replies !
Assign Variable Name As Variable
I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable. For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop. Code:
View Replies !
Assign Mysql Record Values To Gloabl Variabel
I've been struggle with the code below. I've tried mysql_fetch_assoc and various other functions, but can't seem to get it to work. The code works as far as that point though. global $first_name; global $last_name; global $password; function get_acct_rec($email){ $conn = db_connect(HOST, USER, PASS, DB, PORT); $sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "'"; $c_result = mysql_query($sql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . db_error($conn)); while ($row = mysql_fetch_assoc($c_result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $password = $row['password']; echo $row['first_name']; } mysql_free_result($result); db_close($conn); }
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 !
How To Add Function Result To Array?
The way I'd like to set up a particular set of functions is to have them either return TRUE or, for example: $errors[type] = "Sorry, the file type is not allowed. Allowed types are ".print_array_inline($acceptedTypes).". "; Then later, I have a foreach loop that echos each array element. However, when I echo each array element is doesn't output the whatever the print_array_inline function does. Any suggestions?
View Replies !
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 Replies !
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:
View Replies !
Saving Result Of Function Without Being Echoed
I am trying to save the function "rand(1, 1000000)" in a variable but when I am for example trying: $randomnumber = rand(1, 1000000); it is executing it right ahead while when i try $randomnumber = "rand(1, 1000000)"; or $randomnumber = 'rand(1, 1000000)' It is saving rand(1, 1000000) as variable. But what I need is a variable saving the result of rand(1, 1000000) so the number does not change either. Any ideas how I would do this?
View Replies !
Storing The Result Of Javascript Function
how do I store the result of a javascript function into a PHP variable? I have a div that is hidden or shown based on whether or not a checkbox is clicked. Initially the div needs to be hidden. So how do i make sure that it will be hidden in all browsers when the page loads. The code for hiding and unhiding it works in the different browsers i have tried, but not initially being hidden. attached is what I currently have.
View Replies !
Chmode With Mkidir Function, The Result Isn't As Expected
I've tried to create a directory with the php function mkdir(). I've used a "0777" mode , so that owner,group and other can read,write and exectue files in this directory. There's no problem creating the directory, but after it has been created, its mode is "0755". Where did I commit a mistake ?
View Replies !
Using The Function Prevents Accessing The Result Of The Match.
I don't know if this is possible, but it should be. However, it doesn't seem to be working for me. how I can get it to work: I use :||: for my delimiter for str_replace, etc. When replying, the new PM is appended in front of the existing chain of replies, thus the same table entry is used and updated each time. Problem is in storing the sent date, and providing time zone and format adjustments: $string='This is the message that was sent on :|1161850848|:' $newString=preg_replace('/([0-9]*)/',format_time(adjust_time('${1}')),$string); // the result of this is as if ${1} = 0 $newString=preg_replace('/([0-9]*)/','${1}',$string); // returns 'This is the message that was sent on 1161850848' It seems that using the function prevents accessing the result of the match.
View Replies !
Search Function That Highlight Result Instead Of Filtering It Out
I am trying to create a search function that will jump to the page containing the result and highlight it instead of filtering it out. To more clearly illustrate what I mean take a look at this link: I would like to search for eg. "bruce wayne" (its record number 30) and just have that row highlighted. Anybody who could steer me in the right direction would be a massive help as I've spent the last 2 days trying to work this out with no joy.
View Replies !
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); ---------------------
View Replies !
Refreshing Cache Through Php Header Function Yields No Result?
I am building a website for a client. He wants a login page with a "Your account" page for his clients. I am using a combination of javascript and php. Upon succesful login $_SESSION variables are set to 1. example: $_SESSION['logged']= 1; If the client logs out due to idle time or pressing 'logout' these values are set to zero. example: $_SESSION['logged']= 0; Upon loading of "your account" and any of its sub-pages, that page checks $_SESSION['logged']. If the value is zero it redirects automatically back to the login page. Providing oppertunity to log in again if you wish. The checking of $_SESSION['logged'] is supposed to redirect even if the client has logged out, but has pressed "back" on the browser to try and see a login page. The page does not do this. Pressing "back" reveals the page. Interacting with the page or pressing "refresh" THEN causes it to redirect. I need the page to auto-redirect, not show. I am aware that it is the page being cached and keeping those values until you interact with it. I have fully tested the header function in php. Using 'must-revalidate' & 'no-cache' and other version! (most info from php.net). I get no errors when testing the pages, so my code is correctly spelled! But there is simply no reaction by the page, it just does what it does, which is not what it is supposed to do? I ask for experience! Is there a specific way of doing the header functions? Perhaps it must be placed in a specific place in the page? And how can i check that the page is actually using the functions and not just moving over them with no action taken?
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 !
|