Tuesday, 10 September 2013

Adding multiple columns to MySQL table using PHP loop

Adding multiple columns to MySQL table using PHP loop

My objective
To add a number of columns to a MySQL table. I have two concerns:
1) How to do this
2) Is this a bad idea, and if so why?
My reason for wanting to do this:
I have a form with a systematically named set of fields (e.g. field_1
field_2 etc). I want to post that data to a page and have it store it the
mysql table, and I would like the fields to enter columns of a
corresponding name (i.e. columns are named field_1 field_2 etc)
Rather than manually creating a column for each field name manually, it
seemed obvious to loop the task.
However, research here and here seems tells me this approach illicits
horror from people, and I found no actual solutions.
My attempt:
$mysqli = new mysqli("localhost","user","password","db");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$i = 1;
while ($i <= 14)
{
$column = 'field_'.$i;
$sql= '"ALTER TABLE supply ADD '.$column.' VARCHAR(45)"';
$mysqli->query($sql);
printf("Affected rows (ALTER): %d\n", $mysqli->affected_rows);
$i++;
}
This seems to run without error, however the affected rows message gives
me (per loop, so 14 of these):
Affected rows (ALTER): -1
and the columns are not being added.
Can anyone advise me of my error, or a better way to debug what is going
wrong? Additionally if this is an unwise thing to be doing could could you
explain why and what I should consider doing instead? Thank you.

How to change form default button?

How to change form default button?

I have input fields inside the form as follows:
<h:inputText binding="#{MyBean.text1}" />
<h:inputText binding="#{MyBean.text2}" />
<h:inputText binding="#{MyBean.text3}" />
<h:inputText binding="#{MyBean.text4}" />
<h:inputText binding="#{MyBean.text5}" />
<h:inputText binding="#{MyBean.text6}" />
<h:inputText binding="#{MyBean.text7}" />
<h:commandButton value="search1" action="#{MyBean.search1}"
onclick="return validate();"></h:commandButton>
<h:selectOneListbox binding="#{MyBean.cboDepartment}" id="cboDepartment">
<f:selectItems binding="#{MyBean.cboDepartmentSelectItems}"
id="cboDepartmentSelectItems"
value="#{MyBean.cboDepartmentDefaultItems}" />
</h:selectOneListbox>
<h:commandButton value="search2" action="#{MyBean.search2}"
onclick="return validate2();"></h:commandButton>
Now when the user clicks enter in the input text is that the first button
action is fired, and i want to make the second button action fired without
changing the style i tried to handle the keyup event in each input but it
won't work, any ideas how to do that ?

Custom segue not working

Custom segue not working

I am trying to use a custom transition. I want a "cover vertical"
transition from View Controller 1 to 2 and then have View Controller 2
(the middle one) slide back down again when moving to View Controller 3.
Storyboard shown below:
http://i.stack.imgur.com/bJYXI.png
Im using the tutorial that is linked to from this post. And have also
replaced the .m code with the code provided in the answer:
Xcode custom segue - Opposite of Cover Vertical (top to bottom) - COMPLETE
NEWBIE
I have created a subclass of UIViewController and named it
FromTopReplaceSegue. My .h and .m code is shown below:
.h
#import <UIKit/UIKit.h>
@interface FromTopReplaceSegue : UIViewController
@property(nonatomic, readonly) id sourceViewController;
@property(nonatomic, readonly) id destinationViewController;
@end
.m
#import "FromTopReplaceSegue.h"
@interface FromTopReplaceSegue ()
@end
@implementation FromTopReplaceSegue
-(void)perform{
UIViewController *sourceViewController = (UIViewController *)
self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)
self.destinationViewController;
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view
setFrame:sourceViewController.view.window.frame];
[destinationViewController.view
setTransform:CGAffineTransformMakeTranslation(0,
-sourceViewController.view.frame.size.height)];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.75
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromTop
animations:^{
[destinationViewController.view
setTransform:CGAffineTransformMakeTranslation(0,
0)];
[destinationViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[destinationViewController.view
removeFromSuperview];
[sourceViewController
presentViewController:destinationViewController
animated:NO completion:nil];
}];}
@end
When i try to run the simulator i can easily get from Controller View 1 to
2 but it crashes when i try to move from Controller view 2 to 3 using the
custom segue.
Can anyone help.
Thank you so much in advance! Struggling here! :)

How to make instant search within wordpress posts?

How to make instant search within wordpress posts?

Today I need to start something special on my website.
I want to create an INSTANT SEARCH which will search within my posts.
A good example is this one: http://stackoverflow.com/users
Another one is: https://sublime.wbond.net/
I don't know from where to start. Any suggestions will be awesome.
PS: I don't need to use any wordpress plugin.

Monday, 9 September 2013

Editable text view with spinner android

Editable text view with spinner android

I want to create a control in android where user can input through
keyboard or enter through drop down list(spinner).
Actually the values I hard code in array in spinner is not exhaustive, so
user should have the option to input through virtual keyboard also.
So Either user can enter through keyboard or select from list?
How can i achieve this in android?

Let Statement/Random Function in Scheme

Let Statement/Random Function in Scheme

I was wondering if I would be able to use the built in let function from
scheme to define two random variables within the function without their
values changing throughout the code. For example if I wrote:
(let (x (- (* 2 (random)) 1)))
(let (y (- (* 2 (random)) 1)))
Would the value of x be constant until the function exits? I want to
square x and y and take the square root of them, but I need their values
to remain the same.

Is there any way of getting the parent from the child nsArraycontroller?

Is there any way of getting the parent from the child nsArraycontroller?

using cocoa bindings, i have bound to the following:
ChildArrayController
ContentSet
bindto: ParentArrayController
controllerkey: selection
modelkeypath: children
Is there any way of getting the parent from the child controller?
[childArrayController arrangedObjects] is the children.
[childArrayController selectedObjects] is the selected children.
[childArrayController content] is an array
[childArrayController selection] is a proxy for the selected child.
I want to do something like id parent = [childArrayController xxx];