I am building a lottery website and have generated random numbers between 1-49. Each sets of numbers have a specific colour, the code i have used is shown below:-
HOWEVER..i have created 49 images of lottery balls in Photoshop linking with the colour of each ball number according to my code. What i want to do is when the random button is clicked, pull out the speicific image of the ball. so for example if i click
on random and it displays the numbers 4,12,34,35,7, and 9 it will display the images of the balls i have if you know what i mean..? Then i want to insert the information into a database. So basically using exactly the same concept i have used here but instead
of a text box i want to firstly display the relevant image of the ball when the random button is clicked, then i want to add the value into a database.
I assume you named those images in this manner: 1.jpg, 2.jpg, 3.jpg... and you saved them in "images" folder.
If that's the case, you can achieve your goal with this DataList:
Thanks for a great reply, it worked perfectly. The only annoying thing was that all 49 images were made one by one!!
I have another question... once i click on random and it displays the images of the balls, how can i insert that value in the text boxes, so then i can insert the numbers into the database.
For example i have enabled users to put their desired numbers in manually or randomly, so if they do not put it manually, once random is clicked it shows the random ball images, AND puts the numbers into the textboxes...
However what i want to do is ONLY select the winning numbers and not the other text. I want to use the first feed which will say something on the lines of:-
The Main UK Lottery Draw Numbers for 03-01-2009
05 January 2009 02:00
Draw date 03-01-2009 Draw numbers are 39 , 37 , 19 , 49 , 9 and 36 - The bonus ball is 10 , Ball set 6 , Draw machine is TOPAZ
I want to select JUST the numbers and then check them against a database of numbers which users have entered numbers into. I have done some research and the best way seems to be parse string using string.split..? but i really dont know where to begin.
You can try with this code (this example is done with LINQ, so you'll have to use ASP.NET 3.5):
XElement xEl = XElement.Load("http://www.schok.co.uk/lottery/lottery.xml");
CultureInfo info = new CultureInfo("en-US");
var lastDraw = (from p in xEl.Descendants("item")
orderby DateTime.ParseExact(p.Element("pubDate").Value.Substring(5, 20), "dd MMM yyyy HH:mm:ss", info) descending
select p.Element("description").Value).FirstOrDefault();
if (lastDraw != null)
{
string[] lastDrawLetters = lastDraw.Split(' ');
ArrayList nums = new ArrayList();
for (int i = 0; i < lastDrawLetters.Count(); i++)
{
double j = 0;
if (double.TryParse(lastDrawLetters[i], out j))
{
nums.Add(j);
//This line is just for testing:
Response.Write(j + "<br/>");
}
}
}
Cheers, would i need to add a namespace at the top?
I am getting the following errors:-
Error 2 The type or namespace name 'CultureInfo' could not be found (are you missing a using directive or an assembly reference?)
Error 5 Argument '2': cannot convert from 'lambda expression' to 'System.Func<System.Xml.Linq.XElement,System.DateTime>
Error 4 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'OrderByDescending' and the best extension method overload 'System.Linq.Enumerable.OrderByDescending<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>,
System.Func<TSource,TKey>)' has some invalid arguments
That last code was pulling values from the top feed. This one will pull the values from the feed which title starts with "The Main UK Lottery". And I replaced the part responsible for showing the data on the screen with the Label:
XElement xEl = XElement.Load("http://www.schok.co.uk/lottery/lottery.xml");
var lastDraw = (from p in xEl.Descendants("item")
where p.Element("title").Value.StartsWith("The Main UK Lottery")
select p.Element("description").Value).FirstOrDefault();
if (lastDraw != null)
{
string[] lastDrawLetters = lastDraw.Split(' ');
ArrayList nums = new ArrayList();
for (int i = 0; i < lastDrawLetters.Count(); i++)
{
double j = 0;
if (double.TryParse(lastDrawLetters[i], out j))
{
nums.Add(j);
Label1.Text += j + "<br/>";
}
}
}
billy_111
Member
333 Points
878 Posts
random number linked with images
Jan 03, 2009 05:02 AM|LINK
Hey,
I am building a lottery website and have generated random numbers between 1-49. Each sets of numbers have a specific colour, the code i have used is shown below:-
Upon doing this i insert the values of the text boxes into a database using the following code:-
HOWEVER..i have created 49 images of lottery balls in Photoshop linking with the colour of each ball number according to my code. What i want to do is when the random button is clicked, pull out the speicific image of the ball. so for example if i click on random and it displays the numbers 4,12,34,35,7, and 9 it will display the images of the balls i have if you know what i mean..? Then i want to insert the information into a database. So basically using exactly the same concept i have used here but instead of a text box i want to firstly display the relevant image of the ball when the random button is clicked, then i want to add the value into a database.
Any ideas? Sorry for the confusion
Thank You
Kind Regards [:)]
kipo
All-Star
16475 Points
2811 Posts
Re: random number linked with images
Jan 03, 2009 10:42 AM|LINK
I assume you named those images in this manner: 1.jpg, 2.jpg, 3.jpg... and you saved them in "images" folder.
and modify your code a bit(I made it simplier, you just need to add database inserting funcionality):If that's the case, you can achieve your goal with this DataList:
billy_111
Member
333 Points
878 Posts
Re: random number linked with images
Jan 05, 2009 12:39 AM|LINK
Hey,
Thanks for a great reply, it worked perfectly. The only annoying thing was that all 49 images were made one by one!!
I have another question... once i click on random and it displays the images of the balls, how can i insert that value in the text boxes, so then i can insert the numbers into the database.
For example i have enabled users to put their desired numbers in manually or randomly, so if they do not put it manually, once random is clicked it shows the random ball images, AND puts the numbers into the textboxes...
my code now looks like so:
Thank You again.
Regards
kipo
All-Star
16475 Points
2811 Posts
Re: random number linked with images
Jan 05, 2009 06:46 AM|LINK
You can use your own code:
billy_111
Member
333 Points
878 Posts
Re: random number linked with images
Jan 05, 2009 12:05 PM|LINK
[:D] Thank You, your a legend! I now have one final question sorry...
I want to retrieve the winning lottery numbers from the national lottery website from the following RSS feed:-
I have the following code so far:
However what i want to do is ONLY select the winning numbers and not the other text. I want to use the first feed which will say something on the lines of:-
I want to select JUST the numbers and then check them against a database of numbers which users have entered numbers into. I have done some research and the best way seems to be parse string using string.split..? but i really dont know where to begin.
Thank You
Sorry for all the questions
Kind Regards
kipo
All-Star
16475 Points
2811 Posts
Re: random number linked with images
Jan 05, 2009 02:40 PM|LINK
You can try with this code (this example is done with LINQ, so you'll have to use ASP.NET 3.5):
billy_111
Member
333 Points
878 Posts
Re: random number linked with images
Jan 05, 2009 02:48 PM|LINK
Cheers, would i need to add a namespace at the top?
I am getting the following errors:-
kipo
All-Star
16475 Points
2811 Posts
Re: random number linked with images
Jan 05, 2009 03:02 PM|LINK
Yes, you'll need the following:
billy_111
Member
333 Points
878 Posts
Re: random number linked with images
Jan 06, 2009 12:29 AM|LINK
Hey,
It is working but it is getting the wrong RSS feed...
the one i need is
however it is now showing
Also to test it instead of using response.write can i use the following?
Again thank you, really appreciate your help.
Regards
kipo
All-Star
16475 Points
2811 Posts
Re: random number linked with images
Jan 06, 2009 10:35 AM|LINK
That last code was pulling values from the top feed. This one will pull the values from the feed which title starts with "The Main UK Lottery". And I replaced the part responsible for showing the data on the screen with the Label: