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




Addition Of Values In Database


In my database I have two products. Each product is made up of components. This is the product table: Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Preventing The Addition Of Duplicate Items To A Database
I'm trying to stop my file upload system adding the same files to my database. The script below is a much simplified version of what I'm using. It's getting frustrating as I can't get this to work.

I have a page previosu to this that posts up the details form a previous form. The form and everything works fine apart from the duplicate check. 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?

Simple Addition?
I am trying to basically add 2 numbers together but my math skills are lacking when it comes from reading a database. I am not 100% sure I undersdand the code here so bear with me. Code:

An Addition To My Userlevel Problem.
If any of you happened to read my earlier posts, I had a dilemma with
creating an efficient method of limiting access to data for my users and
subusers.

My heirarchy looks like this:
[Please excuse my shoddy ASCII art ;)]

Admins
|
+- Client 1
| |
| +- Business 1
| | |
| | +- Operator 1
| | |
| | +- Operator ..
| | |
| | +- Operator n
| |
| + Business n
| |
| +- Operators ...
|
+- Client n
|
+- Business n
|
+- Operators ...


What I need to do is find a way to associate data entered with a certain
group so that only that group may perform actions on it.

For example: Operator 1 is associated with Business 1 which, in turn,
is associated with Client 1. If Operator 1 enters in some data, that
data should only be accessible by members of the Business 1 group and
groups above it ( Admin > Client 1 > Business 1 > Operator 1 ). This
would be done in such a way that data is shared 'up' but not 'across'.
Data entered by a member of Business 1 would be accessible by other
members of Business 1 but not by Business 2. Moving up a tier, Client 1
would have access to all his businesses, but not the businesses of other
clients.

There would be a bevy of different clients and businesses so saying,
"Well, make Admins = 1000, each client a multiple of 100, each business
a multiple of 10, and each operator a multiple of 1." The obvious
problem with that would be when there are more than 9 of any client,
business or operator.

So, now I beg of you wise, wise people: How on earth do I construct a
heirarchy and tagging system to do what I described above? I'm certain
something like this has been done before. I am just unaware of how to
set it up.

Floating Point Addition / Comparison...
I've written a parser to parse a CSV file that has three fields per line.  The third field is always a number - I want to add up all of these values, and then check to see if it equals 100 before proceeding.  If it does not equal 100, I want to print a message and exit.

Here's the issue - this works perfectly fine for 100 lines in the file to be parsed or less.  As soon as I go over 100 (and I mean immediately, it happens for 101 lines and up), the script breaks.  Even though the numbers in the last field all add up to 100, for some reason the if statement is tripped, a message is displayed and the script exits. 

I know for a fact that they're adding up to 100 because I had several echo statements in there displaying as such - but as soon as the file has more than 100 lines, even though they add up to 100, it does what's inside the if statement and exits.

I cannot for the life of me figure this out. I can't deal with this anymore, I've been looking at it for 6 hours straight, and nothing I have tried has worked.  Here is the code - the contents of the file are in $importContents, each element in the array is a line in the file: Code:

Submit Form With Addition By Email
I have been working on a form for about a week now and am stuck!  I hope someone can help lead me in the right direction... 

I am building a form that will be used to submit cash orders to the person who handles the vault at the bank I work for.  The way it needs to work is that the person ordering the cash fills out the form with the dollar amount of each denomination that they wish to order.  When submitted, an email is sent to the vault person as well as the information that was submitted is displayed on screen.  The trick is that each row and column have to show the totals in them... like this:

Output Example:

Location | 50's | 20's | 10's | 5's | Total
__________________________________
East | 20000 | 1000 | 100 | 300 | 21400
West | 10000 | 3000 | 200 | 100 | 13300
----------------------------------------
Grand Total                              | 34700

I have gotten the form working so that it displays the page with all the ordered information and the totals. 

The main problem I am having is getting the emailed information to work the same way.  I can get it to email the amounts that were entered for each denomination, however the totals don't work.

I'm wondering if I need to have hidden fields on the front page of the form (where they enter and submit the info) that does the math there so that it can be passed to the form processor and be used in the email.  If so, I have not had any luck finding any code examples to help. 

Retrieving Values From The Database
I am retrieving a value from the database and I insert the value as a value of a field
The problem is that when the value has spaces then in the filed is viewed only the part of the value before the first space. If the value is not includes any spaces then the value appears in the field correct.

Displaying Values From A Database From An Include
I've got a URL going to a template, e.g. www.mydomain.com/product.php?id=product_a

where the template is product.php the tag after the ? refers to the product that should be displyed in the template, in this case product_a

Inside the template (product.php) I've got:-

<? $url = $id.".htm"; include("$url"); ?>

This works fine so far. How ever I've also got an include inside the the template (product_a.php), called product_info.php, which is another php file that displays the product version and the platforms that it sits on. so in the the include (product_info.php) I have:-

<?php

$db = mysql_connect("localhost", "username", "password");
mysql_select_db("DATABASE",$db);
$result = mysql_query("SELECT version FROM table1 WHERE id = id",$db);

do { if ($myrow[0] != "") { echo "$myrow[0]n"; } }

while ($myrow = mysql_fetch_array($result));?>

however this displays all the version numbers within the table (for every product)

I just want it to display the version number of the value of $id (www.mydomain.com/product.php?id=product_a)

Inserting Values Into Database Using Arrays
I'm trying to insert the database the answers to a question and to get the user to select the correct answer. PHP Code:

Unable To Insert All My Values Into The Database
I have an error in my code because its not inserting my $_session['identity']  into the database. I know the session has a value because I am able to display it on the page. it just wont insert it into the database. Code:

Droplists/database Values/sessions
I have many droplists that are populated with the values "open" and "closed". This one is called drop31. As with all of the droplists, which value is default is dependent on which value is currently stored in the db under "Lot31": Code:

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?

Calculating Against SQL Database, Returing Values
I was interested in trying to calculate against an SQL Table and return values that matched within the calculation. What i am trying to put together is a Zip Code Locator. I have a table "AREA" of Lat, Long and Zip Code numbers for the area im interested in. I also have a table "LOCATIONS" of Lat, Long and Zip code numbers for 25 different locations with data about Store Name, Address, etc.

What i would like to do is have a user input thier Zip code and that would launch one query, which would pull down the Lat & Long from the table "AREA".  I would like to then Query the database "LOCATIONS" and calculate the distance between them using a formula. So it would do this.

User submit--->$_POST['zip'];---->Query and bring down LAT, LON from "AREA" table--->Query the LOCATIONS table, bring down all values---->calculate LAT, LON, from AREA table minus LAT, LON from the LOCATIONS table and populate to Variables the values that were LESS THAN 5 or something.

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Looping Database Values To Create An Array
I have a fairly simple php code problem I think, I want to loop values from a mysql database within an array to fill the array. I'v never done this before so your help would be valued if someone had the time.

*denotes where I want to use database values*

Navigating Database Results And Posting New Values
I am trying to dynamically display results that I retrieve from my database i.e. only 5 results per page and code should automatically compute how many pages it needs and create links for each page. I have also added a link at the top of my page so that if user wants to POST new data he can post it. Problem is that when I click on page 2 or 3 or any numbered page and click on POST link it gives me following error
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

And it did not tell about any header etc. Code:

Double Quoted Values From Database Won't Show Up In Form
I enter user input from a form into a mysql database using addslashes. When I access values with a double quote from the database they won't show up in a text form field as the default value. I use stripslashes when accessing database values, magic_quotes_gpc is on, magic_quotes_runtime is off, magic_quotes_sybase is off.

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:

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??

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


What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

Images In Database Vs. Image References In Database
i kept all of the uploaded images as files on the server, and created links to them in the database. I have been changing things around now (especially directories) and I am thinking of storing the images in the actual database. I read somewhere that this can be considered a bad practice, so i was wondering what the consensus here was. In my opinion, modifying all of the code to point to the correct directories everytime a page location changes seems like a pain in the a**.

Database Search -text Database...
Can anybody tell me how to search a flat file database delimited by |. I have exploded the data and managed to get it into a table but want to restrict the final table contents by a search.

The table code at the moment is below - I'd be using a htm file to submit the data. and hopefully be able to search by partial searches eg big would return big and bigfoot. Code:

Set Values Once
let say that i want to allow someone (the site admin maybe) to chose
certain configuration values, for instance

* number of products per page
* picture widht
* back color
....

Right now, i just have all those info in a php page, so it can't be
modified
$number of products_per_page = 20;
$picture_widht = 2;
$back_color = #FFFFFF;

I could keep this info in the database, but i should read it every time
a page is rendered... (open connection, query, close conn)

What would be the best way to do what i'm need? Is there any chance to
"read once, keep value for ever" ?

Checkbox Values
Basically, I have 2 checkbox's which are printed out for each record within my table. On the next form, each checkbox is tested for being "checked" and the database is updated accordingly.

This is fine. My problem is that I dont want users to be able to select both check-box's at the same time. After talking to "andnaess" on an earlier post and doing some reading, I decided upon using some javascript to do what i wanted.

I have found a script which does exactly what i want, and i am now incorporating it into my original php script.

I am having problems assigning a name and value variable with an array to my checkbox's. Is this possible, or have i got the wrong idea?

Combo Box Values
I have values in a combo box where datas are coming
loaded dynamically. When an user selects a particular value and press search, even after refreshing the page, I want to keep the value same as the user selects. For example suppose if I selects
value PHP from combo box, after submitting the combo box should
value highlighted must be PHP. IS there any way I can do this?

Reading Url Values
I am able to pass values to the URL as this shows. I can get the id value and select data from mysql, but I cannot access the ln value. I have use various combos and acannot get it to read the ln value and display it. What am I doing or not doing? I have used get, post and result:

$id=$_GET[id];
$ln=$_POST[ln];
echo $_RESULT[ln]

Echo Certain Values Only
I'm creating a table that has 7 columns. In the first column, I'd like to show My_SQL data. The data contains multiple fields, but there is one that matters most right now.

Right now, I show this data with:

<?php echo $row_UserData['Number'];?>

However, I only want to echo this value if another value of the same row ($row_UserData['Code']) equals a certain number.

How would I write a conditional statement like this?

2 Values In A Loop
In a guestbook the im building, I want to set the <tr> bgcolor in a difrent color each msg (the same effect is also here in these forums).The code is a while loop (to get mysql results). How can I do it ?

Monetary Values
What is the best way to remove all characters except digits from a string? ie: I may have a value: '$4,000.00' but all I want is 4000

Values From A Form
I have a form (search.html) that has 1 textbox and 3 listboxes. When I submit this form to a php file (search_res.php), I am using $HTTP_POST_VARS to get the values which is fine.

But then in my php file(search_res.php) I again have a listbox with 2 options. When I choose either one of these options to display the search results either by "Price" or "Name" I lose the values of the main form (search.html). How can I keep these values from the main form in my search_res.php page?

How Do You Add Values In Rows Together
I am using the following code to take records out of a Mysql database and display them on an HTML form. $myrow[8] is a number. At the bottom of the table, I want to display the sum of all the $myrow[8] values added together. Code:

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'];

Adding Different Values
How can I do If I need to add some values, I am using LEFT Join and I am displaying some lists There is my code: PHP Code:

Selecting MAX Values
I have a SELECT statement where I use numerous GROUP functions, namely: SUM, MAX and COUNT to query and combine various elements of a table. My question lies around the MAX() function. The field which I am querying for the MAX function is a TINYINT field named HS with numbers ranging anywhere from 0 to 375. However, there is a second TINYINT field named NO which is also tied to it.

Basically I would like to add a "*" to the end of the HS field if the NO field is set to 1. If it is set to 0 I would just like it to display the number in the HS field alone. Is it somehow possible to select the NO field of the specific MAX value in the query? If that can be done then I can combine it when writing my php.

Compare Values From CSV.....
I have a CSV file which contains data from the search engines, which includes search engine, keyword, number of applicants and number of visits.

However in some cases there is repitition however I want to merge those figures together.

An example of what I mean....

Array (add More Values To The End)
I have an array. I wan to add more values to the end of the array. how would i go about doing this. my current code does not work. PHP Code:

Getting Values From A File
I have a file with content like:

John|10|5|7
Alec|22|9|31
Mike|23|42|1

And I can retrieve all the values using explode and a loop. But for what I'm wanting to do is be able to get the values for one particular line rather than the entire. So how can I retrieve the values for one particular line?

Get Values From Textfield
as I am new to PHP my question is related to pure basics. I wrote
simple PHP file for automated mail sending. It sends, of course, mail
with fixed text but I need "mail()" function to retrieve string values
from textfield controls in Dreamweaver instead of fixed string values.

Option Values
From my experimentation there seems to be a difference when using values from an option value as apposed to an value by a check box etc. I can quite easily input data from a check box selection, but not an option value. Code:

SSL - No $_POST Values
The problem I had was sending posted data to a SSL secure Apache server and when getting the values using $_POST they were empty.

The cause of the problem can be found here http://bugs.php.net/bug.php?id=18759&edit=1
It seems that having enctype="multipart/form-data" in the form tag was causing the problem.

Matching GET Values...
I am trying to pass each GET variable to a function and check if it was
expected.
For example, here is a sample link:

index.php?name=modname&file=filename&func=1

the problem is, instead of returning:
match
match
match

it returns:

match
no match
no match
no match
match
no match
no match
no match
match

I know the problem is something with the =each, because it is evaluating
each item against each other, I just don't know how to fix it.

function bmcheck ($bmc, $g)
{
$bmchk = 0;
while (list ($key, $val) = each ($bmc)) {
if ($val == $g) {
echo "match";
echo "<br>";
} else {
echo "no match";
echo "<br>";
}
}
}

$bmc = array("name","file","func");
foreach ($_GET as $gvalue => $g) {
bmcheck($bmc, $gvalue);
}

Basically, when I'm done, if something like this was passed:
index.php?name=modname&file=filename&func=1&bad=notsupposedtobehere
then I would see 3 "matches" and 1 "no match" for the "bad" parameter.

Get ASCII Values
is there a php(inbuilt) function to get an ASCII value of a string? if isn't ,please explain how to do it I had wanted to send redirection from a page to another page
in same folder .used below code but didn't work though didn't show any error messages.could someone tell where it went wrong? Code:

PHP Null Values
NULL is converted to blank in php array when i use mysql_fetch_array . I want something where NULL  remains as it is in php array.

Variables Not Getting The Right Values
I have a form that has the ID values of various fields from listboxes, etc.,
which are generated from a db query, assigned to variables. The variables
hold the returned $_POST['fieldvalue'] fine, but I also need variables to
hold the labels. I have tried a few options such as running a secondary
query where the selected form value = the label, i.e.

-sample code-

//set variables:

$tooltype_id = $_POST['toolType'];
$toolcat_id = $_POST['toolCat'];
$primeproj_id = $_POST['project'];

//get group and project code and set variables

$query_groupcode = "SELECT groupCode, projCode from groups, proj WHERE
groups.groupID = proj.groupID AND proj.projID = '$primeproj_id'";
$groupname = $query_groupcode['groupCode'];
$projcode = $row_projects['projCode'];

//get tooltype codes

$query_toolpath = "SELECT toolType FROM toolType WHERE toolTypeID =
'$tooltype_id'";
$tooltype = $query_toolpath['toolType'];
- end code -

I then checked to see the variable values:

-code sample-
echo $tooltype_id.' tooltype_id<br />'
echo $toolcat_id.' toolcat_id<br />'
echo $primeproj_id.' primeproj_id<br />'
echo $groupname.' groupname<br />'
echo $projcode.' projcode<br />'
echo $tooltype.' tooltype<br />'
-end code-

this is the result - the data from the db comes across only as 'S':

2 tooltype_id
3 toolcat_id
5 primeproj_id
S groupname
S projcode
S tooltype

I'm sure this is just a stupid little error that I'm not seeing....or that
there is a reasonable way to collect the label values.

Reading Values From Url
what am I doing wrong? I've got a link like this:

<a href="dispcalendar.php?month=1&year=2007">view the calendar for the rest of the year.</a>then on dispcalendar.php I have: showYear($month, $year);But it doesn't seem to be reading the values sent in the url as I just get a blank page.

Getting Form Values
I have so far been trying to get all selected check boxes on the page, quantity text fields and ordernotes text area to INSERT INTO my database but to no avail. Im using OBDC to add to the confusion.

I've tried to develop my 'product' script into some kind of a form, but now need to find out how to make the data i want variable so that i can send them into my database. Code:

Incrementing Values? $var++
I want to be able to get the highest value from my user_id field in the database and increment it by 1. So highest user id is 104... next user will be 105 etc.

I have the below code but it doesn't seem to be doing. It just puts the value in as 1 all the time. the job.

$query = mysqli_query("SELECT MAX(user_id) `user_id` FROM `phpbb_users`");
$fetch= mysqli_fetch_assoc($mysqli_connect, $query);

$get_val= $fetch['user_id'];
$get_val++;

HTTP_ACCEPT_LANGUAGE Values
I'm trying to pull the language tag out of HTTP_ACCEPT_LANGUAGE in the $_SERVER superglobal, and while I'm certain of most of the regular english encodings, I don't know many of the international ones, is there anywhere I can find a full listing of all the country tags?

In particular I'm looking for Chinese. I've checked the HTTP 1.0 and 1.1 specifications and couldn't find a listing there. I've looked through some PHP references, even though this is in the Headers department.


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