I need a way to convert a number into formatted way by inserting comma at suitable places. Can it be done using regex?
Example:
12345 => 12,345
1234567 =>1,234,567
SO I am trying to create a way to structure my database to be able customize forms.
I looked into EAV pattern and here is my db structure:
Table form
- form_id
- form_name
- form_added_on
- form_modified_at
Table: form_fields
- field_id
- form_id
- field_type (TEXT, RADIO etc..)
- field_default_value
- field_required
Table: form_data
- data_id
- field_id
- form_id
- field_value
so now I can store any custom form into the database and if I want to get the values for an individual form I can simply join it by "form_id" ..
the problem:
I want to be able to search through all the forms for a specific field value.
How can I do that with EAV model?
Also, I thought about just storing the custom data as a serialized (JSON) object but then I am not sure how can I query that data.
Please note that I am using Codeigniter with MYSQL. So if conversation can use Codeigniter libraries if needed.
Hello, can't understand mysql error:
UPDATE static_pages SET order = " Some
new data 222222
"Database error: You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'order = "
$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';
Here is $key = order; $value = 'new data 222222';
There is such keys in table: order, prices, contacts. Each of these updates well except the 'order'. Why?
so I have lots of users posting articles with names in different languages. I need some lib to translate thouse article names to english letters for example turn russian '?' into eng 'r' and so on for all european languages, russian and asian languages. Where to get such lib?
i need some code which can delete/filter arrays which doesn't contain a specific word
or we can say keep only that contain a specific word and drop all other ones
Hello,
I am using this IP Validation Function that i came across while browsing, it has been working well until today i ran into a problem.
For some reason the function won't validate this IP as valid: 203.81.192.26
I'm not too great with regular expressions, so would appreciate any help on what could be wrong.
If you have another function, i would appreciate if you could post that for me.
|--------------------------------------------|
The code for the function is below:
|--------------------------------------------|
public static function validateIpAddress($ip_addr)
{
global $errors;
$preg = '#^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}' .
'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#';
if(preg_match($preg, $ip_addr))
{
//now all the intger values are separated
$parts = explode(".", $ip_addr);
//now we need to check each part can range from 0-255
foreach($parts as $ip_parts)
{
if(intval($ip_parts) > 255 || intval($ip_parts) < 0)
{
$errors[] = "ip address is not valid.";
return false;
}
return true;
}
return true;
} else {
$errors[] = "please double check the ip address.";
return false;
}
}
I have a select menu that displays countries. It looks at the DB and judging by the value in the db shows the option as selected. Is there a simpler way off doing this than:
if ($country == 'AG') {echo '<option value="AG" selected="selected">Antigua</option>';}
else {echo '<option value="AG">Antigua</option>';};
if ($country == 'AR') {echo '<option value="AR" selected="selected">Argentina</option>';}
else {echo '<option value="AR">Argentina</option>';};
if ($country == 'AM') {echo '<option value="AM" selected="selected">Armenia</option>';}
else {echo '<option value="AM">Armenia</option>';};
if ($country == 'AW') {echo '<option value="AW" selected="selected">Aruba</option>';}
else {echo '<option value="AW">Aruba</option>';};
if ($country == 'AU') {echo '<option value="AU" selected="selected">Australia</option>';}
else {echo '<option value="AU">Australia</option >';};
if ($country == 'AT') {echo '<option value="AT" selected="selected">Austria</option>';}
else {echo '<option value="AT">Austria</option>';};
if ($country == 'AZ') {echo '<option value="AZ" selected="selected">Azerbaijan</option>';}
else {echo '<option value="AZ">Azerbaijan</option>';};
if ($country == 'BS') {echo '<option value="BS" selected="selected">Bahamas</option>';}
else {echo '<option value="BS">Bahamas</option>';};
if ($country == 'BH') {echo '<option value="BH" selected="selected">Bahrain</option>';}
else {echo '<option value="BH">Bahrain</option>';};
There are a lot of countries and doing this would be madness wouldn't it????
My application requires the user to enter their business name, which the application will automatically create into a unique identifier to be used in URLs, ie
"Bob's Cafe" will become "bobs-cafe"
But if there are duplicate names I would like the application to add a number so if there is already a "bobs-cafe" we will use "bobs-cafe-1" and likewise if there is already a "bobs-cafe-1" we will use "bobs-cafe-2"
Ive used explode and also looked at a regular expressions but I dont know the best way to approach this.
Im stuck in being able to grab the number and incrementing it and returning the string
array(
[0]
name => 'joe'
size => 'large'
[1]
name => 'bill'
size => 'small'
)
I think i'm being thick, but to get the attributes of an array element if I know the value of one of the keys, I'm first looping through the elements to find the right one.
foreach($array as $item){
if ($item['name'] == 'joe'){
#operations on $item
}
}
I'm aware that this is probably very poor, but I am fairly new and am looking for a way to access this element directly by value. Or do I need the key?
Thanks,
Brandon
Is it necessary to validate a name or street address? when I have it coded in the following format. And if so why?
$address = mysqli_real_escape_string($mysqli, htmlentities($_POST['address']));
$name = mysqli_real_escape_string($mysqli, htmlentities($_POST['name']));
What I need to do is have a data structure that shows jobs organised into 14 day periods, but only when an id is the same. I've implemented all sorts of stuff, but they have failed miserably.
Ideally, maybe a SQL expert could handle all of this in the query.
Here is some of my code. You can assume all library stuff works as expected.
$query = 'SELECT date, rig_id, comments FROM dor ORDER BY date DESC';
$dors = Db::query(Database::SELECT, $query)->execute()->as_array();
This will return all jobs, but I need to have them organised by 14 day period with the same rig_id value.
$hitches = array();
foreach($dors as $dor) {
$rigId = $dor['rig_id'];
$date = strtotime($dor['date']);
if (empty($hitches)) {
$hitches[] = array(
'rigId' => $rigId,
'startDate' => $date,
'dors' => array($dor)
);
} else {
$found = false;
foreach($hitches as $key => $hitch) {
$hitchStartDate = $hitch['startDate'];
$dateDifference = abs($hitchStartDate - $date);
$isSameHitchTimeFrame = $dateDifference < (Date::DAY * 14);
if ($rigId == $hitch['rigId'] AND $isSameHitchTimeFrame) {
$found = true;
$hitches[$key]['dors'][] = $dor;
}
}
if ($found === false) {
$hitches[] = array(
'rigId' => $rigId,
'startDate' => $date,
'dors' => array($dor)
);
}
}
}
This seems to work OK splitting up by rig_id, but not by date. I also think I'm doing it wrong because I need to check the earliest date.
Is it possible at all to do any of this in the database query?
To recap, here is my problem
I have a list of jobs with all have a rig_id (many jobs can have the same) and a date.
I need the data to be organised into hitches. That is, the rig_id must be the same per hitch, and they must span a 14 day period, in which the next 14 days with the same rig_id will be a new hitch.
Can someone please point me on the right track?
Cheers
Here I have a variable 'response' which is obtained by parsing an XML file.
$url = 'http://xxxxx.xml';
$ch = curl_init($url);
$response = curl_exec($ch);
The url structure is as follows -
<user>
<id>734</id>
<name>Peter Parker</name>
-
<status>
<favorited>false</favorited>
</status>
</user>
How to access each bit of info like id,name,favorited from response?
This article states that
If your site is run on a shared Web
server, be aware that any session
variables can easily be viewed by any
other users on the same server.
On a larger host like GoDaddy, are there really no protections in place against this? Could it really be that easy? If it is that easy, where are the session vars of the other users on my host so I can check them out?
Edit: I didn't believe it, but here's my little program which shows that this is true! I wonder if those are really the same as the value stored in the cookies on the users' machine?
Hi guys,
I've got this code
mysqli_query ( $userdatabase,
'CREATE TABLE `user_'.$emailreg.'` (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
IP varchar(10),
FLD1 varchar(20),
FLD2 varchar(40),
FLD3 varchar(25),
FLD4 varchar(25),
FLD5 varchar(25) )' );
echo ( mysqli_error ($userdatabase) );
that works fine on my localhost, but when I upload it to the server, it starts giving me a "Incorrect table name '[email protected]'" error. any idea?
Thanks!
MySQL
$selectSize = "SELECT * FROM products";
$querySize = $db->select($selectSize);
while ($product = $db->fetcharray($querySize)) {
HTML
<ul>
<li>Product A</li>
<li>Product B</li>
<li class='right'>Product C</li>
<li>Product D</li>
<li>Product E</li>
<li class='right'>Product F</li>
</ul>
Question
While getting the product, I want the Product C and Product F or any product after 3 loops will have class='right' to the list style. Let me know
Thanks
Hi,
I was wondering how I could sort this array, when I use asort right now it does
14
17
16
15.
How would I go to have
14
15
16
17
array(4) {
[15]=> array(9) {
[2025]=> string(80) "20:25 à 21:15 Spectacle / L'histoire d'un coeur / Auditorium, É.S.P. De La Salle"
[2135]=> string(71) "21:35 à 22:25 Spectacle / Transfugue 2 / Auditorium, É.S.P. De La Salle"
[1430]=> string(64) "14:30 à 15:30 Mise en lecture/Théâtre la Catapulte / De La Salle"
[110]=> string(44) "11:00 à 13:00 Inscription / Pavillon Tabaret"
[1330]=> string(49) "13:30 à 14:30 CÉRÉMONIE D'OUVERTURE / De La Salle"
[1550]=> string(61) "15:50 à 16:40 Spectacle/Université Laurentienne / De La Salle"
[170]=> string(57) "17:00 à 17:50 Spectacle/Université d'Ottawa / De La Salle"
[1750]=> string(45) "17:50 à 19:00 REPAS DE L'AMITIÉ / De La Salle"
[1915]=> string(76) "19:15 à 20:05 Spectacle / Attendre la pluie / Auditorium, É.S.P. De La Salle" }
[16]=> array(8) {
[1845]=> string(81) "18:45 à 19:35 Spectacle / Mimes d'horreur / Salle Académique, Université d'Ottawa"
[1955]=> string(73) "19:55 à 20:45 Spectacle / Déroute / Salle Académique, Université d'Ottawa"
[8]=> string(45) "08:30 à 11:30 Atelier / ABC du jeu dramatique"
[13]=> string(41) "13:00 à 16:00 Atelier / Théâtre physique"
[1130]=> string(28) "11:30 à 13:00 DÎNER LIBRE / "
[1620]=> string(29) "16:20 à 18:20 SOUPER LIBRE / "
[220]=> string(58) "22:00 à 23:30 BAL MASQUÉ / l'Agora du centre universitaire"
[210]=> string(47) "21:00 à 22:00 Rétroaction / Université d'Ottawa" }
[17]=> array(4) {
[950]=> string(79) "09:50 à 10:40 Spectacle / Raison d'être / Salle Académique, Université d'Ottawa"
[110]=> string(76) "11:00 à 11:50 Spectacle / Potionnée / Salle Académique, Université d'Ottawa"
[120]=> string(28) "12:00 à 13:00 DÎNER LIBRE / "
[1330]=> string(48) "13:30 à 14:30 CÉRÉMONIE DE CLÔTURE / De La Salle" }
[14]=> array(1) {
[150]=> string(49) "15:00 à 16:30 Préparation technique / De La Salle" } }
Hey,
Im really interested in the way of using lamda functions. Does it make sense to use them in a high-level programming language? If yes, why?
Is this really just a function embedded in a function, (Like this) or is there more behind?
I'd think there was a question on this already, but I can't find one. Maybe the solution is too easy... Anyway, I have a flat-file and want to let the user change the values based on a name. I've already sorted out creating new name+value-pairs using the fopen('a') mode, using jQuery to send the AJAX call with newValue and newName. But say the content looks like this:
host|http:www.stackoverflow.com
folder|/questions/
folder2|/users/
And now I want to change the folder value. So I'll send in folder as oldName and /tags/ as newValue. What's the best way to overwrite the value? The order in the list doesn't matter, and the name will always be on the left, followed by a |(pipe), the value and then a new-line.
My first thought was to read the list, store it in an array, search all the [0]'s for oldName, then change the [1] that belongs to it, and then write it back to a file. But I feel there is a better way around this? Any ideas? Maybe regex?
I need to get a total count of JPG files within a specified directory, including ALL it's subdirectories. No sub-sub directories.
Structure looks like this :
dir1/
2 files
subdir 1/
8 files
total dir1 = 10 files
dir2/
5 files
subdir 1/
2 files
subdir 2/
8 files
total dir2 = 15 files
I have this function, which doesn't work fine as it only counts files in the last subdirectory, and total is 2x more than the actual amount of files. (will output 80 if I have 40 files in the last subdir)
public function count_files($path) {
global $file_count;
$file_count = 0;
$dir = opendir($path);
if (!$dir) return -1;
while ($file = readdir($dir)) :
if ($file == '.' || $file == '..') continue;
if (is_dir($path . $file)) :
$file_count += $this->count_files($path . "/" . $file);
else :
$file_count++;
endif;
endwhile;
closedir($dir);
return $file_count;
}
I'm looking for the alternative of mysql_real_escape_string() for MSSQL. Is addslashes() my best option or there is another alternative function that can be used?
Edit: Alternative for mysql_error() would also be useful.
hi
i want know find the directory is already there or not...
if not i would like to create the directory...
my coding is below...
$da = getdate();
$dat = $da["year"]."-".$da["mon"]."-".$da["mday"];
$m = md5($url)."xml";
if(is_dir($dat))
{
chdir($dat);
$fh = fopen($m, 'w');
fwrite($fh, $xml);
fclose($fh);
echo "yes";
}
else
{
mkdir($dat,0777,true);
chdir($dat);
$fh = fopen($m, 'w');
fwrite($fh, $xml);
fclose($fh);
echo "not";
}
thanks and advance
Not sure how to go about this...
But, I have two arrays, one with updated information, another with outdated information... There are a lot more elements in the second array, but I'm looking to "update" the outdated one with the updated information.
Here's what the arrays look like:
//Outdated
Array (
[0] => Array
(
[anum] => 3236468462
[cid] => 4899097762
[mid] => 1104881401
[na_title] =>
[na_fname] => JOHN
[m_initial] =>
[na_lname] => DOE
[na_suffix] =>
[na_addr1] => 1234 SAMPLE AVENUE
[na_addr2] =>
[na_city] => NORWALK
[state] => OH
[zip] =>
[zip_plus_4] =>
[route] => R002
[dma_code] => 510334
)
)
//Updated
Array (
[1] => Array
(
[0] => YUD990
[1] => 98
[2] => 1234 Sample Avenue
[3] =>
[4] => Norwalk
[5] => OH
[6] => 44857-9215
[7] => 3236468462
)
)
To clarify, I want to:
(1) Match up the value for [7] from the updated array with the value for [anum] in the outdated array, and then update [na_addr1], [na_addr2], [na_city], [state], [zip], [zip_plus_4] in the outdated array with the values for [2],[3],[4],[5],[6] (I know I'll need to split the updated [6] in order to get it to map corrected to the outdated)
Feel like I'm making this very confusing... sorry about that...