Created
October 29, 2014 17:55
-
-
Save grigoras/961830fd99497d23371a to your computer and use it in GitHub Desktop.
print album
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<? | |
// try db connection | |
mysql_connect("localhost","root","") or die("Could not connect to mysql!"); | |
// select database | |
mysql_select_db("ubervu") or die("Could not select db!"); | |
// create SQL query | |
$result = mysql_query("SELECT * FROM albums"); | |
// fetch results to arrays | |
while($row = mysql_fetch_array($result)) | |
{ | |
// add new album to the list | |
$albums[] = $row; | |
} | |
// check if we received an album id | |
if( | |
isset($_GET["album"]) && | |
$_GET["album"] | |
) { | |
/** | |
* Retrieve all photos from this album | |
*/ | |
// create query for retrieving photos | |
$result = mysql_query("SELECT * FROM photos WHERE album_id=" . $_GET["album"] . ";"); | |
// fetch results to arrays and save photos into a list | |
while($row = mysql_fetch_array($result)) | |
$photos[] = $row; | |
} | |
// | |
foreach($albums as $album){ | |
// check if we received an album id and show its name | |
// else show an anchor to the album's display page | |
if( | |
isset($_GET["album"]) && | |
$album["id"] == $_GET["album"] | |
) | |
echo $album["name"]; | |
else | |
echo ' <a href="display.php?album=' . $album["id"] . '">' | |
.$album["name"] . '</a> '; | |
} | |
?> | |
<table cellpadding=0 cellspacing=0> | |
<tr> | |
<? | |
$i = -1; | |
// show all photos for this album | |
// will be shown max 5 photos per line | |
for($j = 0; $j < count($photos); $j++) | |
{ | |
// get photo | |
$photo = $photos[$j]; | |
// increment photo's index | |
$i++; | |
// create a new line for each 5 photos | |
if($i%5 == 0) | |
echo "</tr></tr>"; | |
?> | |
<td> | |
<img src="<?=$photo["thumbnail"]; ?>" style="margin: 5px;" /> | |
</td> | |
<? | |
} | |
?> | |
</tr> | |
</table> | |
<? | |
if ( | |
isset($_GET["qid"]) && | |
isset($_GET["text"]) | |
) { | |
$qid = $_GET["qid"]; | |
$text = $_GET["text"]; | |
} | |
else | |
die ("Image ID or Caption Text is missing"); | |
if (isset($_GET["edit"])) | |
$editCommand = $_GET["edit"]; | |
else | |
$editCommand = "default"; | |
switch($editCommand) | |
{ | |
case "add_ans": | |
{ | |
caption::addCaption($text,$qid); | |
break; | |
} | |
case "del_ans": | |
{ | |
if (isset($_GET["cap_id"])) | |
{ | |
$cap_id = $_GET["cap_id"]; | |
caption::deleteCaption($cap_id, $text); | |
} | |
else | |
die("Error, caption ID has not been specified"); | |
break; | |
} | |
case "default": | |
{ | |
break; | |
} | |
default: | |
{ | |
die ("Command doesn't exist"); | |
break; | |
} | |
} | |
// page remains the same | |
$crud_page="edit"; | |
?> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment