Jump to content

Modify Mysql - Find/del/copy/move Variables


InfiniteWarrior

Recommended Posts

At the moment I have a database with a variable located at the bottom of every entry.... there are 10,000 entries which need to have the variable moved or copied to another field column corresponding with each entry...... The variable is always located in a specific segment of text which looks something like this.... <b>String: # xxxx.xx</b> - so if the script could locate the phrase <b>string: # and then retrieve the subsequent number, and move or copy that number into a corresponding field on the same table of the MySQL database, this would be extremely useful....,, and save me days of data-entry.... I barely know any PHP, yet I did take computer science and study Java and Perl 6 years ago...... so I understand basic coding principals....

 

Could anyone point me in the right diection of basic PHP scripts or functions which can help me work in MySQL databases..?

 

Love & Light

Link to comment
Share on other sites

Unfortunatly, I am still learning PHP, but www.w3schools.com offers a great list of commands that you can uses with php and mysql databases. Maybe reading the PHP section will help you in your journey.

 

Love & Light,

 

Brett Hartel

 

Unfortunately w3schools uses out of date material with security not in mind. I would not suggest using them as a beginning into php

Link to comment
Share on other sites

Been looking, found basic MySQL functions and whatnot..... this isn't the issue....

 

I basically just need a way to search and replace the text...... can anyone show me a script to locate a string of text, and return a decimal value number which follows the string of text.... , which is a numeric decimal number between 4 and 7 characters in length?

 

Then I need to find a way to repeat this for every field in a table or to parse one large text/excel file and return a list of values for every instance of the specific string in question..... I would pay someone if I could I am just broke.....

Link to comment
Share on other sites

The issue is how to define the variable as a strictly numeric decimal number in that length range which follows the occurrence of a separately defined variable which is the string of text which always precedes the decimal number..... parsing a file and outputting data is relatively easy.. I'll figure it out eventually.....

 

something like variable $string = "<b>string: # "

then the variable following the string needs to be defined as a decimal number with a length of 4-7 characters

then that variable needs to be returned, and placed into a text file on a single line....

 

I am unfamiliar with any php syntax.... I am figuring it out.

Link to comment
Share on other sites

Ended up finding a way basic function in OpenOffice Calc to return a variable from a string...., using the mid, left, and right functions built in...., then modifying further with there to whittle away the unneeded characters with advanced search and replace functions, as the string length was variable in number of characters... only explaining because I know people will be searching similar inquiries in the future on google so always positive to post solutions, didn't have time to learn PHP in one night.

Link to comment
Share on other sites

You could solve this is two ways with PHP, which you should use depends a bit on the details of the pattern you want matched.

 

The quickest method, but also the most technically complex, is by using Regular Exp<b></b>ressions. They'll allow you to create a pattern rule, to match (and retrieve) whatever you like in regular text. Your example is border-line, as it contains HTML.

To get the IDs from your example, something like this should suffice:

$RegExp = '/String: #(\\d+(:?\\.\\d{1,2})?)/';
if (!preg_match_all ($RegExp, $Data, $Matches)) {
  die ("Could not find any IDs in data.");
}

That RegExp will search for the text "String: #", followed by one or more digits (\d, + means "one or more"), potentially followed by a period (\.) and one or two digits (\d{1,2}). Then it'll save the results the array $Matches, so that you can loop through it and do whatever you wanted with the values. ;)

 

The other, possibly more proper, method in this case would be to use the DOMdocument class. Click on the link to learn more about it.

Edited by Christian F.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.