shuffle db table order

simple code to shuffle a table ... with php shuffle:

$result = $mysql->query("SELECT id FROM $table ORDER BY id");
$rows = $result->num_rows;
$order = shuffle(range(1,$rows));
while($row=$result->fetch_row()) {
  $num=array_shift($order);
  $mysql->query("UPDATE $table SET rand_sort=$num WHERE id=".$row[0]);
}

added:
with MySQL RAND():

Ajax frontend for my backoffice in jQuery and PHP

This is my way to organize php for a simple jQuery frontend ajax based:

1.in a administration page include the php that generate html for each box
2.for each box setup behavior in Javascript
3.let each php manage POST request (for change/update) and GET request for show content


So in admin.php we could have something like that

innerHTML problem with internet explorer (supposed)

I lost some time to debug this

$("#link").click(function(){
   $("#target").load('url/to/load');
});

The problem is on Internet Explorer (all version) that refuse to load data in #target, using $.get and innerHTML(data) do not help. The problem is with no well formed html! Internet Explorer refuse to load in dom a malformed html.
Thus

Email from your host you are banned (mail php security matter)

I found this in a server:

$header = "From: <".$_REQUEST['email'].">\n";
#... 
mail($from,$subjet,$message,$header);

$_REQUEST['email'] came from a form input ...

Here $_REQUEST['email'] should be, at least, stripped by all \n no matter on how you trust to js code..

$from = $_REQUEST['email'];
$from = str_replace("\n","",$from);
$header = "From: <$from>\n";

grep over ssh in emacs

M-x grep command is very useful in a number of situation, because, for example, it give you direct access to all matched file ...

But there is not so intuitive how to use grep when opening file via ssh, this is the trick:

First generate a key pair and upload public part to the remote server:
(suppose remote host/user is B/b)

ssh-keygen -t rsa
#...
ssh b@B mkdir -p .ssh
cat ~/.ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
ssh-add

be sure to use ssh-agent in order to use ssh-add

SiteMap php class

2 simple class for sitemap:

http://www.smartango.com/sites/default/files/sitemap.txt

simple use:

{syntaxhighlighter brush:php}
$root = $_SERVER['DOCUMENT_ROOT'];
$sm = new SiteMap($root,'sitemap-1.xml');
$sm->start();
$http = "http://www.example.com";
$sm->addUrl($http."/file.html");
$sm->end();
{/syntaxhighlighter}

...SiteMapIdx similar