jimforsyth 31 Newbie Poster

Hi jbennet,

Go download the latest version of JQuery (http://jquery.com/) and include this (the downloaded file) in the '<head>' of your site.

Next, create a file called delete.js file with the following 'post' request - and include it on your page.

function delete_item(id) {	
	/* Post the id of the item you want to delete */
	$.post("action.php", { delete_id: id }, 	
	function(data) {
		/* Receive the data from your php file */
		var db_response = eval('(' + data + ')');
		/* Alert the response */
		alert(db_response[0]);
	});
}

Then create a file called action.php file that handles the deletion of your items. The output from this file will be picked up by the delete.js file, so you can either show a success or an error message.

/* Delete your item using a MySql statement, then output one of the following: */

/* Success! */
//echo json_encode( array('success') );

/* Error :( */
//echo json_encode( array('error') );

Then put it all together like this:

<html>
<head>
<!-- This is the JQuery file you downloaded -->
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<!-- This is your file that posts a request to your php file -->
<script type="text/javascript" src="delete.js"></script>
</head>
<body>
<a href="#" onclick="delete_item(2); return false;">Click here</a> to delete item #2
</body>
</html>

I hope this helps you out.

Jim :)

jbennet commented: thanks +25
jimforsyth 31 Newbie Poster

Hi apollokid,

Below is some example code that should help you out. You need to choose a different column to order your data by. At the moment you are only selecting items which have a 'catid' of 38 - then you're trying to order the results by 'catid'. If all your results have a 'catid' of 38, you won't affect the order with your current 'order by' statement. Try adding a timestamp or datetime column in your database and use this to order your results.

/* Table name */
$tbl_name = "my_table";

/* Retreive slideshow items from database */
$sql = "SELECT * FROM $tbl_name 
WHERE catid = 38 
ORDER BY datetime DESC LIMIT 5";
$result = mysql_query($sql) or die ('Error, query failed');

/* Create associate array from results */
for( $i=1 $i <= mysql_num_rows($result); $i++ ) {
	/* Create an array for each row in the database, e.g. $arr['title'] */
	$arr = mysql_fetch_assoc($result);
	/* Echo your data ( td class will start 'slider1 -> slider5' ) */
	echo '<table><tr><td class="slider$i">'.$arr["title"].'<td></td></table>';
}

All the best

Jim :)

jimforsyth 31 Newbie Poster

Hi SolidSolutions,

You can also treat a string like an array, i.e.

/* Set string var */
var my_string = 'longboard';

/* Store last character of string */
var last_character = my_string[my_string.length-1];

/* Alert */
alert( last_character );

Jim :)

jimforsyth 31 Newbie Poster

Hi El Pirata,

When the timer is activated, you could store a unix timestamp in a php session. Then if/when the user refreshes the page, you can check for a session (with the start time value) and continue counting down from there.

Hope this helps.

Jim :)

jimforsyth 31 Newbie Poster

Hi MoreBloodWine,

You could loop through the array and replace the data with that of the legend:

foreach( $U2Array as $key => $item ) {
	if ( $key == "http_code" ) $U2Array[$key] = ${'$_'.$U2Array[$key]}; 
}

If you haven't sorted this out already, I hope you find this useful.

Kind regards

Jim :)

jimforsyth 31 Newbie Poster

Hi dudzkie,

It sounds like you're after 'pagination' - where results are displayed over several pages, rather than lumped all together on one.

Try this:

1. Let's assume we have a database with a table called 'tbl_accounts'.
2. We want to find all account holders with the name 'Jack'.
3. Next we want to retrieve the names, then show 10 records per page

/* Set page number */
$page_number = 1; // Or set it from the url by using, $page_number = $_GET['p'];

/* How many results to display per page */ 
$results_per_page = 10;

/* Which page of results are we looking for? */
$first_record = ( ($page_number-1)*$results_per_page );

/* Set value of name to be searched */
$name = "Jack"; 

/* Retreive all matching records */
$sql = "SELECT * FROM tbl_accounts WHERE name = '".$name."'";
$result = mysql_query($sql) or die ('Error, query failed!');

/* Store the number of results */
$total_results = mysql_num_rows($result);

/* No let's get the first page of results */
$sql = "SELECT * FROM tbl_accounts WHERE name = '".$name."' LIMIT $first_record, $results_per_page";
$result = mysql_query($sql) or die ('Error, query failed!');

/* Display results screen */
for( $i=0; $i < mysql_num_rows($result); $i++ ) {
	print_r( mysql_fetch_assoc($result) );
}

/* Calculate how many pages-worth of results are available */
$total_pages = ceil($total_results/$results_per_page);

/* Display page links */
for( $i=1; $i<=$total_pages; $i++ ) {
	echo '<a href="results.php?p ='.$i.'">Page '.$i.'</a>';
}

/* To display page 2, simply reload the code above with …
jimforsyth 31 Newbie Poster

Hi lulemurfan,

Open up the php.ini file on your new server and look for the line that starts:

'display_errors = '

.. make sure it reads:

'display_errors = Off'

The server is obviously trying to tell you something with its warning message, but this may help you short-term - I hope it does.

Kind regards

Jim :)

jimforsyth 31 Newbie Poster

Hi rajeesh_rsn,

Another option would be to do the following:

/* Original array */
$my_arr = array( "first","second","third","forth","fifth","sixth" );

/* Remove element from array */
$my_arr = remove_item_from_array( "third",$my_arr );

/* Display aletered array on screen */
print_r( $my_arr );

/* The function */
function remove_item_from_array($val,$arr) {
	/* Find value's index within the array */
	$index = array_search($val,$arr);
	/* Remove value */
	unset($arr[$index]);
	/* Return altered array with the first index reset to 0 */ 
	return array_values($arr);
}

Whichever solution you choose to use, I hope your project goes well.

Jim :)

karthik_ppts commented: Useful post +6