Showing posts with label Mysql. Show all posts
Showing posts with label Mysql. Show all posts
Previous & Next Functionality with PHP, AJAX, JQuery and MySQLView Comments
Here i have designed a very simple application to fetch data from mysql server with php, through Ajax. In this application i have used two image input component for previous and next functionality and a table to display the data. Here is the preview of the application.
![]() ![]() You can download the application: ![]() On clicking the next button, the ajax function is called through this JQuery function $("#next").click(function(){It sends the index of the next set of data to fetch, to the ajax function. On success the data in the view is updated and the index of current data set is updated. The checkVisible function is to ensure the next previous functionality. i.e, the Next button will be disables on reaching the last data set and the previous button will be disable on reaching the first data set. function checkVisible(){In the ajaxpost file the MySql database fetch is executed. $limitquery = "select id,name,category,price,discount from previousnext limit ".(int)$_REQUEST['current'].",".$limit;The data send from sql server is parsed in the php file and send to the client. while($row = mysql_fetch_array($result)){In the next post i have planned to expand this application to have pagination. Donot forget to comment on my ideas. Need php script to import csv/excel file into MysqlView CommentsUsing a script to parse and import the file If you need to take a csv or other delimited data file and import it INTO MySQL, here is a php script that can do it for you:
$connection = mysql_connect("localhost", "test", "test") or die ("Unable to connect to server");
$db = mysql_select_db("test", $connection) or die ("Unable to select database");
// first get a mysql connection as per the FAQ
$fcontents = file ('./spreadsheet.xls');
// expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
//if your data is comma separated instead of tab separated,
// change the '\t' above to ','
$sql = "insert into TABLENAME values ('".implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."\n";
if(mysql_error()) {
echo mysql_error() ."\n";
}
}
?> Note: Upload a spreadsheet file into the same directory as this script. Then you edit this script to put in the correct table name instead of "TABLENAME". Play with mysql import, export operationsView CommentsWe can easily do import/export operations in mysql very easily. Here is the example for both. In some cases you may have to have backup of your database and you want to use it some other server. In such cases you just follow the instructions given below. You can do the mysql import, export operations in two ways.
Just access the phpmyadmin from your browser(domainname/phpmyadmin) Once you provided authentication its all done. Choose a database which you want to export In the top you can find import,export options. You can export to many number of formats Once you chosen a format and tables which are to export means it will ask you to save the file. Export is over. You can import sql files easily from here, It has a disadvantage too. If your database is too big there will be time out problem. In such case you can follow the below one or just contact your hosting company to do this.
Here you need to ssh access in case if you are accessing the remote server or if it is local you just need terminal. First export the existing database by using the below command mysql -u USERNAME -p DATABASENAME > FILE.SQL Once you have the sql file means yoou can import the sql file by mysql -u USERNAME -p DATABASENAME < FILE.SQL Here you need to provide password to access For example # mysql -u root -p forum < forumdb.sql It will be stored in your present directory. # mysql -u root -p forum < forumdb.sql The sql file should be in the present directory. Leave your comments….
Subscribe to:
Posts (Atom)
About UsCategories
Followers |