I don't use VB allot nor MVC3. Since I am new to ASP.NET concept in general but I got a person who needs some help with code for his project and I was wondering if some one can help me rewrite PHP to ASP.NET MVC3 VB since I already have the PHP code he wants.
<?
// Establish Variables
// Stocks
$stocks = array(
"APPL",
"YHOO",
"GE",
"C",
"CAT",
"FSLR"
);
// MySQL Variables
$host = "localhost";
$username = "admin";
$password = "password";
// Post Variables
$strDate = new DateTime($_POST["$strDate"]);
$endDate = new DateTime($_POST["$endDate"]);
// Establish Database Connection
$con = mysql_connect($host, $username, $password);
mysql_select_db("StockInfo", $con);
// Set Interval as One Day
$interval = DateInterval::createFromDateString("1 day");
$period = new DatePeriod($strDate, $interval, $endDate);
// Loop Through Each Date
foreach ($period as $theDate) {
// Loop Through Each Stock
foreach ($stocks as $stock) {
// Check if Stock/Day exists in DB
$result = mysql_query("SELECT * FROM `StockInfo` WHERE `Symbol`='$stock' AND `Date`='$date' LIMIT 1");
if(mysql_fetch_array($result) !== false) {
// Do something if it is in the DB
} else {
// It's not in the database!
// Get data from Yahoo
get("yahoo", "data");
// Insert the Data into the DB
$query = "INSERT";
/*
`stockID`
`Symbol`
`Date`
`Open`
`High`
`Low`
`Close`
`Volume`
*/
}
}
}
?>
How would I make this exactly same code work in ASP.NET MVC3 VB?
I don't use VB allot nor MVC3. Since I am new to ASP.NET concept in general but I got a person who needs some help with code for his project and I was wondering if some one can help me rewrite PHP to ASP.NET MVC3 VB s
So both of you did not know MVC or VB. And you want to help the other person.
Let;s start:
$host = "localhost";
it is
dim host as string = "localhost";
This must be put in an Action that returns the Model - either from database , either from yahoo
You can make use of
PHP to ASP.NET Migration Assistant. Of course you would have to do some changes manually too since I don't think Migration assistant support MVC.
About the DB connection, my below blog post will help you to convert it to ASP.NET.
IC2UC3
0 Points
7 Posts
rewriting php to asp.net mvc3 vb
Feb 20, 2013 11:19 PM|LINK
I don't use VB allot nor MVC3. Since I am new to ASP.NET concept in general but I got a person who needs some help with code for his project and I was wondering if some one can help me rewrite PHP to ASP.NET MVC3 VB since I already have the PHP code he wants.
<? // Establish Variables // Stocks $stocks = array( "APPL", "YHOO", "GE", "C", "CAT", "FSLR" ); // MySQL Variables $host = "localhost"; $username = "admin"; $password = "password"; // Post Variables $strDate = new DateTime($_POST["$strDate"]); $endDate = new DateTime($_POST["$endDate"]); // Establish Database Connection $con = mysql_connect($host, $username, $password); mysql_select_db("StockInfo", $con); // Set Interval as One Day $interval = DateInterval::createFromDateString("1 day"); $period = new DatePeriod($strDate, $interval, $endDate); // Loop Through Each Date foreach ($period as $theDate) { // Loop Through Each Stock foreach ($stocks as $stock) { // Check if Stock/Day exists in DB $result = mysql_query("SELECT * FROM `StockInfo` WHERE `Symbol`='$stock' AND `Date`='$date' LIMIT 1"); if(mysql_fetch_array($result) !== false) { // Do something if it is in the DB } else { // It's not in the database! // Get data from Yahoo get("yahoo", "data"); // Insert the Data into the DB $query = "INSERT"; /* `stockID` `Symbol` `Date` `Open` `High` `Low` `Close` `Volume` */ } } } ?>How would I make this exactly same code work in ASP.NET MVC3 VB?
Thanks
ignatandrei
All-Star
135087 Points
21669 Posts
Moderator
MVP
Re: rewriting php to asp.net mvc3 vb
Feb 21, 2013 03:02 AM|LINK
So both of you did not know MVC or VB. And you want to help the other person.
Let;s start:
IC2UC3
0 Points
7 Posts
Re: rewriting php to asp.net mvc3 vb
Feb 21, 2013 11:54 AM|LINK
Pretty much neighter I or him know VB. I am more or less deacent with C# but he wants the code in VB
Ruchira
All-Star
43028 Points
7031 Posts
MVP
Re: rewriting php to asp.net mvc3 vb
Feb 21, 2013 12:55 PM|LINK
Hello,
You can make use of PHP to ASP.NET Migration Assistant. Of course you would have to do some changes manually too since I don't think Migration assistant support MVC.
About the DB connection, my below blog post will help you to convert it to ASP.NET.
http://ruchirac.blogspot.com/2012/09/c-and-php-database-connection-code.html
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.