Newb advice
Moderator: General Moderators
Re: Newb advice
Cool - that makes sense.
So here's a newb SQL question.
Been searching around but can't find a simple answer to this.
I've been playing with the various tables on the db for a week or so and I've
made quite a mess. To the point where even though we only have three members, if
a new member joins they become member number 23.
If I hit "empty" will it do what I think and just empty all the data from the table and
forget everything it once knew so that the next new member becomes number 1 ?
Best wishes
Monty
So here's a newb SQL question.
Been searching around but can't find a simple answer to this.
I've been playing with the various tables on the db for a week or so and I've
made quite a mess. To the point where even though we only have three members, if
a new member joins they become member number 23.
If I hit "empty" will it do what I think and just empty all the data from the table and
forget everything it once knew so that the next new member becomes number 1 ?
Best wishes
Monty
Re: Newb advice
http://www.webmaster-talk.com/php-forum ... mysql.htmlMiniMonty wrote:Cool - that makes sense.
So here's a newb SQL question.
Been searching around but can't find a simple answer to this.
I've been playing with the various tables on the db for a week or so and I've
made quite a mess. To the point where even though we only have three members, if
a new member joins they become member number 23.
If I hit "empty" will it do what I think and just empty all the data from the table and
forget everything it once knew so that the next new member becomes number 1 ?
Best wishes
Monty
Re: Newb advice
I can't visit that link (blocked at college) but are you talking about an auto increment field?
If so, what's the problem? You don't need userids to be incremental.
If you delete a member, the auto increment field does not decrement by 1. It will continue from the last value.
If so, what's the problem? You don't need userids to be incremental.
If you delete a member, the auto increment field does not decrement by 1. It will continue from the last value.
Re: Newb advice
Evening chaps...
So I've been off educating myself....
Spent today (and I mean all day) knocking up a script that finds all the images uploaded
by the logged in user, makes a thumbnail of each one and displays them in a new page
with a check box next to each image and a delete button at the top.
Yeah - I know this is five minutes work for you lot but for once I actually slogged through
and wrote this line by line with no help or "cut n paste" so I'm quite pleased with myself.
If you want to see it in action go http://www.shutterbugclub.com/upload.php and click
on the last line of the body copy. "Delete old pictures Here".
Now I just need to work out how to actually delete the image from the user's folder, the thumb
from their thumbs folder and the record on the db when they hit the button so any advice in
that direction much appreciated. I've got the beginnings of a form at the end of the script and I
seem to remember that 'unlink' is the delete syntax. Can I use 'unlink' as a condition ?
i.e. if unlink[success] then print success message ?
And one quick syntax question (which I think I'm allowed because I've been educating myself) on line
28 how can I make this agree to jpg, jpeg, png and gif ?
Tried all the ways I could think of but can't get the syntax right.
Best wishes
Monty
herewith today's efforts !
So I've been off educating myself....
Spent today (and I mean all day) knocking up a script that finds all the images uploaded
by the logged in user, makes a thumbnail of each one and displays them in a new page
with a check box next to each image and a delete button at the top.
Yeah - I know this is five minutes work for you lot but for once I actually slogged through
and wrote this line by line with no help or "cut n paste" so I'm quite pleased with myself.
If you want to see it in action go http://www.shutterbugclub.com/upload.php and click
on the last line of the body copy. "Delete old pictures Here".
Now I just need to work out how to actually delete the image from the user's folder, the thumb
from their thumbs folder and the record on the db when they hit the button so any advice in
that direction much appreciated. I've got the beginnings of a form at the end of the script and I
seem to remember that 'unlink' is the delete syntax. Can I use 'unlink' as a condition ?
i.e. if unlink[success] then print success message ?
And one quick syntax question (which I think I'm allowed because I've been educating myself) on line
28 how can I make this agree to jpg, jpeg, png and gif ?
Tried all the ways I could think of but can't get the syntax right.
Best wishes
Monty
herewith today's efforts !
Code: Select all
<?php
session_start();
if(isset($_GET['id']) || isset($_POST['id']));
else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
} else {
include_once "register.php";
exit();
}
// Connect to database
include_once "scripts/connect_to_mysql.php";
$deleteMsg= "Your image was successfully delted";
// Get the user session id variable into a local php variable
$id = $_SESSION['id'];
ob_start();
$dir = opendir( "members/$id/images" );
$pics = array();
while( $fname = readdir( $dir ) )
{
if ( preg_match( "/[.]jpg$/", $fname ) )
$pics []= $fname;
}
closedir( $dir );
foreach( $pics as $fname )
{
$im = imagecreatefromjpeg( "members/$id/images/$fname" );
$ox = imagesx( $im );
$oy = imagesy( $im );
$nx = 100;
$ny = floor( $oy * ( 100 / $ox ) );
$nm = imagecreatetruecolor( $nx, $ny );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy );
//print "Creating thumb for $fname\n";
imagejpeg( $nm, "members/$id/images/thumbs/$fname" );
}
//print "creating dsiplay page\n";
// ob_start();
?>
<html>
<head><title>Manage Images</title>
<link href="../../../../styles/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>
</head>
<body>
<?php include_once "header_template3.php"; ?>
<br>
<br>
<br>
<div align="left"><br>
</div>
<form name="form1" method="post" action="manage_images.php">
<table width="80%" border="0" align="center">
<tr>
<td><div align="center" class="Times19">Check the box for each image you want to permanently delete then click
<input type="submit" name="Submit" value="Delete">
</div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="500" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<?php
$index = 0;
foreach( $pics as $fname ) {
?>
<td valign="middle" align="center"> <a href="../<?php echo( $fname ); ?>"><img src="<?php echo( $fname );?>" border="2" class="orangeText" /></a> <br>
<input type="checkbox" name="checkbox" value="checkbox"></td>
<?php
$index += 1;
if ( $index % 7 == 0 ) { echo( "</tr><tr>" ); }
}
?>
</tr>
</table></td>
</tr>
</table>
</form>
<br>
<?php include_once "footer_template.php"; ?>
</body>
</html>
<?php
$html = ob_get_clean();
$fh = fopen( "members/$id/images/thumbs/display.php", "w" );
fwrite( $fh, $html );
fclose( $fh );
header("Location: members/$id/images/thumbs/display.php");
ob_end_flush();
?>
<?php
// DELETES THE CHOSEN IMAGES - ONLY RUNS IF THEY PRESS THE BUTTON !
if (isset($_POST['Submit'])) {
//some code in here to delete all the images they have checked - I am so tired now
}
?>
Re: Newb advice
It's strange how inspiration so often comes with the first glass of the night...
I realised I had no way of identifying the check boxes, therefore which were checked
or not and with the fruity taste of cotes du rhone to help me I wrote this:
May seem hopelessly obvious to you lot but I'm well pleased that I did this without
forty minutes of surfing around or asking anyone !
I realised I had no way of identifying the check boxes, therefore which were checked
or not and with the fruity taste of cotes du rhone to help me I wrote this:
Code: Select all
<?php echo "<input type=CHECKBOX name=$fname>"; ?>
forty minutes of surfing around or asking anyone !
Re: Newb advice
Basically, I think you want to do something like this:
Then
Or something like that. I dunno if it works, I can't test it atm, and it's a very "compressed" way of doing it, but hopefully you get the idea. Btw, lambda functions only work in PHP 5.3. If you don't have >= 5.3, you have to use create_function(), or, god forbid, use more than 1 line of code 
I dunno if you have an account on my site, but it's a similar thing to what I do with emails/personal messages. You can view source if you're not entirely sure how it works.
Gl.
Code: Select all
<input type="checkbox" name="delete_pictures[]" value="$pictureid" />Code: Select all
$query = "DELETE FROM `table` WHERE `ID` IN('".implode("', '", array_map(function($int){return (int) $int;}, $_POST['delete_pictures'])."')";I dunno if you have an account on my site, but it's a similar thing to what I do with emails/personal messages. You can view source if you're not entirely sure how it works.
Gl.
Re: Newb advice
OK chaps, I couldn't get it working so I'm trying a different approach.
After making the thumbs and what have you this gets all the images together with a delete button under each one:
Then this re-writes the page and actually shows you the images:
Then my idea (simple I thought) was to have this at the end to deletewhich ever image you
click the button for:
But it's having none of it...
Any ideas why ?
Complete code here in case I've dropped some clanger in the middle.
Best wishes
Monty
After making the thumbs and what have you this gets all the images together with a delete button under each one:
Code: Select all
<a href="<?php echo ("members/$id/images/").$fname; ?>"><img src="<?php echo ("members/$id/images/thumbs/").$fname;?>" border="2" class="orangeText" /></a> <br />
<?php $fileToDelete = "members/$id/images/".$fname;
$thumbToDelete = "members/$id/images/thumbs/".$fname; ?>
<form action="manage_images.php" method="post">
<input type="hidden" name="Name" value="$fileToDelete">
<input type="hidden" name="Name2" value="$thumbToDelete">
<input type="submit" value="Delete">
</form>
Code: Select all
$index += 1;
if ( $index % 7 == 0 ) { echo( "</tr><tr>" ); }
}
?>
</tr>
</table></td>
</tr>
</table>
</form>
<br>
<?php include_once "footer_template.php"; ?>
</body>
</html>
<?php
$html = ob_get_clean();
$fh = fopen( "manage_images.php", "w" );
fwrite( $fh, $html );
fclose( $fh );
header("Location: manage_images.php");
ob_end_flush();
click the button for:
Code: Select all
if (isset($_POST['Submit'])) {
unlink($fileToDelete);
print "Image removed";
unlink($thumbToDelete);
print "thumbnail removed";
}
Any ideas why ?
Complete code here in case I've dropped some clanger in the middle.
Best wishes
Monty
Code: Select all
<?php
session_start();
if(isset($_GET['id']) || isset($_POST['id']));
else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
} else {
include_once "register.php";
exit();
}
// Connect to database, needed every time the page runs or is refreshed in a browser
include_once "scripts/connect_to_mysql.php";
$deleteMsg= "Your image was successfully delted";
// Get the user session id variable into a local php variable for easier use in scripting
$id = $_SESSION['id'];
ob_start();
$dir = opendir( "members/$id/images" );
$pics = array();
while( $fname = readdir( $dir ) )
{
if ( preg_match( "/[.]jpg$/", $fname ) )
$pics []= $fname;
}
closedir( $dir );
foreach( $pics as $fname )
{
$im = imagecreatefromjpeg( "members/$id/images/$fname" );
$ox = imagesx( $im );
$oy = imagesy( $im );
$nx = 100;
$ny = floor( $oy * ( 100 / $ox ) );
$nm = imagecreatetruecolor( $nx, $ny );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy );
//print "Creating thumb for $fname\n";
imagejpeg( $nm, "members/$id/images/thumbs/$fname" );
}
//print "creating dsiplay page\n";
// ob_start();
?>
<html>
<head><title>Manage Images</title>
<link href="../../../../styles/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>
</head>
<body>
<?php include_once "header_template3.php"; ?>
<br>
<br>
<br>
<div align="left"><br>
</div>
<table width="80%" border="0" align="center">
<tr>
<td><div align="center" class="Times19">Check the box for each image you want to permanently delete then click
</div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="500" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<?php
$index = 0;
foreach( $pics as $fname ) {
?>
<td valign="middle" align="center"> <br>
<a href="<?php echo ("members/$id/images/").$fname; ?>"><img src="<?php echo ("members/$id/images/thumbs/").$fname;?>" border="2" class="orangeText" /></a> <br />
<?php $fileToDelete = "members/$id/images/".$fname;
$thumbToDelete = "members/$id/images/thumbs/".$fname; ?>
<form action="manage_images.php" method="post">
<input type="hidden" name="Name" value="$fileToDelete">
<input type="hidden" name="Name2" value="$thumbToDelete">
<input type="submit" value="Delete">
</form>
</td>
<?php
$index += 1;
if ( $index % 7 == 0 ) { echo( "</tr><tr>" ); }
}
?>
</tr>
</table></td>
</tr>
</table>
</form>
<br>
<?php include_once "footer_template.php"; ?>
</body>
</html>
<?php
$html = ob_get_clean();
$fh = fopen( "manage_images.php", "w" );
fwrite( $fh, $html );
fclose( $fh );
header("Location: manage_images.php");
ob_end_flush();
// DELETES THE CHOSEN IMAGE !
if (isset($_POST['Submit'])) {
unlink($fileToDelete);
print "Image removed";
unlink($thumbToDelete);
print "thumbnail removed";
}
?>
Re: Newb advice
To anyone who is still subscribed to this thread..... !
Thanks for all your help, after six months it's finally finished and over the next few
days I'm asking people to test it, spot mistakes, find errors and generally try to break it.
If you're still interested this is the email that went out to a few trusted friends.
Please feel free to join in !
- - - - - - -
Hello and thanks for agreeing to help us out with the testing of our new site ShutterBugBlub.com
The site is an online photographic college where folks can learn the basics of digital photography, some composition
tricks and tips and a few other things to help them along with their enjoyment of digital photography.
We would be very grateful if you could take an hour or so to check the site out and pass on all and any comments you may have.
You will earn our genuine gratitude (and probably a few beers).
Please be assured that the site is currently on a test server and any information you enter (you'll need to use a real email address at least once) and any pictures you upload
will be deleted at the end of this consultation.
So that we can have some consistency in the results from our whole test group please follow this quick list and give your feedback on each point and comment freely on the general experience.
(it's a good idea to have a couple of sheets of A4 and a pen handy...)
1/ go to the site (password details below), have a look around and then sign up as a member. (how long did it take to get your confirmation email) ?
2/ explore the new links that are only available to members. (general comments please).
3/ upload some of your own pictures to the galleries. (how did this go) ? (how long did it take)? (did the site reject any of your images) ?
4/ set up a profile, upload an avatar, fill in the biography boxes (you can be as cryptic, stupid or funny as you like). (general comments please).
5/ try a "blab" or two from your profile page. (is this a good system) ? (any other comments on this) ?
6/ sign up for a course - ignore the PayPal button - just click "submit" (did the course download successfully) ? (if not, please give details).
7/ once signed up to a course, please click "Your Courses" and upload some coursework. (any old pictures and please write whatever you like). (how do these pages look and feel to you) ?
8/ you will soon receive an email from one of the course tutors (a real person) directing you to the critique of your pictures, click the link in the email. (again, how do these pages look and feel to you) ?
9/ all and any other general comments on the site both good or ill are very gratefully received. We will rely on your honest feedback so don't hold back !
Start here: http://www.shutterbugclub.com
Best wishes
ShutterBugClub development team
admin@shutterbugclub.com
Thanks for all your help, after six months it's finally finished and over the next few
days I'm asking people to test it, spot mistakes, find errors and generally try to break it.
If you're still interested this is the email that went out to a few trusted friends.
Please feel free to join in !
- - - - - - -
Hello and thanks for agreeing to help us out with the testing of our new site ShutterBugBlub.com
The site is an online photographic college where folks can learn the basics of digital photography, some composition
tricks and tips and a few other things to help them along with their enjoyment of digital photography.
We would be very grateful if you could take an hour or so to check the site out and pass on all and any comments you may have.
You will earn our genuine gratitude (and probably a few beers).
Please be assured that the site is currently on a test server and any information you enter (you'll need to use a real email address at least once) and any pictures you upload
will be deleted at the end of this consultation.
So that we can have some consistency in the results from our whole test group please follow this quick list and give your feedback on each point and comment freely on the general experience.
(it's a good idea to have a couple of sheets of A4 and a pen handy...)
1/ go to the site (password details below), have a look around and then sign up as a member. (how long did it take to get your confirmation email) ?
2/ explore the new links that are only available to members. (general comments please).
3/ upload some of your own pictures to the galleries. (how did this go) ? (how long did it take)? (did the site reject any of your images) ?
4/ set up a profile, upload an avatar, fill in the biography boxes (you can be as cryptic, stupid or funny as you like). (general comments please).
5/ try a "blab" or two from your profile page. (is this a good system) ? (any other comments on this) ?
6/ sign up for a course - ignore the PayPal button - just click "submit" (did the course download successfully) ? (if not, please give details).
7/ once signed up to a course, please click "Your Courses" and upload some coursework. (any old pictures and please write whatever you like). (how do these pages look and feel to you) ?
8/ you will soon receive an email from one of the course tutors (a real person) directing you to the critique of your pictures, click the link in the email. (again, how do these pages look and feel to you) ?
9/ all and any other general comments on the site both good or ill are very gratefully received. We will rely on your honest feedback so don't hold back !
Start here: http://www.shutterbugclub.com
Best wishes
ShutterBugClub development team
admin@shutterbugclub.com