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
See Related Forum Messages: Follow the Links Below to View Complete Thread
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!!"; } }
While ($row = Mysql_fetch_array($result)) Error Suppression
How can you get rid of the error that displays if you do a query which returns no result and then try and fetch the array, WITHOUT having to put the while in another conditional like if ($result != ''), something more efficient if possible.
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.
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?
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;} ?>
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? ....
Varible Pointing
Is it possible to point one varible onto another varible? Here's my code; PHP Code:
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? :-(
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:
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:
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);
Compare Record With Session Variable And Update Record If Different
I'm trying to figure out how to create a session variable from a recordset field value in a mySQL database and compare this with subsequent values from the same field each time the page reloads. When the value of the field changes (as a result of a user update) I want to trigger an event (redirecting to another page). It's probably a very basic PHP function but I am a newbie with this language.
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?
Mysql_fetch_array() In PHP 4.3.1
so i setup PHP/Apache/MySQL on my local computer to do development on - the code i brought over from the web works fine on 34sp's server, but not on mine. it says that mysql_fetch_array(): supplied argument is not a valid MySQL result resource or whatever. my code looks like this:
Mysql_fetch_array
can anyone tell me why this does not work? obviously there is more to the script but i believe that this is where my problem is, $result = mysql_query("SELECT * FROM table WHERE field LIKE 'variable'"); $result2 = mysql_query("SELECT * FROM table WHERE field BETWEEN 'variable' AND 'variable'"); while($r=mysql_fetch_array($result,$result2))
Mysql_fetch_array
I do a query that select latest 3 records in the database table. Now after doing the query, i need to echo it's results in 3 different tables, 1 big, and 2 small below the big one.
Mysql_fetch_array
I have used mysql_fetch_array in the past and haven't had any trouble. The code is to grab quotes out of a db based on the last name of the individual. PHP Code:
Mysql_fetch_array
I recently downloaded a php shopping cart tutorial and placed the database on my server and simply uploaded the php pages that were supplied. Upon running a page entitled products.php I recieve an error that states: Warning: Supplied argument is not a valid mysql result resource in yada/yada/yada/products.php on line 42. That line contains: while($row = mysql_fetch_array($result)) Might someone have a fix for this?
Mysql_fetch_array
i'm trying to extract var's from one table and use the results to extract var's from another table in the same db: PHP Code:
Mysql_fetch_array();
If i was making a website with a search engine and wanted to display the 26th-50th result from a mysql_query() what's the best way to do it?
Mysql_fetch_array
<?php //start session session_start(); //store cmpid from querystring $_SESSION['session_cmpid'] = $_GET['cmpid']; $campaign=$_SESSION['session_cmpid']; //connect to db server require dirname(__FILE__).'/core/dbconnect_vps.php' //select db $database = "atdata"; //define sql $sql_campaignredirect = "SELECT web_confirmurl FROM tbl_marketingcampaign WHERE marketingcampaignid = '$campaign'"; //run sql $result = mysql_db_query($database,$sql_campaignredirect) or die (mysql_error()); //fetch data $campaign_url = mysql_fetch_array($result); //display data echo 'URL is '.$campaign_url; ?> Instead of displaying the data (http://www.domain.com), it returns: URL is Array I know it's probably a simple oversigt on my part but can't seem to figure it out.
Mysql_fetch_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!
Mysql_fetch_array()
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:
Mysql_fetch_array
I've got following code: $sql = "select user_id from sales_users where sales_id = ".$user['id']; $res = mysql_query($sql); echo mysql_num_rows($res); $clients = mysql_fetch_array($res); It's a database containing users(sales_id) tied to clients(users_id). Each is is salesman for one or more clients, so obviously the resulting array has one or more rows. Whensales_id is 44, there are 3 rows: user_id's 4,13 and 45. The echo of mysql_num_rows tells me there are indeed 3 rows. Now here it comes: when I convert the results to an array, I only get 1 element in the array, user_id 4. When I change the user_id's, it always returns the lowest user_id and leaves the other 2 behind. A print of the resulting array:Array(=> 4) What am I overlooking? Up until now this has always worked well for me, but now I really don't see what could be wrong.
Mysql_fetch_array
im trying to access the 'update' time from my database by using the below code. $result = mysql_query("SHOW TABLE STATUS FROM logtable;"); while($array = mysql_fetch_array($result)) { print_r($array[Update_time]); // Will print information about each table stored in database The only problem is I get this error. What am I doing wrong?? 'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in...'
Mysql_fetch_array Problem
Hello, 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".
Understanding Mysql_fetch_array
I have copied some code which helps me get the forename and surname from a database. When I try to formulate the code to how I think it should work it only prints either the forename or the surname depending on how I format it. So therefore I have used all the including the bits I dont need to make it work. could someone look at the following code and explain what I dont need and the anatomy to make it work correctly include('pageconnect.php'); $connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database"); mysql_select_db($db) or die ("Unable to select database: $db "); $selectresult = "select forename, surname from users where username = '$username' and password = '$password' "; $result = mysql_query($selectresult); if ($result) { echo ""; while ($r = mysql_fetch_array($result)) { $forename = $r["forename"]; $surname = $r["surname"]; } echo "</ul>"; } else { echo ""; } mysql_free_result($result); //anotherpart of the page echo ("$forename" "$surname);
Resetting Mysql_fetch_array?
I'm having a bit of trouble getting this script to work. I am retrieving a list of items from a database. I want to display the individual items in the list in one of two pulldown menus depending on a bool value I have stored under a column in the database. PHP Code:
A Questions About Mysql_fetch_array()
whenever i use this, i'm leaving out one item from the array. in other words, one row from the table i'm querying won't show up. i'm new at php, and this is probably a simple thing, but please help of you can. here's an example that leaves out the most recent submission: $query = "SELECT topic, message, author, DATE_FORMAT(posted, '%M %e, %Y') AS d FROM messageboard ORDER BY posted DESC"; $result = @mysql_query ($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC) ) { echo"<p> {$row['topic']}<br> {$row['message']} <br>Posted by {$row['author']} on {$row['d']} <br>"; }
Mysql_fetch_array Error
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:-
MySQL_fetch_object And MySQL_fetch_array
I'm just wondering what the differences between the two of them : MySQL_fetch_object and MySQL_fetch_array I read on the PHP.net Manual, it said that when u use fetch_object the return would be object but u can only call it with their field name, but if u use array u can call it by its field name or its number So what the advantages of using MySQL_fetch_object rather than using MySQL_fetch_array ?
Mysql_fetch_array Problem
I set up phpmyadmin, and it works fine, but my code isn't working. id is the correct column (it is the primary key), stock is the correct database. CODE: $qresult = mysql_query("SELECT id FROM 'stock'"); echo ("START<P><HR>"); while ($row = mysql_fetch_array($qresult)) { echo ($row ["name"]); echo ("<br>"); } echo ("<P><HR><P>END"); OUTPUT: START Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14
Mysql_fetch_array... Interesting
this is probably another simple one, but the web doesnt seem to have an answer that I can find. Veeeery simple code. each row has 10 columns. require('db.php'); $query = "SELECT * FROM mytable"; $result = mysql_query($query); $numrows = mysql_num_rows($result); for($x=0; $x<$numrows; $x++) $row_arrays[$x] = mysql_fetch_array($result); //test row 1 foreach($row_arrays[1] as $count) print "$count<br>"; result for each print is the column number (0-9) and each id(0,a,1,b,2,c etc). But if I use mysql_fetch_array($result, 'MSQL_ASSOC') as the docs say, I get the 'The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH' error. No quotes, additional error about undefined constant. I figure using this would get the array including the id only and not include the number.
Table / Mysql_fetch_array
I can't keep my columns at a fixed width. About every five rows that are returned the last couple of columns will scrunch in. How do I keep everything perfectly aligned? Code:
Mysql_fetch_array Fetches Nothing?
I have some SQL experience and am having no problems with any other queries but this one in particular is just not working. I'm trying to get information from a sql table. There are 34 columns, and im fetching one row. Each of the values in the row is just a 1 or 0. After the query, I use mysql_fetch_array to put that one row into an array. Usually, I can just call any associated number of the array and pull the corresponding value, but in this instance, it's not giving me anything. I have checked the query over and over, it's definitely correct. I have added code to check for any SQL errors, there are none. I have used the exact same code elsewhere with a different table (and different data) and had no problems. The variable that mysql_fetch_array is run in returns as nothing, it does not return as "array" like it should. Code:
Iterating Through Mysql_fetch_array
been playing for a while with the mysql_fetch_array function and would like to be able to iterate through the return values rather that pick out certain ones like, $row[7] or $row['rank']. heres my code.... //perform query $query = "SELECT RAFPerId FROM personnel WHERE job !='Station Commander' AND job !='Squadron Commander'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $RafSqdCdrId = $row[0];} as you can see im returning the first result with $row[$i]. Is there a way i can do this like when using a For loop and $i and the iterator, $row ?
Difference Between Mysql_fetch_array, Mysql_fetch_object
Well there are certain queries whose answer i haven't been able to find and want to seek your help. Here are the questions: How many types of tables are there in MySQL and whats the difference between them? Which is the default table type for tables in MySQL? If I have lost MySQL password to login how can i retrieve it. If I'm not able to access to MySQL (say the executable file is corrupted) then how can I take the backup(for both Linux and Windows). whats the difference between mysql_fetch_array, mysql_fetch_object and mysql_fetch_row in PHP? How many values can we set in PHP using the set function?
Case Sensitivity - Mysql_fetch_array()
I'm retrieving some results from a mysql database and i'm using mysql_fetch_array() everything works fine.. Apart from the results are not case sensitive, i've checked the database using phpMyAdmin and the values stored ARE case sensitive what am i doing wrong? here's a peice of code as an example <? $sql = "SELECT * FROM table ORDER BY signup_date DESC LIMIT 5"; $result = mysql_query($sql) or die ("ERROR: ".mysql_error()." with query: $sql"); while($row = mysql_fetch_array($result)){ echo "<tr> <td class='profile_name'> <p><a href='user-profile.php?username=$row[username]'>$row[username]</a></p> </td>"; // Format date $signup_date = date('d-m-y', strtotime($row[signup_date])); echo "<td class='signup_date'> <p>$signup_date</p> </td> </tr>"; } ?>
Multiple Mysql_fetch_array() Calls
I've got a simple query hopefully somebody can clear up for me. I need to make a query on a database to select a set of table rows, using something like: $result = mysql_query($query); I can then use mysql_fetch_array in a while loop to access each row in the result. This all works fine. However, what I'd like to do is to go through this result more than once. ie. use mysql_fetch_array() to go through each row in $result more than once. How do I do this?. There appears to be no my of resetting mysql_fetch_array back to the beginning of the $result once all rows have been erad once. I don't want to make multiple identical queries on the database, simply to read the same information.
Isn't Mysql_fetch_object Less Flexible Than Mysql_fetch_array?
Or is it something I misunderstand with the way PHP treats objects? When it is an array I could do $row[$custom_field] and thus cgabge dynamically the field to get. When $row is an object, however, I can do no such thing as I am accessing an object var: $row->field. So why to use fetch_object?
Mysql_fetch_array Generates Error
Using php 4.3 (register_globals 'on') the mysql_fetch_array is generating the following report in error.log: Quote: [Mon Apr 07 23:25:16 2003] [error] [client 127.0.0.1] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:Program FilesApache GroupApache2htdocsshoppingcart.php on line 49 Part of the script that generates this is as follows: PHP Code:
|