I have creatd a database in which one of the fields is the URL reference for an organisation or article.
Well, the administrator of the site has populated the database with a mix of:
www.domain1.com
www.anotherdomain.com
www.site.com/article3.html
http://www.site.com/article3.html
www.site.com/
etc.
Does anyone have a robust code snipped for adding the \\"http://\\" if it is not there and otherwise leaving it?
I assume it is preferred to change the add / edit bits of code so the database always has the references with the http://.
1) Code to check if there is an http:// at the start and if not add it. Assume could be used for INSERTs or SELECTs.
2) (this is pushing it :-)
Code to run through the database and UPDATE each field which does not have the http://
Assume the latter would be something like:
sql: SELECT primary_key_field, url_field FROM table;
while ... {
$primary = $myrow[1];
$url = $myrow[2];
if (function to check the http: is missing) {
function (to add http:// if missing)
sql: UPDATE table SET url_field=$newurl WHERE primary_key_field=$primary
}
}
Anyone with code, would be appreciated!