Friday, 9 August 2013

Stuck with SQL repeating first row only

Stuck with SQL repeating first row only

OK, so here goes.
I'm trying to write a blogging system (learning how to anyway), and the
problem I have is that SQL is only returning the first line in the
database. It does it as many times as records I have. I can't work out
what is going wrong. Can somebody point me in the right direction please?
<?php
include "db_connect.php";
include "functions.php";
include "style/header.php";
?>
<link href="style/style.css" rel="stylesheet" type="text/css">
<div id="main">
<?php
echo 'Welcome to the forest, '.$_SESSION['username'];
$sql = mysql_query("SELECT post_id, post_user, post_title,
post_description, post_info, post_date FROM posts");
$row = mysql_fetch_array($sql);
$post_id = $row['post_id'];
$post_user = $row['post_user'];
$post_title = $row['post_title'];
$post_description = $row['post_description'];
$post_info = $row['post_info'];
$post_date = $row['post_date'];
do { ?>
<article>
<h2>
<?php
echo $post_title;
?>
</h2>
<?php
echo $post_description;
echo $post_info;
echo 'Posted by '.$post_user.' on '.$post_date;
} while ($row = mysql_fetch_array($sql));
?>
</article>
</div>

PHP, is it acceptable to include a php file not at top of the file to get around the limitations of the header() function?

PHP, is it acceptable to include a php file not at top of the file to get
around the limitations of the header() function?

I apologise for the trivial question, but I have been having problems
using the header() php function to redirect to pages. More specifically I
am struggling to redirect a user when he/she tries to view a non existent
profile page. My problem is that I am always including a header file which
contains session start and some html to display a basic header. Does this
mean I cannot use the header() function to redirect to pages in my scripts
that include this header file? I thought one way to get around the problem
might be to split the html part of the header into a separate file, and
include the header scripts first, then write my profile scripts, and
finally include the html part of the header. Is that bad practice? the
profile.php script follows:
<?php include("inc/incfiles/header.inc.php"); ?>
<?php
if(isset($_GET['u'])) {
//check user exists
$username = mysql_real_escape_string($_GET['u']);
if (ctype_alnum($username)) {
$check = mysql_query("SELECT username, email FROM users WHERE
username = '$username'");
if (mysql_num_rows($check)===1) {
$get = mysql_fetch_assoc($check); //execute query and store in
array
$username = $get['username'];
$email = $get['email'];
}
else {
header("Location: index.php");
die();
}
}
else {
echo "username has to be alphanumeric";
}
}
else {
echo "error";
}
?>
<h2> Profile page of <?php echo "$username";?>
<h3> Email: <?php echo "$email";?>
header.inc.php file:
<?php
include ("inc/scripts/mysql_connect.inc.php");
//start the session
session_start();
//Checks whether the user is logged in
$user = $_SESSION["user_login"];
if (!isset($SESSION["user_login"])) {
//header("Location: index.php");
//exit();
}
else
{
header("location: home.php");
}
?>
<?php
//Login Scripts has to be at the top to make sure header() redirecting works
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9]#i','', $_POST["user_login"]);
//filter user login text
$password_login = preg_replace('#[^A-Za-z0-9]#i','',
$_POST["password_login"]); //filter user password text
$md5password_login = md5($password_login);
$sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND
password='$md5password_login' LIMIT 1"); //query the user
//Check for user's existence
$userCount = mysql_num_rows($sql); //count number of rows
if ($userCount == 1) {
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
}
$_SESSION["user_login"] = $user_login;
$_SESSION["password_login"] = $md5password_login;
header("Location: home.php");
exit();
}
else {
echo "That information is incorrect, try again";
}
}
?>
<html>
<head>
<link href = "css/main.css" rel = "stylesheet" type = "text/css">
<title> title </title>
</head>
<body>
<div class = "wrapper">
<div id = "header">
<div class = "logo">
<img src = "img/Logo.png">
</div>
<div id = "login-header">
<form action = "index.php" method ="post" name =
"form1" id = "form1">
<div class = "input-wrapper"><input type =
"text" size = "25" name = "user_login" id =
"user_login" placeholder = ">Username" ></div>
<div class = "input-wrapper"><input type =
"password" size = "25" name = "password_login"
id = "password_login" placeholder = "Password"
></div>
<div class = "input-wrapper"><input type =
"submit" name = "login" value = "Sign
in"></div>
</form>
</div>
<div id = "menu">
<a href = "#"></a>
<a href = "#"></a>
</div>
</div>
</div>

bibliography numbering

bibliography numbering

I'm using biblatex with the biber as follows
\usepackage[backend=biber,sorting=nyt]{biblatex}
and my references show up beginning with the number 1. I would like to
number them starting at the number 0. How can I do this?

Table view tag issue while create new table in same view

Table view tag issue while create new table in same view

Hi i have a table view with tag 1.When i remove this table and again
create same new table with tag 2 its hang in simulator nothing action
happen.While if i create with same tag 1 its ok.any body help me? sorry
for my bad english.
my code is below.
- (IBAction)menuTapped:(id)sender {
UIButton *btn = (UIButton *)sender;
if (btn.tag==0)
{
UIView *subview;
while ((subview= [[mainView subviews]lastObject])!=nil)
if ([subview isKindOfClass:[UIView class]]){
[subview removeFromSuperview];
}
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320,45)];
[mainView addSubview:view];
[view setBackgroundColor:[UIColor darkGrayColor]];
_btnNavigation=[UIButton buttonWithType:UIButtonTypeCustom];
_btnNavigation.frame=CGRectMake(10, 9, 30, 25);
[_btnNavigation setImage:[UIImage
imageNamed:@"reveal-icon@2x.png"] forState:UIControlStateNormal];
[_btnNavigation addTarget:self action:@selector(menuTapped:)
forControlEvents:UIControlEventTouchUpInside];
_btnNavigation.tag=0;
[view addSubview:_btnNavigation];
UILabel *lblheading=[[UILabel alloc]initWithFrame:CGRectMake(58,
6, 205,32)];
[view addSubview:lblheading];
lblheading.text=@"MY TEAMS";
lblheading.backgroundColor=[UIColor clearColor];
lblheading.textColor=[UIColor whiteColor];
lblheading.textAlignment=NSTextAlignmentCenter;
lblheading.font=[UIFont fontWithName:@"LeagueGothic-Regular"
size:32.0];
searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 45, 320,
44)];
[mainView addSubview:searchBar];
searchBar.delegate=self;
_tableTeams=[[UITableView alloc]initWithFrame:CGRectMake(0,90,
320, 326)];
[mainView addSubview:_tableTeams];
_tableTeams.delegate=self;
_tableTeams.dataSource=self;
_tableTeams.tag=1;
AdWhirlView *adWhirlView = [AdWhirlView
requestAdWhirlViewWithDelegate:self];
adWhirlView.frame=CGRectMake(0, 430, 320, 50);
[mainView addSubview:adWhirlView];
CGRect frame = self->mainView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(
animationDidStop:finished:context: )];
[UIView beginAnimations:@"slideMenu" context:( void
*)(self->mainView)];
mainView.hidden=NO;
if(menuOpen) {
frame.origin.x = 160;
menuOpen =NO;
}
else
{
frame.origin.x = 0;
menuOpen = YES;
}
self->mainView.frame = frame;
[UIView commitAnimations];
}
else if (btn.tag==1)
{
UIView *subview;
while ((subview= [[mainView subviews]lastObject])!=nil)
if ([subview isKindOfClass:[UIView class]]){
[subview removeFromSuperview];
}
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320,45)];
[mainView addSubview:view];
[view setBackgroundColor:[UIColor darkGrayColor]];
_btnNavigation=[UIButton buttonWithType:UIButtonTypeCustom];
_btnNavigation.frame=CGRectMake(10, 9, 30, 25);
[_btnNavigation setImage:[UIImage
imageNamed:@"reveal-icon@2x.png"] forState:UIControlStateNormal];
[_btnNavigation addTarget:self action:@selector(menuTapped:)
forControlEvents:UIControlEventTouchUpInside];
_btnNavigation.tag=1;
[view addSubview:_btnNavigation];
UILabel *lblheading=[[UILabel alloc]initWithFrame:CGRectMake(58,
6, 205,32)];
[view addSubview:lblheading];
lblheading.text=@"PRICE HILL ATHLETICS";
lblheading.backgroundColor=[UIColor clearColor];
lblheading.textColor=[UIColor whiteColor];
lblheading.textAlignment=NSTextAlignmentCenter;
lblheading.font=[UIFont fontWithName:@"LeagueGothic-Regular"
size:32.0];
_tableTeams=[[UITableView alloc]initWithFrame:CGRectMake(0,90,
320, 326)];
[mainView addSubview:_tableTeams];
_tableTeams.delegate=self;
_tableTeams.dataSource=self;
_tableTeams.tag=2;
/*
_tableSchedule=[[UITableView alloc]initWithFrame:CGRectMake(0,90,
320, 326)];
[mainView addSubview:_tableSchedule];
_tableSchedule.delegate=self;
_tableSchedule.dataSource=self;
_tableSchedule.tag=2;
*/
AdWhirlView *adWhirlView = [AdWhirlView
requestAdWhirlViewWithDelegate:self];
adWhirlView.frame=CGRectMake(0, 430, 320, 50);
[mainView addSubview:adWhirlView];
CGRect frame = self->mainView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(
animationDidStop:finished:context: )];
[UIView beginAnimations:@"slideMenu" context:( void
*)(self->mainView1)];
mainView.hidden=NO;
if(menuOpen) {
frame.origin.x = 160;
menuOpen = NO;
}
else
{
frame.origin.x = 0;
menuOpen =YES;
}
self->mainView.frame = frame;
[UIView commitAnimations];
}
else if (btn.tag==2)
{
}
NSLog(@"Menu tapped");
}

Drawing does not remain on view after clearing canvas

Drawing does not remain on view after clearing canvas

I tried to create a drawing board.Following is my code
DrawingBoard.java
public class DrawingBoard extends View {
private static final float TOUCH_TOLERANCE = 4;
private float startX = 0;
private float startY = 0;
private Bitmap bitmap = null;
private Canvas canvas = null;
private Path path = null;
private Paint paint = null;
private Paint bitmapPaint = null;
public Paint getPaint() {
return paint; // returning paint.
}
public void setPaint(Paint paint) {
this.paint = paint; // Assigning to this.paint.
}
public DrawingBoard(Context context) {
super(context);
bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
path = new Path();
bitmapPaint = new Paint(Paint.DITHER_FLAG);
}
public Bitmap getBitmap() {
return bitmap; // returning bitmap.
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap; // Assigning to this.bitmap.
}
/*
* (non-Javadoc)
*
* @see android.view.View#onSizeChanged(int, int, int, int)
*/
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
/*
* (non-Javadoc)
*
* @see android.view.View#onDraw(android.graphics.Canvas)
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(bitmap, 0, 0, bitmapPaint);
canvas.drawPath(path, paint);
}
public void clearCanvas(){
bitmap = Bitmap.createBitmap(320, 480 , Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
path = new Path();
paint = getPaint();
startX = 0;
startY = 0;
invalidate();
}
/*
* (non-Javadoc)
*
* @see android.view.View#onTouchEvent(android.view.MotionEvent)
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
touchStop();
invalidate();
break;
case MotionEvent.ACTION_DOWN:
touchStart(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touchMove(x, y);
invalidate();
break;
}
return true;
}
private void touchStart(float x, float y) {
path.reset();
path.moveTo(x, y);
startX = x;
startY = y;
}
private void touchMove(float x, float y) {
float dx = Math.abs(x - startX);
float dy = Math.abs(y - startY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
path.quadTo(startX, startY, (x + startX) / 2, (y + startY) / 2);
startX = x;
startY = y;
}
}
private void touchStop() {
path.lineTo(startX, startY);
canvas.drawPath(path, paint);
path.reset();
}
}
MainActivity.java
public class MainActivity extends Activity implements
OnColorChangedListener {
private DrawingBoard drawingBoard = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
paint.setColor(0xFFFF0000);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(3);
drawingBoard = new DrawingBoard(this);
drawingBoard.setPaint(paint);
drawingBoard.setDrawingCacheEnabled(true);
setContentView(drawingBoard);// R.layout.activity_main);
}
@Override
public void colorChanged(int color) {
drawingBoard.getPaint().setColor(color);
}
private void showGalleryImages(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select
Picture"), 1000);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 1000) {
Uri selectedImageUri = data.getData();
if (selectedImageUri != null) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(uri,
projection,null, null, null);
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String imagePath = cursor.getString(column_index);
try {
cursor.close();
} catch (Exception e) {
}
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Bitmap bitmap = loadBitmap(imagePath,
getImageOrientation(selectedImageUri),displayMetrics.widthPixels,
displayMetrics.heightPixels); //
BitmapFactory.decodeFile(selectedImagePath);
if (bitmap != null) {
drawingBoard.clearCanvas();
drawingBoard.setBitmap(bitmap.copy(Bitmap.Config.ARGB_8888,
true));
}
}
}
}
private int getImageOrientation(Uri imageUri) {
int orientation = -1;
try {
Cursor cursor = context.getContentResolver().query(imageUri,
new String[] { MediaStore.Images.Media.ORIENTATION },
null,
null, null);
try {
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
orientation = cursor.getInt(0);
} else {
orientation = -1;
}
} catch (Exception e) {
orientation = -1;
} finally {
if (cursor != null) {
cursor.close();
}
}
} catch (Exception e) {
}
return orientation;
}
private Bitmap loadBitmap(String filePath, int orientation, int width,
int height) {
Bitmap bitmap = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
int scale = 1;
// calculate scale only if the height or width of
// the image exceeds the required value.
if ((options.outWidth > width)
|| (options.outHeight > height)) {
// calculate scale with respect to the smaller dimension
if (options.outWidth < options.outHeight) {
scale = Math
.round((float) options.outWidth / width);
} else {
scale = Math.round((float) options.outHeight
/ height);
}
}
options.inSampleSize = scale;
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(filePath, options);
if (orientation > 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
}
} catch (Exception e) {
bitmap = null;
}
return bitmap;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/*
* (non-Javadoc)
*
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
drawingBoard.getPaint().setXfermode(null);
drawingBoard.getPaint().setAlpha(0xFF);
switch (item.getItemId()) {
//create new drawing board
case R.id.action_create:
drawingBoard.clearCanvas();
drawingBoard.setBitmap(Bitmap.createBitmap(320, 480,
Bitmap.Config.ARGB_8888));
drawingBoard.invalidate();
break;
//set color
case R.id.action_color:
new ColorPickerDialog(this, this, drawingBoard.getPaint()
.getColor()).show();
break;
//edit an existing image
case R.id.action_edit:
showGalleryImages();
break;
}
return super.onOptionsItemSelected(item);
}
}
I tried to create this app following an android sample in ApiDemos. My
issue is that when selects 'Create' or 'Edit' manu and try to draw the
drawing does not remain in the view. It become disappears when removing
touch. I am stuck on this issue.How can i fix this problem?
Thanks in Advance

set theory,exprssing sets, set operations

set theory,exprssing sets, set operations

1.express the set of real numbers as union of bounded intervals. 2.Express
the set of natural numbers as union of infinitely many subsets.

Thursday, 8 August 2013

angularjs find properties of div in directive

angularjs find properties of div in directive

new to angular, new to stackoverflow. been trying to solve this for days.
here is my problem:
I want to center a group of boxes.
Is there a way to get access to properties of div's (with id or class
names) and manipulate them in a directive?
in my html I am creating divs with ng-repeat, the divs are the boxes that
are displayed. I have a directive that I, for now, am trying to use to
find and manipulate properties of the div's/directives in the html,
however I can't seem to do this.
I have googled a lot and have found similar issues but nothing that seems
to work in my code.
here's a fiddle: http://jsfiddle.net/3m87R/
app.directive('someBoxes', function()
{ return function(scope, element, attrs) { element.css('border', '1px
solid white'); //element.css('width', '200px');
var body = angular.element(document).find('.bookitem');
console.log(body[0].offsetWidth);
if(scope.$last)
{
//console.log("element name is: " + element.attr("class"));
//console.log("element is: " + element);
//console.log($(".bookitem").children("div").attr("class"));
//console.log($('.container').children('div').attr('class'));
}
};
});
Thank you for any help provided.