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




Comparing Database Data And New Data


I am trying to create a PHP script that reads in a file, parses it for the data I want and compares it to the data I have in a database.

The data is points and ranking information for a Folding@Home Team.  Every week someone creates a news item with points gained by each team member for that week and other info.  This is done manually and takes a lot of time.  I hope for my script to automate as much of it as possible.

The script was to run as follows:

Download and parse latest statistics into 2D array
Compare usernames in array to usernames held in Database
Any new usernames and their respective points/rank to be added to database

Compare points in 2D array of each user to those held in database.
Output username and points gained

I thought I had a working script until I actually tested it on real data, and realised I missed something rather obvious - the order of usernames from the parsed file is not going to be the same order as in my database - due to people moving up and down the ranks.  So i can't just get a recordset from the db and run a simple loop to compare it to the parsed data.

I am not sure how to go about comparing the database information with the parsed data that works around the fact the data could be in any order.  The only thing i can think of is:

foreach item in $parsed_data_array
    query database for $parsed_data_array=>username
        if(number of results == 0)
          build new insert query for current username
        else
          continue

I don't know if this works [haven't tested yet] but I can't help feel it is a little DB intensive.  There could be up to 200 queries being sent to the database.  This can be minimized by adding extra criteria, like ignoring inactive users of course.  Is this a viable solution or is there a much better way of doing this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Comparing Form Data To Mysql Data
Im interested in building a script that would take form data, a variable like an address, and compare it with a known address in a mysql table (called addresses), then if there is a match log the address information in a separate table called (addresslog), and return the visitor to a certain page. If there is no match between the address entered in the form and known addresses then the information is still logged into the addresslog database but the visitor will be sent to a different page.

I'm still new to this, and am working through the logic and the syntax, but I believe I'm close. It's still not working, I have all of the proper tables, maybe I'm way off with the coding so I thought I would seek out some expert advice. Here's the entire script with as much explanation as I could give. PHP Code:

Comparing Data From A .txt File To DB Info.
I have a txt file that stores separate lines of information. Here is an example of one of the lines. Western Pleasure || height:>= 15, discipline:== 'western'

That is just telling me the qualifications of the "Western Pleasure" show type, which is that the height has to be greater than 15 and the discipline has to be western.

Now I am trying to take these qualification statements and compare them to values in the database, if  both qualifications match up, I would like to add the word "western pleasure" to an array. Here is my current code:

Getting Data From Database
I created a databae that i added greek text in it and when i try to get the data to echo in a table i get ?.Any help? I also set the collation of the table and the field to greek_general

Getting Data From Database
I have a database with a table named members with columns - id, member name, age etc..
Is there a way I can get the member name from the table members and store it in a variable $name without looping?

Getting Data From Database
I have a script to select data from a database and put it into a new url which the user gets automaticaly directed to that specific page. The problem is that its not getting the data to put into the new url. Code:

Checkbox Data In The Database
I want to display the checkboxes taken from the database from table “const_skills”, but the checkboxes and its values do not appear ($html_skills). Can anyone figure this out. Below is the codes that I’ve been using.
Thanks in advance.

<?php
include "dbinfo.php3";

function get_checkbox_labels($table_name) {
/* make an array */
$arr = array();

/* construct the query */
$query = "SELECT * FROM $table_name";

/* execute the query */
$qid = mysql_query($query);

/* each row in the result set will be packaged as
an object and put in an array */
while($row= mysql_fetch_object($qid)) {
$array[count($arr)] = $row;
}
return $arr;
}

/* Prints a nicely formatted table of checkbox choices.
$arr is an array of objects that contain the choices
$num is the number of elements wide we display in the table
$width is the value of the width parameter to the table tag
$name is the name of the checkbox array
$checked is an array of element names that should be checked
*/

function make_checkbox_html($arr, $num, $width, $name, $checked) {

/* create string to hold out html */
$str = "";

/* make it */
$str .= "<table width="$width" border="0">n";
$str .= "<tr>n";

/* determine if we will have to close add
a closing tr tag at the end of our table */
if (count($arr) % $num != 0) {
$closingTR = true;
}

$i = 1;
if (isset($checked)) {
/* if we passed in an array of the checkboxes we want
to be displayed as checked */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id"";

reset($checked);
while (list(, $entry)=each($checked)) {

if ($entry == $ele->id) {
$str .= "checked";
continue;
}
}
$str .= ">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}

} else {
/* we just want to print the checkboxes. none will have checks */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}
}
/* tack on a closing tr tag if necessary */
if ($closingTR == true) {
$str .= "</tr></table>n";
} else {
$str .= "</table>n";
}
return $str;
}
/* get the checkbox labels */
$skills = get_checkbox_labels("const_skills");

/* create the html code for a formatted set of
checkboxes */
$html_skills = make_checkbox_html($skills, 3, 400, "skills[]",$checked);
?>

<html>
<body bgcolor="#ffffff" text="#000000" id=all>
<br>
<form name="skills" method="POST" action="insertskills.php3">
Check off your web development skills:
<? echo "$html_skills"; ?>
<br>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Is There A Another Way To Retrieve Data From My Database
Is there another way I can retrieve and display the data in the
database. Am completely exhausted by this script.

Modify Data In A Database?
I am using PHP to add data to a MySQL database in an HTML form. Does anyone have any code to display all the records and click on one to modify it and update the data?

Trying To Insert Data In A Database
I am trying to insert data in a database
Code:

How Do You Add Data To A Database Via A Form?
I have a mysql database and I'm using PHP to access it. Has anyone got a piece of code that will allow me to use an HTML form to add data to the database?

Inserting Some Data Into Database..
The code I have at the moment creates directories (mkdir) and copys files into them. This seems to work, but I need the variables "$mypath" and "$newfile5" to be inserted into my database. But it won't. It enters the other data such as name and description and creates the folder. Code:

Sending Data To My Database
I have ms access database (im know mysql is better but please bare with me) and within it  is a product list. That product list is called and displayed on my product page. After the price of an item has been echo'ed out i have a small text field where the user of the system is required to type the product id ($ProductId) on all the items they wish to select and then proceed to click submit.

Once the submit button has been pressed i want to send all of the data typed into the little text fields into a single cell separated by commas in the database. I have some basic code that doesn't correctly do what i want it to. If more than 3 products are listed on a page and i type the product id for any items not in an order E.g.

Product 1  <----i want this one
Product 2
Product 3
Product 4
Product 5 <-----I wantthis one

I just get ',,,' sent tothe database however if i type product id like this:

Product 1  <----i want this one
Product 2  <----I want this one as well
Product 3  <----i want this one too
Product 4
Product 5

I get 1,2,3 sent into the database. Code:

Retriving Data From A Database
I have code that lists a number of people from a data and stores it array

// select people from first table who are part of group 1
$query= "SELECT personID FROM people WHERE groupID = 1";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while ($row = mysql_fetch_array($result) {
$personid = $row["personID"];}

The problem is I do not know  how many records it will return.
I then need to enter all these people into another table.

// add people to second table who are part of  group 1
$people = 0;
while ($people != $numrows) {
$query2 = "INSERT INTO people2 (peopleID, groupID) VALUES ('$personid',  '1')";
$queryaddperson = mysql_query($query2) or die(mysql_error());
$people++;}

Rather than add every single person who is part of group 1 it just keeps adding the first person over and over again to the people2 table.

Got Data From Database But Doesn't Show
I get data from a database and I need to put in a table.

the table dynamically adds rows depending on the results from the database.

So my rows are getting created but their's nothing in their.

What can be the problem here? Code:

Truncated Data From Textarea Box To Database
I have a simple form with a textarea box. The user is supposed to cut/paste text from documents into the textarea box, which is then added using php as a record to a MySQL column of data type mediumtext. The problem - the text keeps getting truncated at about 1800 characters (sometimes more, sometimes less).

PHP And SQL Encrypting Data Before Sending To Database
I know it is possible but dont know how to do it!

how can you encrypt data using php before sending it to a MySQL database (e.g password) and then dycrypt it when retriving it.

Extracting Data From Database Using Three Strings
I am a complete newbie. I have been working on a self-learning project that will ask users for three strings (i.e. name,dob and number. If details are correct, will vector to a new page and display all their other information unique to their name,dob and number. The second page will then display their school,work,address, etc. which is editable. They will then click the submit button at the bottom to save the displayed data (or any changes they made to it) in the database from where it was initially extracted from.

Here is the php for the first page which asks the name,dob and number:

Retrieve Data From The Database And Populate
I know how to fill data in text boxes and submit to the database and retrieve from the database. But how do you retrieve data from the database and populate a drop down menu?

Data Not Posting To My Database Php/mysql
I am having a problem postion data from my form into my database. My users visit my site and fill out a form which is suppose to go into my mysql. I check phpMyAdmin to see if the data got there but nothing. Below is my Code. could someone help me out. Code:

How Do You Send Data To A Database Via Checkboxes?
I am using PHP to send and retrieve data from a MySQL database via HTML forms. I am using text boxes and everything is fine.

If I have a page with checkboxes on, and the users check them and click on the submit button, how does this show up in the database? Nothing seems to show up for me.

Data Format In Application Or Database?
I have found that by far the easiest way to store dates in my LAMP
application is in a text string in the database in Unixtime format.

First of all, what would be the most efficient data type to store this as?

Secondly, in terms of translating into a human readable format, is it
quicker to format the date in the application using date() or in the
database in the select query?

How To Display Data From Database In Different Web Pages?
When we get data from database by use mssql_query(),suppose the data is very large ,it has many rows, and we want display the data in different web pages like many search engines do, my question is how to do that using the same result without call mssql_query() again?

Form Data Not Stored In DataBase
I was trying setting up these scripts following instructions in a book from 2003, so I thought maybe some of the code might be outdated.

Basically this is what Is supposed to happen:
1.- Display a form, enter details into fields and click submit.
2.- After having clicked on submit you're redirected to another page that will display the entered values and store them in the MySQL DB specified.

Now what happens is that no errors are displayed after clicking on the submit button in the form, but neither are the entered values. In PHPMyAdmin I can see that the Db is still empty. I created a total of 3 files that reside in the same folder: The form, that when clicking on submit is redirected to the next file: Code:

Mailing Data From Mysql Database
I have searched, but didnt find what I need. I am trying to mail someone if a user changes data in my MySQL database, which is being written to by a php script. All is set up, just need to be notified of what data got changed.

Ok Problems Entering Data Into Database
i am having problems if you look at the script below you will
see that it the query has 4 values to insert but the actual values only
contain title entry and now() for the date. well i have made the
database and the blog_id is a primary auto interger what ever table
bascly look below the the insert code block to find the code block
that makes the table in the database,

// Define the query.
$query = "INSERT INTO blog_entries (blog_id, title, entry,
date_entered) VALUES ('{$_POST['title']}', '{$_POST['entry']}',
NOW())";

// Execute the query.
if (@mysql_query ($query)) {
print '<p>The blog entry has been added.</p>'
} else {
print "<p>Could add the entry because: <b>" . mysql_error() . "</b>.
The query was $query.</p>";
}

---------------------------------------------------------------------------------------------------------------------------------------------------

// Define the query.
$query = 'CREATE TABLE blog_entries (
blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
entry TEXT NOT NULL,
date_entered DATETIME NOT NULL
)'

// Run the query.
if (@mysql_query ($query)) {
print '<p>The table has been created.</p>'
} else {
die ('<p>Could not create the table because: <b>' . mysql_error() .
'</b>.</p><p>The query being run was: ' . $query . '</p>');
}

Quote:

Writing Data To MySQL Database Using PHP
Can anyone tell me why the following code isn't working?

$dbh = mysql_connect($host,$user,$pass) or die("Couldn't connect...");
$selected = mysql_select_db($db,$dbh);
$name = $_GET['name'];
$state = $_GET['state'];
$desc = $_GET['desc'];
$lat = $_GET['lat'];
$lng = $_GET['lng'];
$result = mysql_query("INSERT INTO re_cities (name, state, description,
lat, lng) VALUES ('$name','$state','$desc','$lat','$lng')");

The script doesn't die when I attempt to connect so I'm assuming that
isn't the problem. I'm pretty sure I also get a result because the
following code echoes "City Add Successful".

if ($result) {
echo "City Add Successful";
} else {
echo "City Add Unsuccessful";
}

However, the data doesn't show up in the database.

Calculating Some Formulas From Database Data
I am doing a project on beetle diversity and need to calculate a few
diversity indices for a load of data i have collected. I thought that
maybe i could make a program in php to do that for, and save a bit of
time (as well as prevent calculation errors). I imagine this could be
quite a bit of programming but i have dreamweaver to help me.
Now what i have is a MySQL database full of data on beetle diversity
with the following tables:

Date - the date the sample is from
Habitat - one of 9 habitats that i am testing between (ie. grass,
stones, birch woodland, etc)
Replica - ie 'Repeats', there were two replicas for each habitat from
each date (A and B)
Trap number - from each replica there were 6 traps
Species - the species of beetle that was found in the trap (of course
there are often more than one per trap)
Number of Individuals - the number of individuals of that species
found in that trap

What i need to do is calculate Shannon-Weiner, Shannon Equitability
and Margalefs Diversity indices for each replica from each date for
each habitat (the data for the individual traps will be merged
together).
I have an idea of how to do it but what i am stumbling at is how to
create a recordset which will calculate the total number of
individuals for that species from that replica, date & habitat (I) and
calculate the number of different species for that replica, date &
habitat (S). Once i have S and I i should be able to write the formula
in php to create the indices.
Ideally this could be done in a way to allow for each repeating areas
to be assigned so that all of the indices for that habitat (for each
date and replica) could be shown on one page (to save a lot of
clicking).

Using Session Data To Query A Database
Basically the title is the general idea of what i'm trying to do, a user logs in, great, his login id is stored (it is also his number on a seperate database) in a session variable. Now that session variable needs to be queried to another database (with all of that users information) to get all of the information on that user back to the original server (not the first database, the first database just has user number, id, and a password field).

So I have a  question, and if you have answers great! or if you know of the thread that they are on that would also help because i've been searching and haven't found anything yet.

1. How can I query a session variable in a sql statement, do I just put select * from users where '.$_SESSION['mysessionname'].' = usernumber ?

Form Data Not Stored In Database ?
This is the code for a Returns form where I am trying to implement these validations:

1. Check if fields aint empty
2. Check if SESSION_username = username from Customer table and get customer ID
use that Customer ID to look up Orders table and find if the ORDER NO. that has been entered is = an order no. in the Orders table
i.e. see if the oder no. entered was actually an order placed by the user b4

* Customer table has cust id and username. Order table has only cust ID. returns table will store username from Session so that it can display each user's individual returns. Code:

Inserting Data Into Database With Use Of Variables
this code insters data correctly into the 1st table but not the second. I bet a simple modification is required but i cant figure it out - ive tried many things: Code:

Check Mysql Database For Data
Need to check if some info matches from mysql database in two tables to see if the current session user is on a friends list for the profile page he or she is viewing. If they do not exist in field, return an error. Here is the structure and what i got so far: Code:

Delete Data From MySQL Database
I am new to PHP and MySQL but I have setup a MySQL database. I can view the information in an HTML table using PHP scripts and can delete an entry form the database table, but what i need to do is to be able to delete an entry by selecting a radio button next to the relevent information however when i try to add a form in the PHP script i get an error.

Selecting Data From Database(php/mysql).
Alright I've come to a point where I only want a DB for settings and nothing based on ID's on a sql table.

instead of say:

$setting = mysql_query("SELECT * FROM settings WHERE id='1' ");

Now i broken up all the sql into seperate settings like so:

settingname | value

boardonline | no

Thats basicaly how I got the sql set up instead of having it all in one table row I have them in seperate rows.

So how do I go about selecting data from SQL not based on ID but mainly on setting name? would I do

$settings = mysql_query("SELECT * FROM settings");
$settings = mysql_fetch_array($settings);
$settings['boardonline'][1];//would echo true/false according to my sql table instead of the row name?

Arrays And Inserting Data In To The Database
I have a form that uses two arrays one get's a list of courses from the database and one creates dates... i have two questions

1. how do i get the $i and $d value off of the arrays to insert in to the database, but still have each know they belong in the same row?

2. how do i change the dates from a multiselect dates ie, Jun 3, Jun 6, and Jun 12 to 'Jun 3, 6, 12'

here is the snippet of code from my select page. $numposts is a value selected on an earlier page. Code:

Create Checkboxes From Database Data
I'm trying to create checkboxes from a database table header row and then pass that to another page.

The checkboxes are gotten from the "header" row of the mysql table.
I check which of these checkboxes are selected and if it is selected, I display the data for the rest of the rows under that same column which is selected as a checkbox. Here's the code to generate the checkboxes:

Inserting Checkbox Data Into A Database
Typically, checkbox inputs have a name value of an array (something like <input name="options[]" type="checkbox" />).  Is there an easy way for me to extract the values of such an array and insert them into the right database column?  Or should I just bite the bullet and give each checkbox input a unique name so I save myself some confusion/readability?

Retrieve Randomly Data From Database
I have store in a database some question with four answers for each question.
I want retrieve randomly 20 questions from the database. Also I have to mix the answers as I echo them out… Do you have any idea how can I do this?

Add Data To A Database Using Dropdown Menus?
lets say i had a database with a table called admin hacks and another table called user hacks,and both tables had feilds called name and id

now what i want to be able to do is create a submit form with a drop down menu saying the table names mentiond above, also the form will have a field called name.

now lets say a user slected admin hacks from the drop down menu and enterd jack in the name, how would i get the data in that submitted form to be inserted into the correct database table, so jack should now be in the table called admin hacks

also lets say someone selected user hacks and entered jon how would i do the same for that?

Inserting Data From A Sql Database Into An Array
I am currently working on a project where I need to put information from a sql statement into an array.  Currently I can get one row into the array, but the rest aren't showing.  I have checked, and all of the information is getting to the array, but I can only get one row to show up. 

Here's the code:

  while(($row = mysql_fetch_array($result)))
  {
   $info=array($count=>array('line1'=>$row["first_name"], 'line2'=>$row["last_name"], 'line3'=>$row["product"], 'line4'=>"$".$row["date"]));
   $count++;
  }

I'm trying to get this array to hold multiple rows from the sql statement, but when I display the array, I can only get one row out of it.

Getting Data From Database And Turning Into Variables?
how i can get something from a database and turn it into a variable. Not anything like a table or anything, something like a persons ID.. if there is a table for members and then there is a field called ID asweell as things like username, email ect... how do i get the ID and use it.

I do not want a certain ID, i want the ID of a person logged in at that time, so say they left a message on a guestbook, i could display there ID next to them by simply putting a variable like $member_id.

Simulate Send Data With POST And Get Data From A Web Page (whith A Session)
I'd like to get text of a webpageB that I reach by putting
a login and a password in a webpageA.

I mean:
I'd like to get text of a WebPageB with a php script.
But before I can see WebPageB I have to autenticate myself
in a WebPageA writing my login and my password in a form,
the host recognise me and (by session) let me see the WebPageB.

The question is:
1)how to simulate send data (login an password) in form with a PHP script?
2)how to navigate in a Web usin the same session?

Name Of File That Stores MySQL Database Data
I need to recover my database from a backup after a system crash. What is the file name (extension) that stores the database information?

Import Data From Access Database To MYSQL
I have some data in access database. I wish to import it (keeping the same structure) in MySQL.

Also I want to know what will be procedure for importing data from databases like Oracle, Sybase, Informix etc.

Dynamic Insert Of POST Data Into Database
I have two tables one with game data ie visitor team home team so on and so forth and one with team name and team id, this info is pulled into a dynamic form. I can get the data from the form ok

foreach($_POST as $key => $value){
echo "$key:$value";
}

when I echo the info it gives me the correct output

game1:7 game1id:513
game2:14 game2id:514

I have columns in the database that correspond to the form var fields What my question is is how do I get the info into the database through each iteration in one row?

This is an example I have tried and I know doesn't work

$sql = "INSERT INTO teampicks ($key) VALUES('". $value ."')";
$res = mysql_query($sql);

Entering Data From A Form To A Mysql Database
I'm trying to enter data from a form with the fields name and email into a mysql database called newsletter, as you guess it's a newsletter sign up. this what I have at the moment: Code:

MYSQLDUMP, Create New Database, Before Restoring SQL Data.
I can use mysqldump to create a .sql file backup of my data.

For importing how can I test to see if the DB exists, if it does
import the .sql

If not create the DB then import the .sql!

Inserting Data Via Browser(textarea) Into Database
I just wanted to make something that creates html-code which should be
inserted in a mysql database.

The user should type text in a textarea. When the user submits the data,
all enters should be translated into "<br>" and it would be nice if the
user could also insert links ( "<a href="..." ) in the formular.

Does someone knows a good, very simple script? There are wysiwyg editors
on the net, but I don't need to modify fonts, colors et cetera. The most
important thing are the "<br>" tags which should be generated.

How Do You Extract Data From The Database And Save It To A Variable
How do you take data out of the database for a particular field (the field will be of BLOB data type) and save it to a variable.?

Can I Use PHP For Selecting And Writing Data Into A Server-database?
I like to build a small simple dinamic website: Point-of-sale
(detail-shop), So entering stock, logging all sales, print out
invoices and download the logs to be imported into Excel.

I once could write a bit in ASP/SQL/HTML/JAVASCRIPT and even some
Excel-VBA but have lost most knowledge about that and I never know a
lot nor did I know how to set up a simulating PC to write and test the
website.

I don't want to spend much money buying Microsoft product, so I've
heard that PHP with MySQL can do it for free, right? But all I find is
that PHP can look up data in a file on the server and send dinamicly
changed HTML, but can it also write data on the servers data-bases?
Can I make a link on the site to download some requested data like the
sales-log in 1 text or Excel-file?
How much data can MYSQL with PHP handle? What about 1.000.000 sales
and finding a product within 100.000 products?


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