I am trying to create a homepage.
Shortly, my problem is... I have added to images (left and right arrows) to my html page, and when a user clicks on one of these arrows, a GET method occurs (get the next photo, and show it on the htmlpage). I am trying to write the code that connects to the Mysql database, where I have created a table called Photos. The table has 3 columns: "id (int), picturename (varchar) and src (varchar)"
So I'm not saving my photos in the database, I only save references to the pictures. How do I go about with this?
Here is my html code:
<div>
<a href="" class="leftArrow"><img id="venstrePil" style="position: relative; top: 350px; left: 0px"
src="smallLeftArrow.jpg" alt="" runat="server" /></a> <!-- This is the left arrow the get's the previous pic -->
<div class="innerDiv">
<img ID="midPic" class="billede" src="" alt="" runat="server"/> <!--This is where the picture should be shown-->
</div>
Here is the C# code that connects to the database:
protected void uploadPic()
{
MySqlConnection connection = new MySqlConnection("SERVER=server;PORT=port; DATABASE=database; UID=userId;
PASSWORD="pw");
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * from Billeder ORDER BY id";
Uri tempUri = new Uri("http://www.ExampleUri.com");
String query = tempUri.Query;
String resName = HttpUtility.ParseQueryString(query).Get("imgnr");
try
{
connection.Open();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
midPic.Src = ???? I'm stuck here. Notice that midPic is the ID from the html code.
}
connection.Close();
}
I'm pretty lost, so any help is greatly appreciated.
For those who have not understood my problem yet, here is the code that shows the exact concept that I want to do. It is just expressed in php code (I didnt write this code, someone else did it to show me the overall idea). I am not familiar with PhP, but I do understand most of the code below, since I've programmed java a lot (I know these 2 languages are not comparable).
<html>
<head>
<title>Billeder</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
</html>
<body>
<?php
$conn = mysql_connect("mysql.domain.net", "domain_net", "password");
mysql_select_db("domain_net_db", $conn);
$imgnr = $_GET['imgnr'];
if ( !ctype_digit($imgnr) ) $imgnr = 0;
$cnt_billeder = mysql_result(mysql_query("SELECT COUNT( * ) FROM Billeder"), 0);
$get_billeder = mysql_query("SELECT * FROM Billeder ORDER BY id ASC LIMIT ".$imgnr.",1");
$go_billeder = mysql_fetch_array($get_billeder);
echo "<img style=\"width: 100px; \" src=\"images/".$go_billeder['src']."\" alt=\"".$go_billeder['billednavn']."\"/>" . "<br />";
$previmg = ($imgnr == 0) ? $cnt_billeder - 1 : $imgnr - 1;
$nextimg = ($imgnr + 1) % $cnt_billeder;
echo "<a href=\"?imgnr=" . $previmg . "\">Forrige</a>";
echo "<a href=\"?imgnr=" . $nextimg . "\">Næste</a>";
?>
</body>
</html>
Thanks alot

New Topic/Question
Reply




MultiQuote




|