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 Complete Forum Thread with Replies
Related Forum Messages:
Test For PTR Record
I need to test a IP for a PTR record and display the outcome. The problem i have is i need to test with 2 vars. $host = the ip $hostmask = the hostmask How do i use 2 vars in one function so i can call it like: test_ptr($host, $hostmask) Ive tested this but cant seem to get it to work. code below. Thanks in advance function test_ptr($host) { if (strlen(gethostbyaddr($host))== strlen(gethostbyname("$hostmask"))) { $emsg = " !!Couldent find PTR Record!!"; } }
View Replies !
Issues With Using Mysql_fetch_array($result)
I keep having serious issues with using mysql_fetch_array($result) and I don't know why. I have used it many times previously without issue. Here is the code I am using (I have added in a few items while trying to debug it). Code:
View Replies !
Inaccurate Mysql_fetch_array Result
When I use this code: while($row=mysql_fetch_array($result)){ it DOES work, BUT it always gives me ONE LESS out of the array than it should. ex) If I have 5 items in the array, it'll only print out 4, etc when I use the echo commands. PS. I fogot to thank the puerson who helped me last time when I posted here. :headsmack: His suggestion did work! Now I can't find it.
View Replies !
Mysql_fetch_array Result Type Error
I'm trying to run mysql_fetch_array with a variable in place of the optional result type constant, like so mysql_fetch_array($result, $rtype) where, obviously, $rtype is one of the three valid values for the result type. This throws an error: "mysql_fetch_array() [function.mysql-fetch-array]: The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH." I'm not quite sure what the issue here is, other than that I'm replacing a constant with a variable. I'm looking for a solution that will allow me to (variably) be able to dictate this value.
View Replies !
Mysql_fetch_array Error - Warning: 4 Is Not A MySQL Result Index
I have written a function to bulid a table of url links stored in MySQL. In my database I have two tables: tblLinkTypes and tblLinks. My Output should look like this: Link Type1 Link Title2 URL2 Link Type2 Link Title1 URL1 However I get this error when the code gets to the bottom (see //errors here). Warning: 4 is not a MySQL result index in /home/httpd/inc/dbWhiteWater.inc on line 275 Code:-
View Replies !
An Extra Last Empty Field In An 'mysql_fetch_array' Result Array?
I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe The following code: $oCursor = mysql_query("SELECT ID from tblName WHERE Name='Jane'"); if (!$oCursor) { $bGo = false; } else { $aRow = mysql_fetch_array($oCursor); } results in: count($aRow) = 2; $aRow[0] = 1; $aRow[1] = '' Am I missing something, doing something wrong, a wrong PHP setting?
View Replies !
Mysql_fetch_array :: Supplied Argument Is Not A Valid MySQL Result Resource
I've got a problem with mysql_fetch_array function. I have two function: function db_query($dbh,$qw) { db_test($dbh); $result = mysql_query($qw); return $result; } function db_insert($dbh,$table,$what,$info) { db_test_table($dbh,$table); $id=0; $qw="insert into $table $what values $info"; $result = db_query($dbh, $qw); return $result; } Then I have the following piece of code: $result = db_insert($dbh, $table1, $what1, $info1); $row = mysql_fetch_array($result); The db_insert call workes fine, 'cause a new record is inserted into the table. The problem is that when I call mysql_fetch_array I got the following error: "Supplied argument is not a valid MySQL result resource".
View Replies !
Mysql_fetch_array(): Supplied Argument Is Not A Valid Mysql Result Resource
i recieve this error from this part of the code: mysql_fetch_array(): supplied argument is not a valid mysql result resource it's returning a long text from the database which is about 200 characters long. <?php if ($_SESSION['is_town'] = 1){ $query = "SELECT usemap FROM town WHERE town_id = " . $_SESSION['townID'][0]; $db_result = mysql_query($query); $db_usemap = mysql_fetch_array($db_result); echo $db_usemap;} ?>
View Replies !
Warning: Mysql_fetch_array(): Supplied Argument Is Not A Valid MySQL Result
Here is my script: <?php $dbh=mysql_connect("localhost", "my_username", "my_password") or die ('No can do!'); mysql_select_db ("my_databasename"); $query = "SELECT * FROM contacts"; while($i = mysql_fetch_array($query)){ echo $i[first]; echo $i[last]; echo $i[email]; } ?> Get this error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/my_username/my_domain/my_databasename/test.php on line 6.
View Replies !
Warning Mysql_fetch_array(); Supplied Argument Is Not A Valid MySQL Result Resource?
i am getting the following error with this bit of code? Warning mysql_fetch_array(); supplied argument is not a valid MySQL result resource? Code: <?php /* Connect to database */ $extra = 'blah' $size= Ƈ' $paper= 'matte' $db= mysql_connect("localhost", "", ""); mysql_select_db("", $db); $sql="select type_id FROM type WHERE extra=".$extra." AND size=".$size. " AND paper=".$paper ; $type_id=mysql_query($sql); ............
View Replies !
Specifying A Certain Record Of A Result Set
I am looking to retrieve a certain record of a result set, but not by means of a traditional primary key. Instead, I would like my query to receive an integer from a method, and retrieve that record in the result set (e.g. the method sends it Ɗ', then it must retrieve the 4th record in the result set.) Code:
View Replies !
Define The Maximum Result Record
I would like to define the maxmum record that are shown after a search. Say the total result has 20000 records I want the result page show only the first 50 out of the 20000, and ignore the rest. I heard someone say i could "Change the SQL to "SELECT TOP 50...." I'm not sure how to do that, can anyone help? ....
View Replies !
Deleting A Mysql Record In Active Result
I'm doing a select in wich I retrieve some values. If the value is in an array, I must delete the record. As I'm doing a "mysql_fetch_object", may I delete this record inside the loop ? when doing a mysql_query, do I have a "local" copy or just a link to the mysql query result. In the first case I may delete the record as I get an "image" of the query result, in the second case I shouldn't as the query result will be changed by the deletion of any record.
View Replies !
Mysql_fetch_array() In Function
I would like to encapsulate mysql_fetch_array in a function that just returns an array containing the results. mysql_fetch_array seems to only return one row at a time though. Is there a way to take the whole result set and put it directly in an array without sending mysql_fetch_array through a loop? Also, is there any downside to this? I just dont want to have to reuse mysql_fetch_array everytime i need data from a common query.
View Replies !
Mysql_fetch_array Function
I'm trying to separate the results of my query into a comma-separated array. $query_records = "SELECT * FROM category"; $records = mysql_query($query_records, $db) or die(mysql_error()); $records_array = mysql_fetch_array($records); $final_array = implode(',', $records_array); print_r($final_array);
View Replies !
Make A Function, Like Mysql_fetch_array
Is it possible to make a function, like mysql_fetch_array, where data can be put into an array inside a loop expression, without having to do all kind of checks and stuff to end the loop when done pulling out the data? Code:
View Replies !
Mysql_fetch_array In A Function Will Work?
when i try to make the mysql_fetch_array in a function, its not work, is my code is correct? function mq($tbl){ $query="SELECT * FROM $tbl WHERE type ='".$_GET['type']."'"; $query = mysql_query($query) or die(mysql_error()); return $query; } function mfa($query){ Â Â $result = mysql_fetch_array($query) or die(mysql_error()); Â Â return $result; } Â Â Â Â Â Â while($result = mfa($page_query)){ Â Â Â $menu .='<li><a href="pages.php?type=page&pageid='.$result['page_id'].'">'.$result['page_name'].'</a></li>'; Â Â Â Â Â Â }
View Replies !
Continued Prob W/ Mysql_fetch_array Function
FORUM MODERATORS: i marked my own thread resolved before i should have. i thought i had solved the problem, but i had only really got half of it. i hope that someone could mark it unresolved. thanks! i'm still stuck on how to use this mysql_fetch_array function again that i need to pull the results from my query. i've shown my table in almost every post i've made about this-- not for any other reason that i made it, and it could perhaps provide a useful supplement to my illustration of my code problems. i hope no one is annoyed by it. Code:
View Replies !
Using The Mysql_fetch_array Function To Pull Data In As An Array.
Im currently pulling in a load of data from my sql table. I found that using the mysql_fetch_array function was the way to pull it all in as an array. The only problem? I cant manage to get it to store a value into another name eg $ip = $row['ip'] and count how many instance's are contained within it. I need to do similar things to the 'url' and the 'time' but as I cant access the data there isnt much I can do!
View Replies !
How To Test If FLock Function Is Working
I believe the syntax is correct but how would I test to see if the txt file is indeed being locked and unlocked after being written to? $fp = fopen($settings['idfile'],"wb") or die("Can't open the id file ($settings[idfile]) for reading!"); flock( $fp, LOCK_EX ); fputs($fp,$previd); flock( $fp, LOCK_UN ); fclose($fp);
View Replies !
Why A Header Would All Of The Sudden Stop Pointing To The URL
Can anyone tell me why a header would all of the sudden stop pointing to the URL that I designated it to go to: Here's the example: <? require("Cart.php3"); DBinfo(); Root(); mysql_connect("$DBHost","$DBUser","$DBPass"); mysql("$DBName","INSERT INTO CartItems VALUES ('$UID','$ItemID','$ItemQuantity','$Date','$CartItemsID')"); Header("Location: $Relative/viewCart.php3?UID=$UID");?>
View Replies !
How Can I Make A Function That Would Test If The Time Entered By The Employee Is Valid?
I have a program that calculates log in and out of an employee... My question is how can I make a function that would test if the time entered by the employee is valid example: 1.) IN : 02:00:00 OUT: 03:00:00 Result: VALID 1.) IN : 22:00:00 OUT: 01:00:00 Result: VALID 1.) IN : 23:00:00 OUT: 22:00:00 Result: INVALID 1.) IN : 02:00:00 OUT: 01:00:00 Result: INVALID 1.) IN : 02:00:00 OUT: 00:00:00 Result: INVALID
View Replies !
Links Pointing On PHP Manual Not Shown In Error Messages
I have html_errors set On and it's visible that it's on because I get some parts of the error messages bold. The problem is I can't get any links to point to the PHP manual. docref_root = "/php_manual/" docref_ext = ".html" are set but no links are appearing. By that I mean there are absolutely no <a> tags or anything of that sort in my error outputs. I tried generating almost every type of error but please if somebody could post a line or two of code that produces some clickable error message on their box so that I can test it on my. (send the output also, please) if my script is: <?php $var1 = 'var1' $var2 = 'var2' ?> I get this output <br /> <b>Parse error</b>: syntax error, unexpected T_VARIABLE in <b>e:www estarray.php</b> on line <b>3</b><br /> shouldn't there be any links in that pointing to PHP manual in my php_manual dir? :-(
View Replies !
Function That Is Tracking A Record When Updated
I have 2 tables $tblprefix.basenji and the $tblprefix.tracking The $tblprefix.basenji contains records and all records have unique basenji_id the $tblprefix.tracking is only having basenji_id e-mail and action (enum) = sub From the moment a person press "tracking" of a record, it happens and $tblprefix.tracking register the request in its tabel. basenji_id insert the id of that record from the table $tblprefix.basenji and the email of the person that is tracking that record. 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 !
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 !
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 !
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 !
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 !
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 !
Script Repeat Updates The Record And Also Inserts Another Record With The Same Information.
I have a form which contains some fields that are populated with data from a table. This same form also has fields that are empty because the data has not been collected yet. The main table is called client with a primary key of client_id. What I need to do with this form is select the client and update the record into a new table with the missing information. If the client doesn't not exist in this second table, I need to insert the row otherwise if the client does exist in this table because of a previous update, update the record. When I run my script, the insert works. When I try to run the script again and try to update the record, the script not only updates the record but also inserts another record with the same information. How can I write my script so it checks whether a client exists in a table and if it does, update the record and if the client does not exist in the table, add the client?
View Replies !
|