Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
Hello world!
decembrie 11, 2007 de carassHow to make programs/windows transparent in Windows 2000 or XP
decembrie 10, 2007 de carassThis brief guide will walk you through the steps to make any of your programs transparent in Windows 2000 or XP. Transparency levels can be set on a per program basis, turned off and on again, and more.
- Download Glass2K from Chime Software. Glass2K is a small, free program. The installation is typical (next, next, done). Once it has completed, you’ll see a new icon in your task bar. Right-click it and select Settings. Note: the first time you launch Glass2K, the settings window may appear automatically.
- Make any changes you see fit and then click Save
- Now right-click on the title bar of any of your open programs or windows. In addition to the default pop-up (move, minimize, maximize etc) you’ll see a new window. From here you can set the transparency preferences for that window/program.
- And now your windows are as transparent as you want them!



How to convert files to Windows Media Video (.wmv) to play on your Windows Mobile device
decembrie 10, 2007 de carassThis tutorial will guide you through the steps to converting an existing video file to a .wmv (Windows Media Video) to play on your Windows Mobile device.
- First things first – download Windows Media Encoder from Microsoft. It’s free. It works in 2k/XP and though not ‘officially’, it seems to work fine in Vista. The installation is painfully straight forward – you’ll just click ‘Next’ a bunch of times.
- Once the installation has completed, launch Windows Media Encoder. Select Convert a file and then click OK.

click to enlarge - From the Source file: section, click the Browse button. Navigate to the file you want to convert into a wmv, select it, and click OK. The first time you convert a file you may want to go with a smaller one. It will take less time to encode, and if the resulting quality isn’t good enough, you won’t have ‘wasted’ a lot of time. Once you find the settings that work best for playback on your device, you can convert larger/longer videos with confidence.The default Output file: name and location will be identical to the input file, but with .wmv as the extension. You can change the name and save location of the output file if you wish, by clicking Browse. Once you’re happy with the input and output files, click Next.

click to enlarge - You’ll be prompted to select a Content Distribution method. For the sake of converting your first video file, select Pocket PC as the method. Further down in this tutorial (step 12) I’ll go into more detail on customizing the quality of .wmv. Click Next.
- Review the info on the Encoding Options. You may even want to write it down, so you can compare it to customized video files that you’ll be trying out later. Click Next (not Finish).
- Enter the meta data for your video. This isn’t mandatory, but it does help when you’re searching for files, how they’re displayed in Windows Media Player etc. When you’re done, click Next.
- And now review all of the info for your video conversion. Remove the check from the Begin converting when I click Finish (so that you can preview the encoder window before it’s actually encoding). Click Finish.
- And here it is. The main encoding window. You can click around and explore the various options, but try not to change anything quite yet. You’ll want to create a default Pocket PC video, so that you can compare its quality to the custom videos you’ll create later. Click the Start Encoding button when you’re ready to convert the video.
- Make yourself comfortable. Or, make yourself a cup of coffee. Watching videos encode is about as interesting as watching paint dry.
- By default, the video will go through two ‘passes’.
- Once the conversion has finished, you’ll be presented with a summary screen. Here you can find the resulting file size, bit rates etc. Click Close.
- Navigate to the output file, and upload it to your Windows Mobile device (via ActiveSync or Windows Mobile Device Center in Vista).
- Give the video a play. Watch it in full-screen and try to determine if the audio and video quality are suitable for you.
- At this point, if you’re happy with the resulting file – you’re done. If the quality is good enough for you, you can just repeat the above steps to convert more of your video files. Remember – the resulting file is never going to be better than the original file, but a lot of the time it will be smaller in size, and of decent enough quality to suit a small screen device (as most Windows Mobile products are). If you’d like to try customizing the videos to go for higher audio, video (or both) quality – keep reading.
- Using the same file that you converted in steps 1-14 (so you can compare the resulting quality), repeat the same steps (but choose a different name for the resulting file, otherwise you’ll over-write the first .wmv). This time when you get to step 7, again be sure to remove the check from the box labeled Begin converting when I click Finish. Click the Properties button and then select the Compression tab. From here, you can increase the quality of the video by selecting a higher bit rate. You can also increase (or decrease) the Audio bit rate.
- Click the Start Encoding button when you’re ready to convert your video again.
- And once again watch as it converts/encodes.
- Click Close after reviewing the results.
- Transfer the new video to your Windows Mobile device and compare the quality to the first video. Depending on what type of Windows Mobile device you have, the higher the quality, the harder it is for the device to play back the file. So files that are encoded at a very “high” quality, actually suffer by jittery playback on your Windows Mobile device. The trick is finding the right bit rate and quality settings that are best for your device.

Sursa : http://www.simplehelp.net
How to install a cpu in a computer
decembrie 10, 2007 de carass
Tutorial CS 1.6 Server NoSteam on Linux (RO)
decembrie 10, 2007 de carassCereri:
- Un calculator cu Linux pe el (Fedora Core 4/5/6, Cent0s, sau alta distributie) si acces ssh , cu privilegii root .
- Pentru un server de 22 de playeri avem nevoie de :
- Procesor 1 GB ;
- 512 MB RAM ;
- 1-2 GB spatiu pe HDD ;
- O conectiune la internet de aproximativ 1 – 1.5 MB/s ; atat download cat si upload !(daca vrei sa bagati multe pluginuri atunci este bine sa aveti banda mai mare si mai mult ram)
- IP Rootabil ; port forward .
Recomand folosirea PuTTy si WinSCP pentru urmarea pasilor de mai jos:
1) Download fisierele pentru server:
Mai intai creem un nou direct, eu voi folosi hlds mkdir /usr/hlds Intram in folderul nou creat cd /usr/hlds A) Downloadam HLDSUpdateTool: wget http://www.steampowered.com/download/hldsupdatetool.bin Suntem in /usr/hlds, executam comenzile :
chmod +x hldsupdatetool.bin
./hldsupdatetool.bin
AI) Este posibil sa va dea o eroare legata de uncompress, atunci rulati comanda: ln -s /usr/bin/gunzip /usr/bin/uncompress
rulam iar comanda:
chmod +x hldsupdatetool.bin
./hldsupdatetool.bin
b ) Downlodam hltv-ul si nucleul valve (game engine): ./steam -command update -game valve -dir .
Va face un update, va cere sa executati comanda de mai sus din nou . Incepe instalarea fisierelor necesare Server-ului timpul downlodului difera in functie de conexiunea externa pe care o aveti. Trebuie sa va apara un mesaj la sfarsit: HLDS installation up to date
c) Downlodam fisierele necesare pentru jocul Counter – Strike: ./steam -command update -game cstrike -dir . Incepe instalarea fisierelor necesare Server-ului timpul downlodului difera in functie de conexiunea externa pe care o aveti. Trebuie sa va apara un mesaj la sfarsit: HLDS installation up to date
2) Patchuirea server – ului pentru a accepta clienti STEAM si No – Steam
Downlodam NO – Steam engine de Downlodati de aici
Execum comenzile:
rm -rf engine_amd.so
rm -rf engine_i486.so
rm -rf engine_i686.so
tar xfv engine.v15.tgz
3) Configurarea fisierului: server.cfg
Mergem in /usr/hlds/cstrike/server.cfg , stergem tot si adaugam:
hostname “Numele Serverului”
mp_autokick 0
mp_autocrosshair 0
mp_autoteambalance 0
mp_buytime 2
mp_consistency 1
mp_c4timer 35
mp_fadetoblack 0
mp_falldamage 0
mp_flashlight 1
mp_forcecamera 3
mp_forcechasecam 2
mp_friendlyfire 1
mp_freezetime 3
mp_fraglimit 0
mp_hostagepenalty 0
mp_limitteams 6
mp_logfile 1
mp_logmessages 1
mp_logdetail 3
mp_maxrounds 0
mp_playerid 0
mp_roundtime 3
mp_startmoney 800
mp_timelimit 35
mp_tkpunish 0
mp_winlimit 0
sv_aim 0
sv_airaccelerate 10
sv_airmove 1
sv_allowdownload 1
sv_clienttrace 1.0
sv_clipmode 0
sv_allowupload 1
sv_cheats 0
sv_gravity 800
sv_lan 1
sv_maxrate 7000
sv_maxspeed 320
sv_maxupdaterate 101
sys_ticrate 10000
decalfrequency 60
pausable 0
log on
decalfrequency 60
edgefriction 2
host_framerate 0
exec listip.cfg
exec banned.cfg
rcon_password PAROLA
- la hostname scriem numele serverului care va aparea cand un jucator apasa TAB sau in favourites, atentie trebuie ca numele sa fie intre ghilimele.
- la rcon_password, scrieti o parola.
ATENTIE: aceasta parola nu trebuie dezvaluita adminilor sau altor persoane decat in care aveti incredere.
- mp_c4timer 35 – timpul in care bomba va exploda, timpul este in secunde, default este de 35 de secunde, pe majoritatea serverelor c4timer-ul este de 30 secunde
- mp_autoteambalance 0 – 0= nu va face nici o actiune; 1= daca este un dezichilibru in echipa serverului va muta din jucatori in functie de fragurile pe care le au( ca sa activati aceasta optiune in loc de 0 scrieti 1)
- mp_buytime 2 – timpul in care un jucator poate cumpara arme(timpul este in minute), la fel aceasta optiune o modificati dupa bunul plac
Restul optiunilor le modificati dupa propriul risc.
4) No Secure server
intram in /usr/hlds/cstrike/liblist.gam si cautam: secure “1″, variabila 1 o inlocuim cu 0, acum va arata asa secure “0″
5) Instalare si configurare Adminmod:
Downlodam Adminmod + Metamod:
wget http://downloads.sourceforge.net/halflifeadmin/halflife-admin-2.50.60-linux.tar.gz?
modtime=1093132800&big_mirror=0
Dezarhivam Adminmod tar xfvz halflife-admin-2.50.60-linux.tar.gz
Se va crea un nou director, Adminmod, ca sa instalam adminmod trebuie sa ne aflam in directorul extras din arhiva:
cd Adminmod
./install_adminM
La prima intrebare raspundem cu Y .
Ne va intreba care este directorul HLDS-ului . Raspundem cu /usr/hlds .
Ne va intreba pentru ce mod vrem sa instalam adminmod-ul . Raspundem cu 1 .
La urmatoarele intrebari raspundem cu Y .
Configurarea adminmod-ului:
- intram in /usr/hlds/cstrike/addons/adminmod/config/adminmod.cfg
in dreptul fiecare linii este cate o explicatie in engleza, eu va voi traduce si explica liniile importante: admin_bot_protection – daca este setat 0 si rulam un server cu boti, aceast cvar lasa adminii sa dea slay, kick, ban etc botilor.
admin_connect_msg – acesta este mesajul ce apare unui jucator in mijlocul ecranului dupa ce s-a conectat.
admin_cs_restrict – il punem de preferat 1 pentru a putea restrictiona armele in joc.
admin_debug – il lasam 0
admin_fun_mode – de preferat il lasam 0. Acest cvar e pentru a face jucatorii sa straluceasca intr-o culoare (glow blue).
admin_fx – il punem 1. Efecte speciale.
admin_gag_name – 0 sau 1 in functie de preferinta.
admin_gag_sayteam – la fel.
admin_highlander – Ar trebui lasat 0. Daca il trecem 1, doar un singur admin, cel mai mare, va avea access la comenzi. De ex daca pe server sunt 3 admini, cel mai mare ramane, iar celati 2 raman simple sloturi.
admin_ignore_immunity – Aici depinde de gusturi. Daca e pus 1, adminii, moderatorii si ceilalti jucatori cu imunitate isi pot da/lua slay-uri, kick, ban etc intre ei.
admin_repeat_msg – Un mesaj ce apare cu verde in mijlocul ecranului o data la cateva minute.
admin_quiet – Daca trecem 0, comenzile date de admin vor aparea cu tot cu nickul lui. Daca trecem 1, comenzile vor aparea dar in locul nickului adminului va aparea doar “Admin” iar daca trecem 2, comenzile nu vor aparea deloc.
allow_client_exec – Neaparat 1 ! Cu asta putem obliga jucatorii sa execute orice comanda (quit etc)
password_field – Poate cel mai important cvar. Ce trecem aici, vor trebui adminii nostri sa scrie in consola inainte de a se conecta la server. De ex. daca punem _parola, adminul X cu parola X789 va trebuie sa scrie in consola name X si apoi [b]setinfo _parola X789[/b] inainte de a se conecta la serverul nostru.
reserve_slots – Asta lasa adminii si sloturile rezervate sa se poata conecta atunci cand serverul este plin.
reserve_type – Lasati 0. E cel mai bine. Daca sunteti curiosi ce face, cititi manualul adminmod-ului.
Unele linii nu le-am adaugat pentru ca ele pot fi lasate default, modificati doar daca stiti despre ce este vorba
Cum adaugam / stergem admini:
- intram in users.ini, un admin trebuie scris sub forma nume:parola:acces
exemplu: X:parola_mea:131071
- codul 131071 este accesul maxim pe care il are un admin pe server, pentru a calcula acces dupa bunul plac intrati aici: http://www.adminmod.org/help/online/Admin_…in_Commands.htm
selectati ce comenzi vreti sa aibe fiecare clasa de admin in parte
6) Instalare si configurare statsme:
Downlodam statsme:
wget http://ovh.dl.sourceforge.net/sourceforge/statsme/statsme-2.8.3-cstrike.zip
Dupa ce termina de downlodat, extragem statsme
cd /usr/hlds/cstrike
unzip statsme-2.8.3-cstrike.zip
Mergem in /usr/hlds/cstrike/addons/metamod si deschidem plugins.in si adaugam aceasta linie deasupra tuturor celor existente, este foarte important ca linia de la statsme sa fie prima:
linux addons/statsme/dlls/statsme_mm_i386.so
Mergem in cstrike\addons\statsme, deschidem statsme.cfg, cautam linia sm_menupassword modificam r3wt cu o alta parola dorita.
Cum facem sa apara /rank si /top 10?
- deschidem statsme.cfg iar la sm_storebyauth sa puneti 0 in loc de 1
7) Cum pornim serverul:
Pentru serverul LuST eu folosesc screenuri este cel mai usor si bine, scriem:
cd /usr/hlds
screen -a
screen -A -m -d -S hlds ./hlds_run -game cstrike +ip ip.de.internet +sv_lan 1 -nomaster +maxplayers 18 +map de_dust2
Creere admin_who:
Ce este admin_who ? este o comanda pe care un user / admin o scrie in consola fiecarui server(90% toate serverele au acest plugin) pentru a vedea ce adminii sunt ON
- downlodam de aici programu WHO.zip
Introduceti textul care sa apara inainte si dupa nivele: .:.:: Useri Logati
Introduceti numarul de nivele: 3
Numele pentru nivelul 1: =//= GODZ =\\=
Access rights pentru nivelul 1: 131071
Numele pentru nivelul 2: =//= ModeratorS =\\=
Access rights pentru nivelul 2: 65535
Numele pentru nivelul 3: =//= SlotS =\\=
Access rights pentru nivelul 3: 32768
Sursa : http://www.gnx.ro
How to create PHP Contact Form
decembrie 10, 2007 de carassLooking for a form for your contact page. Well heres a simple and easy code which will make your contacting page an easier way of making.
Open any type of text editor for example, Notepad and copy and paste this code and save it as mail.php:
“<?php
//variables (change these)
$youremail = “name@domain.com”;
// your email address
$subject = “Contact”;
// the subject of the email
$thankyou = “thankyou.php”;
// thank you page
// don’t change anything else
;if($email == “”){
?>
No email address added. Please go back.<br/>
“<?php
;}elseif($name == “”){
“?>
No name added. Please go back.<br/>
<?php
;}elseif($message == “”){
“?>
No message added. Please go back.<br/>
“<?php
;}else{
$msg = ereg_replace(“\\\’”, “‘”, $message);
$msg = ereg_replace(‘\\\”‘, “\”", $msg);
$message1 = “from: $name\nemail: $email\nmessage:\n$msg1″;
mail($youremail, $subject, $msg, “From: $email\r\nReply-to: $email\r\n”);
?>
<meta http-equiv=”refresh” content=”0; url=<?echo $thankyou;?>”">
“<?php
}
“?>
*You don’t have to have a thank you page if you dont need it you can just
make it index.php or whatever page*
Now for the form:
<form action=”mail.php” method=”post”>
Name
<input type=”text” name=”name”><br/>
Email addess
<input type=”text” name=”email”><br/>
Message<br/>
<textarea name=”message” cols=”40″ rows=”5″></textarea><br/>
<input type=”submit” value=”send”><br/>
</form>
**If you are unfimiliar with <br/> it’s the new HTML standard.**
Source http://www.tutorialguide.net
PHP/MySQL Tutorial | Part 8 – Finishing The Script
decembrie 9, 2007 de carassIntroductionThroughout this tutorial I have taught you how to use PHP to interact with a MySQL (or SQL) database and how to use the most common commands available. I have, throughout this tutorial, also shown you how to create a basic contacts management system to illustrate some of the options you can use. In this part I will show you some final MySQL tips and will give you a final version of the script.
Saving Time
When creating complex scripts using databases you will find that the most common thing you are doing is connecting to a database. Because of this, you can actually save time by creating either a username/password file or a connection file. For example for a username/password file you would create a file called:
dbinfo.inc.php
and put the following in it:
<?
$username=”databaseusername”;
$password=”databasepassword”;
$database=”databasename”;
?>
Replacing the appropriate sections. Then in your php files use the following code:
include(“dbinfo.inc.php”);
or
include(“/full/path/to/file/dbinfo.inc.php”);
at the beginning. Then, you can use the variables $username, $password and $database throughout your scripts without having to define them every time. Also, if you ever change this information, for example if you move to another web host, there is only one file to change.
You can use the same principal to connect to the database, by putting the connection code in the file, but you must always be sure to close the connection in each file or you may have problems with your MySQL server.
Searching
A limited form of searching can also be performed on your database using a built in MySQL function. This is by using the LIKE function as follows:
SELECT * FROM tablename WHERE fieldname LIKE ‘%$string%’
To explain furhter, LIKE tells the database to perform its ’searching’ feature. The % signs mean that any other data could appear in their place and $string would hold your search string. In this place could be a word or number as well e.g.:
LIKE ‘%piano%’
which would output any rows with piano in the specified field.
Similarly, you can leave out one of the % signs so that you can specify the position of the string e.g.:
LIKE ‘piano%’
Will only output rows where the specified field begins with piano, so:
The piano is next to the table.
Would not show up.
The Finished Script
Throughout this tutorial I have given you pieces of code to make a contacts database script. You can download the full script as a zip file so that you can examine the code (see Related Links).
Conclusion
From this tutorial you should now know the basics of using PHP and MySQL together to create database-enabled websites and programs. Using databases with the web opens up a huge new selection of things you can do and can make a simple website much more powerful, saving time updating the site, allowing user interaction and feedback and much more.
PHP/MySQL Tutorial | Part 7 – Updating & Deleting
decembrie 9, 2007 de carassIntroduction
So far you have learnt how to put information into your MySQL database, view the information in it and select which information you would like to view. In this part I will show you how to do the two final actions, updating your database and deleting records from it.
The Update Script
Last week I explained how to create a link for each record to point to your update script. By using the $id variable you output links which would pass the correct ID to the script so that it can update the database. Using this you can then create the update script, which will actually have two sections to it.
Displaying The Update Page
The first part of the update script uses the single record selection from last week but adds a little HTML to it to make it more useful. First of all, we connect to the database and select the appropriate record.
$id=$_GET['id'];
$username=”username”;
$password=”password”;
$database=”your_database”;
mysql_connect(localhost,$username,$password);
$query=” SELECT * FROM contacts WHERE id=’$id’”;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,”first”);
$last=mysql_result($result,$i,”last”);
$phone=mysql_result($result,$i,”phone”);
$mobile=mysql_result($result,$i,”mobile”);
$fax=mysql_result($result,$i,”fax”);
$email=mysql_result($result,$i,”email”);
$web=mysql_result($result,$i,”web”);
Space For Code
++$i;
}
Where ‘Space For Code’ is in this script is where the code for the update page will go. This is, in fact, just HTML formatting for the output:
<form action=”updated.php” method=”post”>
<input type=”hidden” name=”ud_id” value=”<? echo $id; ?>”>
First Name: <input type=”text” name=”ud_first” value=”<? echo $first; ?>”><br>
Last Name: <input type=”text” name=”ud_last” value=”<? echo $last; ?>”><br>
Phone Number: <input type=”text” name=”ud_phone” value=”<? echo $phone; ?>”><br>
Mobile Number: <input type=”text” name=”ud_mobile” value=”<? echo $mobile; ?>”><br>
Fax Number: <input type=”text” name=”ud_fax” value=”<? echo $fax; ?>”><br>
E-mail Address: <input type=”text” name=”ud_email” value=”<? echo $email; ?>”><br>
Web Address: <input type=”text” name=”ud_web” value=”<? echo $web; ?>”><br>
<input type=”Submit” value=”Update”>
</form>
As you can see, this code will output a standard form, but instead of having blank boxes like on the form for inserting a new record, this one already has the current information from the database inserted into it. This makes it much more effective for an update script.
Updating The Database
The next stage of this script is to actually update the database. This is a simple operation and just involves a new query for the database:
$query = “UPDATE contacts SET first = ‘$ud_first’, last = ‘$ud_last’, phone = ‘$ud_phone’, mobile = ‘$ud_mobile’, fax = ‘$ud_fax’, email = ‘$ud_email’, web = ‘$ud_web’ WHERE id = ‘$ud_id’”;
This query tells the database to update the contacts table where the ID is the same as the value stored in $ud_id (which as you can see from the form on the previous page was set as the id of the record we are updating) and to set the following fields to the specified values (which were set using the form on the previous page).
This query could then be integrated into a simple script:
$ud_id=$_POST['ud_id'];
$ud_first=$_POST['ud_first'];
$ud_last=$_POST['ud_last'];
$ud_phone=$_POST['ud_phone'];
$ud_mobile=$_POST['ud_mobile'];
$ud_fax=$_POST['ud_fax'];
$ud_email=$_POST['ud_email'];
$ud_web=$_POST['ud_web'];
$username=”username”;
$password=”password”;
$database=”your_database”;
mysql_connect(localhost,$username,$password);
$query=”UPDATE contacts SET first=’$ud_first’, last=’$ud_last’, phone=’$ud_phone’, mobile=’$ud_mobile’, fax=’$ud_fax’, email=’$ud_email’, web=’$ud_web’ WHERE id=’$ud_id’”;
mysql_query($query);
echo “Record Updated”;
mysql_close();
This code would update the database and give the user a confirmation.
Deleting Records
The final part of the contacts database which needs to be created is a page to delete records. As with the Update page, this should have a record ID sent to it in the URL e.g.:
delete.php?id=9
The code to do this is the same as to update the database, except with a slightly different MySQL query. Instead of the UPDATE query you should use:
DELETE FROM contacts WHERE id=’$id’
This would then be used with the connection and confirmation code as above.
Loops
At this time it seems appropriate to mention another use of loops with a database. As well as using a loop to get information from a database as we have before, you can also use loops to execute queries. For example, if you wanted to change all the records in the database with the last name Smith to have the website www.smith.com:
Standard Database Connection Code
$query=” SELECT * FROM contacts WHERE last=’Smith’”;
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,”id”);
$query1=”UPDATE contacts SET web=’http://www.smith.com’ WHERE id=’$id’”;
mysql_query($query);
++$i;
}
mysql_close();
Of course, this could have been achived far easier and quicker using:
$query1=”UPDATE contacts SET web=’http://www.smith.com’ WHERE last=’Smith’”;
and no loop.
PHP/MySQL Tutorial | Part 6 – Single Records & Error Trapping
decembrie 9, 2007 de carassIntroduction
In the past two parts of this tutorial I have shown you how to take data out of the database and display it on screen. In this part I will enter into the final aspect of this data displaying, selecting one piece of data and stopping errors from happening when you output data.
Error Trapping
By outputting all the information from the database, it is quite unlikely that there will be no data, but if you allow updating and deleting of records, it is certainly a possibility. Luckily, with PHP and MySQL, there is an easy way round this using:
$num=mysql_numrows($result);
where $result contains the result of a query on the database (like selecting all the records). As I expalined before, this will set the value of $num as the number of rows in the result (and it was used in a loop in part 4). Because of this you can make a simple error trap using an IF statement:
if ($num==0) {
echo “The database contains no contacts yet”;
} else {
Output Loop
}
You can expand on this more by making it more user friendly (for example by providing a link to the Add Data page if no contacts exist).
Ordering Data
Not only can you output data based on the contents of a field, but you can also order the output based on a field (for example placing users in alphabetical order). By default, the output from your queries will be in order of the id field, going from 1 upwards. You can sort it on any field, though.
For example, a useful sort would be to place all the users in alphabetical order based on their last name. For those not familiar with standard databases, this would be in Ascending order as it goes from A to Z. (Ascending order is also for 1-10 etc. and descending order provides Z to A and 10-1). To do this you would use the following query:
SELECT * FROM contacts ORDER BY last ASC
You could also use DESC to order the data in Descending order.
More Uses Of mysql_numrows and Sorting
The value you have assigned to $num is very imiportant as, apart from error trapping and loops, it has many other uses. An example of this would be to print out only the last 5 records added to a database. Firstly, they would need to be placed into order based on the id field (as the one with the latest ID would have been added last. This would require them to be in Descending order.
Now you have them in order of newest to oldest but this does not restrict the script to only showing the first 5. To do this, you would need to set your loop to run to 5 instead of $num (as this would only run the loop 5 times so only 5 records would be output).
Of course, before doing this, it would be important to check that $num was greater than 5, as if you ran the loop 5 times and there were only 3 rows you would get an error. This is easy to do though and the following code is an example of the sort of thing you would want to have:
if ($num>5) {
$to=5;
}else{
$to=$num;
}
$i=0;
while ($i < $to) {
REST OF CODE
This code would check if there were more than 5 rows in the database. If there were, the loop would be set to run 5 times. If there were less than 5 rows the loop would run the correct number of times to output the whole database.
The ID Field
If you remember back to creating the database for the contacts at the beginning of this tutorial, you will remember that we included a numerical field called id. This field was set as auto_increment as well as being the primary field. I have already explained how this field is unique for every single record in the database, but I will now take this a stage further by explaining how this can be used to select an individual record from a database.
Selecting A Single Record
At the end of the last part of this tutorial, I s
howed you how to select records from the database based on the contents of partiular fields using:
SELECT * FROM contacts WHERE field=’value’
Now, by using the unique ID field we can select any record from our database using:
SELECT * FROM contacts WHERE id=’$id’
Where $id is a variable holding a number of a record. This may seem to be a little worthless as it is, but you can use this very effectively in a number of different ways. For example, if you wanted to have a dynamically generated site run through a database and a single PHP script, you could write the script to include the database data into the design. Then, using the id field, you could select each individual page and put it into the output. You can even use the page’s URL to specify the record you want e.g.
http://www.yoursite.com/news/items.php?item=7393
And then have the PHP script look up the record with the id corresponding to $item, which in this case would be 7393
Links For Single Records
Using this method of choosing a record using the URL to select the record can be expanded further by generating the URL dynamically. This sounds a bit complicated so I will elaborate. In the contacts script we are writing, I will be showing you how to create an Update page where the user can update the contact details.
To do this, another column will be included in the output column, with an Update link in it. This update link will point to a page allowing the user to update the record. To select the record in this page, we will put:
?id=$id
By getting the id of the record along with the other information when we are outputting the information from the database, this code will create a link which has each record’s ID number in it. Then, on the update page, there can be code to just select this item.
PHP/MySQL Tutorial | Part 5 – More Outputs
decembrie 9, 2007 de carassIntroduction
Throughout this tutorial you have learnt how to create a database and table, insert information and display the database information. In this part I will show you more ways of displaying and outputting the information in the database.
Formatting Output
In the last part of the tutorial we output a list of all the people stored in the database. This just gave us a very basic output, though and is not particularly useful for a working website. Instead, it would be better if we could format it into a table and display it like this.
Doing this formatting is not particularly complicated. All you need to do is use PHP to output HTML and include your variables in the correct spaces. The easiest way to do this is by closing your PHP tag and entering the HTML normally. When you reach a variable position, include it as follows:
<? echo $variablename; ?>
in the correct position in your code.
You can also use the PHP loop to repeat the appropriate code and include it as part of a larger table. For example, using a section of the code from part 4 which looped to output the database you can format it to display it in one large table:
<table border=”0″ cellspacing=”2″ cellpadding=”2″>
<tr>
<th><font face=”Arial, Helvetica, sans-serif”>Name</font></th>
<th><font face=”Arial, Helvetica, sans-serif”>Phone</font></th>
<th><font face=”Arial, Helvetica, sans-serif”>Mobile</font></th>
<th><font face=”Arial, Helvetica, sans-serif”>Fax</font></th>
<th><font face=”Arial, Helvetica, sans-serif”>E-mail</font></th>
<th><font face=”Arial, Helvetica, sans-serif”>Website</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,”first”);
$last=mysql_result($result,$i,”last”);
$phone=mysql_result($result,$i,”phone”);
$mobile=mysql_result($result,$i,”mobile”);
$fax=mysql_result($result,$i,”fax”);
$email=mysql_result($result,$i,”email”);
$web=mysql_result($result,$i,”web”);
?>
<tr>
<td><font face=”Arial, Helvetica, sans-serif”><? echo $first.” “.$last; ?></font></td>
<td><font face=”Arial, Helvetica, sans-serif”><? echo $phone; ?></font></td>
<td><font face=”Arial, Helvetica, sans-serif”><? echo $mobile; ?></font></td>
<td><font face=”Arial, Helvetica, sans-serif”><? echo $fax; ?></font></td>
<td><font face=”Arial, Helvetica, sans-serif”><a href=”mailto:<? echo $email; ?>”>E-mail</a></font></td>
<td><font face=”Arial, Helvetica, sans-serif”><a href=”<? echo $web; ?>”>Website</a></font></td>
</tr>
<?
$i++;
}
echo “</table>”;
This code will print out table headers, then add an extra row for each record in the database, formatting the data as it is output.
As long as you are familiar with PHP and HTML the code is probably pretty self explanatory but I will just point out the last two lines in the table, for example:
<a href=”mailto:<? echo $email; ?>”>E-mail</a>
This shows one of the useful features of using PHP to include MySQL data as you can use it to output parts of your code and make pages fully dynamic.
Selecting Pieces of Data
As well as showing the whole database, PHP can be used to select individual records, or records which match certian criteria. To do this you must use a variation of the SELECT query. To display the whole table we used the query:
SELECT * FROM contacts
If we just wanted to select ones who had the first name ‘John’ you would use the following query:
SELECT * FROM contacts WHERE first=’john’
As with other MySQL queries, it is almost like plain english. In the same way you could select records based on any field in the database. You can also select ones with more than one field by adding more:
field=’value’
sections onto the query.
Although I won’t go int
o great depth about it in this section, you can also use variables to give the database criteria. For example, if you had a search form you could get the last name people wanted to search for and store it in a variable called $searchlast. Then you could execute the following piece of code:
$query=”SELECT * FROM contacts WHERE last=’$searchlast’”;
$result=mysql_query($query);
Please note that at the end of the first line there is a ‘ followed by a ” before the semicolon.
Security
At this point it should be noted that you must be very careful in using the technique given above. Without correct secuirty measures, it would be very easy for someone to access data on your server, or even make changes to the database. This can occur if the user sets the variable to a value which edits the SQL string being generated in such a way that it can be used for their own purposes. I won’t go into full details here, but there are many websites which give full details (search for ’sql injection attack’).
This security hole is easy to plug with a bit of work. Always check input data for invalid chanracters and use PHP’s built in functions to remove control characters and HTML code etc. Again, there are many websites which go into this in depth.














