Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Affected Row Return Values From MySQL


When I remove 10 rows from a table in a mySQL database, I am not getting 10 as the affected rows return value. I am also getting positive return values if I try to delete a non-existent entry. here is a small test script that I am working on where I am getting errors. Code :




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Return Values
I have an idea about returning variables.

in 1st page, there's variable "x1". it's action page is B.
So, I can use "x1" in B.

$x11 = (int)$_POST['x1'];

B's action page is C

In that case, I want to use "x1" in C.
So, can I save "x1" in B and use it in C?

for exmaple, can I use following commend in C?

$x22 = (int)$_POST['x11'];

Function Return Values
If I assign a variable to a function, say,

$x = f($y);

and then f happens not to return anything, does $x just remain unset? Or is
this illegal?

Multiple Values Return From One Fuction
Let say i calculated var1,var2 in a function and i wan to return both of these?

Odbc_fetch_array Doesnt Return Any Values
My problem is odbc_fetch_array returns no value at all, but the scripts returns no error and all i can see in the page is the html table without any data in it..

the connection to oracle via odbc works, and in my other scripts i used odbc_fetch_row to retrieve data, but this one is kinda slow in getting massive amount of data from oracle. im now testing which is faster, odbc_fetch_row or odbc_fetch_array? but odbc_fetch_array returns no value at all. PHP Code:

Table Return Values & Strpos()
I'm having the following problem, after I have pulled out data from my database tables (MySQL) then it seems the php5 strpos() function fails to get results.

I'm using strpos() to find tags in the format like [IMG] and [/IMG] to wrap html code around it and then display it, everything works fine when I load the data from txt files. But when I use the same data from the table then strpos() just runs over the tags in the string and does not find them.

What is the diffrence about a string that gets contents from out fread() or from a database table? I'm confused.

Does anyone knows why this happens and/or how I can solve this?

Attempting To Return Values From Array From W/in A Function
I am attempting to read through a text file & then update an HTML page
table w/ the output from the text file (ie; statusing by table).

What I want the code to do is read through the file, look for a line
that matches a couple of strings, next is loop through the file from
that match to 30 lines searching for a "score" from, then store that
score; and then look for the next algorithm (8 of them) run & score.

What I get is an array w/ only the most recent array entry.

I have tried several things; return(), array_push(), php manual, and a
more than a few days searching online for a similar example.

Code example below;

function fraction_0($file,$log) {
while (! feof($file)) {
$line = fgets($file,512);
if (ereg($_GET[what],$line) && ereg("_A_0",$line) &&
ereg("Request ID",$line)) {
print ("$log".htmlspecialchars($line)."<BR>");
for ($i30 = 1; $i30 < 30; $i30++){
$line = fgets($file,512);
if (!ereg("returned best solution",$line)){
if (ereg("Score from run", $line)){
print ("$log".htmlspecialchars($line)."<BR>");
$alg_score = explode(" ", $line, 512);
if (ereg($alg_score[6], 1)) {
$alg_array = array("alg0_1" =$alg_score[8]);
print "score for alg 1 is $alg_array[alg0_1]<BR>";
}elseif (ereg($alg_score[6], 2)) {
$alg_array = array("alg0_2" =$alg_score[8]);
} elseif (ereg($alg_score[6], 3)) {
$alg_array = array("alg0_3" =$alg_score[8]);
} elseif (ereg($alg_score[6], 4)) {
$alg_array = array("alg0_4" =$alg_score[8]);
} elseif (ereg($alg_score[6], 5)) {
$alg_array = array("alg0_5" =$alg_score[8]);
} elseif (ereg($alg_score[6], 6)) {
$alg_array = array("alg0_6" =$alg_score[8]);
} elseif (ereg($alg_score[6], 7)) {
$alg_array = array("alg0_7" =$alg_score[8]);
} elseif (ereg($alg_score[6], 8)) {
$alg_array = array("alg0_8" =$alg_score[8]);
}
print "<table border="1"><tr><th>Alg 1</th><th>Alg 2</
th><th>Alg 3</th><th>Alg 4</th><th>Alg 5</th><th>Alg 6</th><th>Alg 7</
th><th>Alg 8</th></tr>";
print "<tr><td>$alg_array[alg0_1]</td><td>
$alg_array[alg0_2]</td><td>$alg_array[alg0_3]</td><td>
$alg_array[alg0_4]</td><td>$alg_array[alg0_5]</td><td>
$alg_array[alg0_6]</td><td>$alg_array[alg0_7]</td><td>
$alg_array[alg0_8]</td></tr>";
print "</table>";
}
} else {
print ("$log".htmlspecialchars($line)."<BR>");
$i30=30;
}
}
}
}

Rows Affected?
I am executing an update-query. Is there a way I would get a result if there
is a row affected, because if the row isn't affected (product may not exist)
I have to execute a insert-query. This way I could use 1 query (in the
update-case). Else I would always have to execute 2 query's (1 count-query
and 1 insert or update query).

Query Results And Affected Rows?
I'm doing a mass database update and I have a query string something like this:

UPDATE table SET field1=0, field2='' WHERE (email='address1' OR email='address2' {and so on...} );

I know you can view how many rows were changed after its done. I'm wondering though, is there a way I can view which entries failed? For example, lets say the email address - 'address34' was not found in the database, is there anyway I can display this from this UPDATE query? or to do this, would I have to compare each address individually with the table to check if it exists? (and if it matters I have about 1000 adresses that are being updated from this)

Return The Key From Last Mysql Insert
How do I return the auto incremented value of the primary key from a tuple that I have just inserted into a MySql database. If that is not quite clear enough then this long winded explanation should explain what I mean: Say I have a MySql table called "n" with two columns:

1: id = Autonumber - Primary Key
2: name = Text

If I insert a tuple with the following mysql command using a PHP interface:

Quote: INSERT INTO `n` ( `name`) VALUES ('Paul Smith')

Then a tuple with with values say (34,Paul Smith) will exist in the MySql table. 34 is the value of the auto generated primary key. The question is how can I find this value 34, which is the primary key, without running a statement like :
Quote: SELECT * FROM `n` WHERE `name` = 'Paul Smith'

MySQL Results To Return Only One Value
For example, I have a column that has three different values, 1, 2, & 3. In the database, there may be over 500+ entries with one of these values assigned to it. How can I get MySQL to return just 1, 2, & 3 only once rather than several hundred times.

No Return Using PEAR And MySQL
Below is the php code (Very simple):

<?php
include_once('C:AppServphpPEARDB.php');
$db = DB::connect("mysql://alucard@localhost:3306/soccer");
$db->setErrorHandling(PEAR_ERROR_DIE);

if (DB::isError($db)) {
print $db->getMessage();
exit;
} else {
$result = $db->query("SELECT * FROM league;");
print 'Query returned ' . $result->numRows() . ' rows'
print 'Query returned ' . $result->numCols() . ' cols'
print 'Query affected ' . $db->affectedRows() . ' rows'

$db->query("INSERT INTO people VALUES ('Thomas', 0);");
print 'Query returned ' . $result->numRows() . ' rows'
print 'Query returned ' . $result->numCols() . ' cols'
print 'Query affected ' . $db->affectedRows() . ' rows'
$result->free();
}
$db->disconnect();
?>

Now the problem is, when I ran this code, there is nothing return in
browser.(ALL BLANK, see nothing, no error, no result, absolutely
white)

There was also no changes on DB.

Linking Back Into MySQL From A Return
I have a simple contact table with a catagory, name, address columns and I'm sorting it by catagory then name.

My question is after I get this return how I can make each catagory listing link back into the database to return all its members in a seperate part of the page. I can make a simple echo html table loop to return the catagory data, but how do I also include an <a> link to each catagory listing so that it will then access the database and dump it into another part of the page.

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

Return MySQL Table Name As PHP Variable
I've got a MySQL query something like the following:

$fields = mysql_query('SELECT ItemID FROM Table1 UNION SELECT ItemID FROM Table2 ORDER BY RAND() LIMIT 1');

There's more criteria than that, but this illustrates the basics of the situation. Essentially I want to randomly select one row from either of the two tables. I've got that part down; the query is returning the results I need.

However, the problem I'm having is finding out which table the query pulled the result from. I'm querying two tables and will return one result - but I need to know which table the result came from. Is there any way to assign it to a variable? If so, how can it be done?

How Do I Return Result Of Mysql Row Deletion
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.

How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?

MySQL Query Return Category Name Instead Of #
I Have 2 MySQL tables of interest here. 

Table 1: categories
ID
name

Table 2: items
ID
category (this relates to the category ID in Table 1)
title

I want my table on my webpage to show the category name from Table 1 instead of the category number in table 2. Code:

Mysql Doesnt Return All Results Of A Query
I have an sql query like this:
SELECT column FROM table WHERE column1="3" AND column2="1"
This query works perfectly if i run it in the command line, to be
exactly it return two results.
But if i run it from php i just get the first of the two results.
Any ideas?

Mysql 4.1.8
php 5.0.3

I have a second problem. But its more of a question.
if i run the foreach loop on an array like this
array("id" => "78"), then it splits 78 up in 7 and 8.
Now you say its stupid to use a foreach for this array. But in the
function there i use it the array could also be two dimensional.
Is this behavior normal? I looked in the php manual but found nothing.

Return Record Ranking Of A Mysql Table
I have a table consisting of names, and registration dates. I query the db "select * from users order by regdate" I want do another query for a particular user, I am looking for the script to say: user is row 15 of 30.

Trying To Return Mysql Array Items From Function
I am writing a calendar script which returns events, holidays etc.. from MySQL for days with events. This was easy BUT then I tried to return multiple events on some days and thats where I am stuck.

I found some examples of returning arrays from functions from functions but they all use some form of array(&#391;',&#392;',&#393;') and then use a for loop... I am using mysql_fetch_array so this does not seem to work... First, here is some of the code from the function where I am returning the value: PHP Code:

Query Mysql, Return Highest Value Then Create Value +1
I have a product input form I created (with php freaks help) for my website which I input general information and specs on our products. What I'd like to do now is when that form loads, it searches a seperate table and looks for the highest "ID" number.

It returns the number, adds 1 to it and displays the number somewhere on the input form for reference + error checking. When the form is submitted it takes that form and creates a record pushing that number in the correct field.

How To Convert Carriage Return In Mysql To Excel Format?
I have a varchar field in MySQL table that has carriage returns. I am trying to display this field in an Excel document. When I display this using (php_writeexcel class ) Excel I get small squares due to Excel converting the carriage returns.

Is there a way to convert these carriage returns to display properly. I have already tried str_replace("","",$value) and does not work. Any regular expressions?

Mysql_free_result Return Error Saying Not Valid Mysql Result Resource
im trying to do a query which takes rows of large amounts of text data
and displays them one after another. the size of the fields is causing
the page to be massive in size. so to try and reduce this im trying to
use mysql_free_result to clear the contents from memory.

however its returning an error saying not valid mysql data when im
certain that it is.

is this because im using a while loop like this...?

($row = mysql_fetch_result($result)) {
mysql_free_result($result);
}

MySQL- Detect Values
I am trying to make a system that detects wherther an entry has been made in the database containing a certain value.

More accurately, the system checks the database of usernames to see if the username the user entered in the sign up page has been used. If not, it allows the name to be used, if so, it does not allow it to be used.

The database stores the information in the cells: username, password, and userID (an auto-incrementing cell) The database is called usernames. What I am asking for is the code I would use to do the username check. Basically:

if (username has been used) {
     don't allow user to sign up, and present an error message
} else {
     allow user to sign up, and complete the registration process
}

Checking Values In A Table (MySQL)
I've got a tables with two variables, "one" and "two". I want the value of "two" when "one" equals $blaa It is easy, like this PHP Code:

Inserting Values Into MySQL Using A For Loop In PHP
I have an html array I am trying to insert the values from into my database.I have no idea how to do this using a for loop.These are not seperate rows that I want to insert, but rather one row with these values in the columns they are meant for. PHP Code:

Scrubbing MySQL Values And CSVtoArray()
I have a function that passes a csv string to mysql to use as values:

<?php
function fnINSERT ($csvValues) {
$sSQL = "INSERT INTO mytable (
field_a, field_b, field_b, field_c
) VALUES {
$csvValues);
return mysql_query($sSQL);
}

//note the SQL Injection attack in the 2nd parameter
$csvValues = "1, "&#391;' OR ''='"
$oResult = fnINSERT($csvValues);
?>

$csvValues is already scrubbed for some business logic, but (obviously)
it needs to have that mysql_real_escape function run on each of those
csv values, as well.

For architectural reasons, I can't do the scrubbing before the function
is called, but instead have to do it when it comes to me as this csv SLOB.

My First Question:
Can I run the real escape function on $csvValues as a whole, to
successfully scrub each parameter - or will I experience undesirable
results that way?

My Second Question:
I can convert an array to csv pretty easily, but going the other way
screws me up (because of quoted commas). So, my "architectural reasons"
(for this and some other stuff, too) would evaporate if someone could
help me write a function like this:

function CSVtoArray($sCSV) {
$aryRetVal = array();
$aryRetVal = foo($sCSV);
return $aryRetVal;
}

Storing MYSQL Values Into An Array
Ive got a basic MYSQL query that is returning data and i want to store it in an indexed array so i can get at the individual values easily. in my code i have used the list() function. Code:

Checkbox Values Stored In Mysql
I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.

Holding Place Values In Mysql
I have a field in my database that is a winning percentage for each team in my league. This field is a float and I want the winning percentage to produce 3 decimal places. The problem I am having is that when I enter the value in the DB if the value is say, .650, itr only enters .65. I want it is this way for consistentcy when I print the data on my stats page. Is there any way to combat this?

Increasing Certain Values In MySQL Database
Each post in my announcement section has an IndexNo . . . so far I've had to do enter that automatically. How do I rig something up so that php will extract the most recent (or last entered) news post's IndexNo and increase it? The IndexNo is stored as an integer so increasing it is no worry . . . my real problem is how do I tell mySQL to give me the most recently posted news article?

Post Two Values Into One Mysql Field?
I'm posting data into a MYSQL database, which works fine using the schema below and the php form below:

cms_test
story_id (int 3)
web_date (date)
web_time (time)

Code:

Updating Multiple Form Values To MySQL
i am building a content management system for my employer's Web site, which is a daily newspaper. haven't had too much trouble learning PHP up to this point, but I have a problem now that I am finding difficult to figure out. any help would be much appreciated.

I have two MySQL tables for a Poll on our site, one named PollQuestions and one named PollAnswers. I am trying to build an administration form that will allow the user to pull up both the question and answers for any given poll and edit them if they need to. I haven't had a problem with the Poll Question, but with the Poll Answers, I am unsure how I can pull each Poll Answer into a text field and update all of them in one query based on an ID field for the answers.

In other words, I have each answer pulling into the form from the database and for each answer, i have a hidden field that stores that particular answer's ID number.

So how do I update all of the answers in one query based on that particular answer's ID number? I have written the following code, but it does not work. Any help would be much appreciated.

For the form itself, here is the code for the Answer text fields:

Updating A Slew Of Values Into MySQL From A Form
I'm working on a script to edit stored values which I will call on to change the appearence of certain parts of my website. I figured that I can store default values in MySQL, echo those values into a form, then edit whichever values I want, and have it updated in MySQL. However, I can't get the updating into MySQL part to work.

The form displays everything the way it should, including the current values in the database. When I try updating it, instead of using the new value, it instead inserts blank space. I *think* it's because of my query, but I don't see why it shouldn't work, since I did define $values = $_POST['values'] at the top of the script. I don't know if it's my logic that's off, or my code, but I would appreciate any assistance. PHP Code:

Checking For Values In MySQL And Other Conditions Not Working?
I'm trying to redirect when testing for certain condidtions as shown
below. When the conditions are ture, it redirects, but still goes ahead and
processes the sql query. What am I doing wrong??? And then sometimes when
the conditions are correct, it doens't redirect. It appears to be very
inconsistent.

//Check for repeat name
$result = mysql_query("SELECT * FROM survey WHERE FirstName =
'".$FirstName."' AND LastName = '".$LastName."' ");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){header("location: ./oops.htm");};

//Check for repeat email
$result = mysql_query("SELECT * FROM survey WHERE EmailAddress =
'".$EmailAddress."' ");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){header("location: ./oops.htm");};

//Check for existance of first name, last name, and email
if(!$FirstName){header("location: ./oops.htm");};
if(!$LastName){header("location: ./oops.htm");};
if(!$EmailAddress){header("location: ./oops.htm");};

$newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')");
$result=mysql_query($newrecord);

Mysql Null Field Values Not Being Returned
is there a workaround for rows with null values not being returned? I am
using PHP 4.3.2 and mysql. the mysql_fetch_array just seems to ignore some
of the latest rows with null values.

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);

}

Querying Mysql Database Based On Values From Html Form
I want to build a simple form for querying database having business organization info. The form has four fields name, category, city and state. Users should be able to search based on any of these fields. Code:

Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated.

When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:

Comparing User Input Values In A Form With Database Values
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

Adding New Values To An Array That Already Contains Values..
is it possible to append new values to an array that already has values in it??

say, i have my existing array;

existing array;
$array = array([66314] => 66314 , [66315] => 66315) ;

then , when i check my checkbox on my next page, the ids should be appended to the $array:

array that needs to be added to the $array;

$array = array([66316] => 66316,[66317] => 66317,[66318] => 66318);

how should it be done??

Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

Assigning Values With Other Values
Say one has an array like such:

array("lang=english", "nomusic=true", "name=Fred", "menu=false");

Is there a function in which I input the array and it makes all the things into variables with the other things as the content like:

$lang="english";
$nomusic="true";
$name="fred";
$menu="false";


Return A Value
i got a functions and it echos out a result, the problme is if i make the functions into a string it still echos out the result at the spot where the string is at. Code:

Return 0
I have a little function that gets a result from a query when supplied arguments, it works great except when the result is 0. Here's the func : Code:

Return MAX Value From Array
I need to return the county with the greatest score with the following long query:

Class Does Not Return A Value
My first time working with a PHP class, and after 6 hours of working out the
kinks I am unable to return a value from the class, so now I appeal to the
general audience what on earth did I do wrong this time?

This is the code the retrieves the values:

What Can Return The ENTIRE Url?
I'm looking for PHP equivalent to Javascript's location.href property. This returns the ENTIRE url (including any variables that might be submitted to a script). I've looked at phpinfo(), but I didn't see exactly what I am after. If the answer is the HTTP_POST_VARS variable, could someone please give me a simple example of how exactly this variable is to be used in code?

Return Statement
What happens when you take the value returned by a function that
doesn't return a value? For example,

function myfunc($myvar) {
if ($myvar == "xyzzy")
return(1);

return;
}

$abc = myfunc("def");

I know from my days of c programming that this would be very bad to
do. But php gives you so rope I'm wondering if you could just do an
isset($abc) to see if myfunc returned a value.

If so then we could write (scary) code where on an error condition
instead of returning something like -1 you just don't return a value.

Return $$ From Function
How can I use the variables generated by the following function in my code? They're just not being passed to the main script. I've tried global $$k; bu that did nothing PHP Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved