Php Class For Beginners. Question Will Be Treated With High Priority.

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 08, 2009, 12:55 AM
423467 members and 291050 Topics
Latest Member: willidane
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: OmniPotens, yawa-ti-de)  |  Php Class For Beginners. Question Will Be Treated With High Priority.
Pages: (1) (2) (3) (4) (5) (6) Go Down Send this topic Notify of replies
Author Topic: Php Class For Beginners. Question Will Be Treated With High Priority.  (Read 5638 views)
*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #64 on: March 04, 2009, 02:27 AM »

I don try that your number tire sef.
netm
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #65 on: March 06, 2009, 08:54 PM »

@dhtml, got my mail? Where exactly are you around here? You can reach me on 07031582275.
*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #66 on: March 07, 2009, 01:08 AM »

I stay somewhere around Ikeja, and i dont do personal training, berra get to Mr Qadri. Anyway, in case you wish to discuss some other issues with me, you can reach me on 07030290746.

@topic: i think we stopped somewhere around escaping strings with backslash. Now i am expecting to see stuffs like addslahses and stripslashes . . . possilby md5 sef.

@quadrillo: sorry for posting off topic on your thread.

@all: have a nice day. . .
kolexinfos
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #67 on: March 07, 2009, 01:02 PM »

@dhtml nice work u are doing here.
I am new to dis thread,this is the kind of thread I av been looking for so as to learn to design website from the scratch without all the shortcut software.

I av used different kinds of software b4 but I found out that they do not give u the full control u need as a web master.Here ismy short story:

I started coding html with Notepad and becos i could not get all the pimping, beautiful grapichs and flash animations properly I jumped to Dreamweaver.

I used Dreamweaver using Fireworks for graphics, Flash and SwishMax for animations but could not attain the level becos I am always having one glitch or the order with Dreamweaver.I also use for all my PHP codes and MySQL but it all got messed up when I wanted to design something big.

So I moved on to CMS started using Joomla 1.x(site that i designed wit Joomla www.kennybroltd.com) and thought it was the best in the whole world not until I found out that to produce something of your own i.e to be original u still had to edit Joomla Templates which invovles Dhtml,CSS,Javascipt, PHP/MySQL e.t.c.

So I decided to start learning everything from the scratch so as to attain the true Webmaster Status.So I saw this thread and I started reading all the recommended materials from the scratch would get back asap.

Thanks

*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #68 on: March 10, 2009, 08:03 PM »

Quote from: kolexinfos on March 07, 2009, 01:02 PM
@dhtml nice work u are doing here.
I am new to dis thread,this is the kind of thread I av been looking for so as to learn to design website from the scratch without all the shortcut software.

I av used different kinds of software b4 but I found out that they do not give u the full control u need as a web master.Here is my short story:

I started coding html with Notepad and becos i could not get all the pimping, beautiful grapichs and flash animations properly I jumped to Dreamweaver.

I used Dreamweaver using Fireworks for graphics, Flash and SwishMax for animations but could not attain the level becos I am always having one glitch or the order with Dreamweaver.I also use for all my PHP codes and MySQL but it all got messed up when I wanted to design something big.

So I moved on to CMS started using Joomla 1.x(site that i designed wit Joomla www.kennybroltd.com) and thought it was the best in the whole world not until I found out that to produce something of your own i.e to be original u still had to edit Joomla Templates which invovles Dhtml,CSS,Javascipt, PHP/MySQL e.t.c.

So I decided to start learning everything from the scratch so as to attain the true Webmaster Status.So I saw this thread and I started reading all the recommended materials from the scratch would get back asap.

Thanks



Are you sure that was directed at me or at quadrillo. . .i have some threads but not this one. . .
quadrillio (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #69 on: March 11, 2009, 10:47 AM »

sorry, about my number palava, okay guy I can confidently tell u that u can get me on any of this number (08077796668, 07036650669)

I lost my glo phone, which I just retrieved, and MTN is very bad in my office so u can try my glo line between 8am-5pm(working hours) and try my MTN after working hour anytime after 5pm

Or better still you can send me a text message, I'll get it and I will call you back my yahoo id is quadri20_wale @ yahoo.com

am always online during office hour, (but can be invisible sometimes, just send me your message I will reply)

save,

Will continue the tutorial
chukslist (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #70 on: March 12, 2009, 09:31 AM »

Nice work Quadrillio, at least just for taking the time and effort, time is expensive,  and you have been able to give yours for free, 

I have a question?

Why are a good number of IT professionals straight up corky! I have had several job positions, but when I  worked as a business analyst with several IT pros, it's amazing how some of these guys feel like they run the world, wow!

Since I joined this forum, I get a kick out of some of the comments I see,  some of them are just off the wall,  coming at you like that,  'haba, na fight?'

Keep up the good work Quad~, I'm sure some people have learned a thing or two from your effort,  out a book or not! References are nice for further reading, but if you change the wording, content, and delivery, then u don't have to reference anything!

Gosh i'm gettin addicted to Nairaland!
neeyee (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #71 on: March 12, 2009, 07:27 PM »



Quadrillio needs commendation!!! This will serve as a way of encouraging him. He's trying.
*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #72 on: March 13, 2009, 05:47 PM »

Yeah right, he is really doing a great job here. . .i get motivation from him and webdezzi on all these tutorial stuffs. . .
quadrillio (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #73 on: March 18, 2009, 10:25 AM »

Formatting Strings

PHP provides a powerful way of creating formatted strings, using the printf and sprintf functions. If you have used this function in C, these will be quite familiar to you, although the syntax in PHP is a little different.

Using printf
You use printf to display a formatted string. At its very simplest, printf takes a single string argument and behaves the same as echo:

printf("Hello, world");



The power of printf, however, lies in its ability to substitute values into placeholders in a string. Placeholders are identified by the percent character (%), followed by a format specification character.

The following example uses the simple format specifier %f to represent a float number.

$price = 5.99;
printf("The price is %f", $price);



The second argument to printf is substituted in place of %f, so the following output is produced:

The price is 5.99



There is actually no limit to the number of substitution arguments in a printf statement, as long as there are an equivalent number of placeholders in the string to be displayed. The following example demonstrates this by adding in a string item:

$item = "The Origin of Species";
$price = 5.99;
printf("The price of %s is %f", $item, $price);



Table 6.1 shows the format characters that can be used with the printf function in PHP to indicate different types of values.

Table 6.1. printf  Format Characters
Character                         Meaning
 b                                     A binary (base 2) number
 c                                    The ASCII character with the numeric value of the argument
 d                                    A signed decimal (base 10) integer
 e                                   A number displayed in scientific notation (for example, 2.6e+3)
 u                                   An unsigned decimal integer
 f                                    A floating-point number
o                                   An octal (base Cool number
s                                  A string
x                                 A hexadecimal (base 16) number with lowercase letters
X                              A hexadecimal (base 16) number with uppercase letters
 

Suppose you use the %d format specifier instead of %f to display the value of $price:

$price = 5.99;
printf("As a decimal, the price is %d", $price);



In this case, PHP will treat the argument passed as an integer, so only the whole part of the value will be displayed. The output produced is as follows.

As a decimal, the price is 5



 Decimals The %d format string represents a decimal integer, with decimal referring to base 10 numbers and not decimal points. There are different format specifiers to display numbers in base 16 (hex, %x), base 8 (octal, %o), and base 2 (binary, %b).
 




Format Codes
A format specifier can also include optional elements to specify the padding, alignment, width, and precision of the value to be displayed. This allows you to carry out some very powerful formatting.

The width specifier indicates how many characters the formatted value should occupy in the displayed string and appears between the percent sign and the type specifier. For instance, the following example ensures that the name displayed takes up exactly 10 characters:

$name1 = "Tom";
$name2 = "privates";
$name3 = "Harry";
echo "<PRE>";
printf("%10s \n", $name1);
printf("%10s \n", $name2);
printf("%10s \n", $name3);
echo "</PRE>";



 Padding These examples use <PRE> tags to make sure that multiple spaces used for padding are displayed onscreen. Usually a web browser will treat multiple adjacent whitespace characters as a single space.

String padding is not used very often in creating dynamic web pages. However, it is useful when you're producing plain-text output, such as generated email text, in PHP.
 




If you run this example through a web browser, you will see that each name displayed is indented from the left of the screen by the correct number of characters to make each name right-aligned with the others.

The default behavior is to right-align to the given width. However, you can reverse this by using the minus symbol as an alignment specifier. To left-align the strings in the previous example, you would use the format specifier %-10s. Although visibly this would not appear any different from simply using %s, the strings would be padded on the right with spaces to a length of 10 characters.

You can change the padding character from a space to any other character by placing that character before the width value, prefixed with a single quotation mark. The following example ensures that a five-digit order number is always displayed padded with zeros if necessary:

$order = 201;
printf("Order number: %'05d", $order);



The output produced is as follows:

Order number: 00201



The precision specifier is used with a floating-point number to specify the number of decimal places to display. The most common usage is with currency values, to ensure that the two cent digits always appear, even in a whole dollar amount.

The precision value follows the optional width specifier and is indicated by a period followed by the number of decimal places to display. The following example uses %.2f to display a currency value with no width specifier:

$price = 6;
printf("The price is %.2f", $price);



The price is correctly formatted as follows:

The price is 6.00



 Float Widths With floats, the width specifier indicates only the width of the number before the decimal point. For example, %6.2f will actually be nine characters long, with the period and two decimal places.
 




Using sprintf
The sprintf function is used to assign formatted strings to variables. The syntax is the same as for printf, but rather than being output as the result, the formatted value is returned by the function as a string.

For example, to assign a formatted price value to a new variable, you could do the following:

$new_price = sprintf("%.2f", $price);



All the format specifier rules that apply to printf also apply to sprintf
quadrillio (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #74 on: March 18, 2009, 10:28 AM »

see u in the next class
chessman
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #75 on: March 23, 2009, 10:52 AM »

I just stumbled on this thread and its very very educative. I 've been willing to know much about  php all this while.

Let me put together my questions now for better understanding.

Thanks man.
royalicon (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #76 on: March 31, 2009, 12:40 PM »

Hello NL, can anyone help me with this PHP code.

Pls help me to finetune this PHP code to mine from my Db with particular reference to a form item.
e.g.
select *from DB where StudentID = "$text_StudentID"

What I want here is ("$text_StudentID") is a form item that will use the studentID in the form as a basis of searching the dD among other items.
Pls correct the SQL for me as i know its wrong, not fecthing from the db.

Thanks.
RuuDie (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #77 on: March 31, 2009, 06:26 PM »

whats wrong with this line of code Huh

<?php
$user_name = "root";
$password = "";
$database = "onlineDating";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
$SQL = "SELECT * FROM tbl_userlogin";
$resultz = mysql_query($SQL);

[color=#990000][color=#990000]while ($db_field = mysql_fetch_assoc($resultz))
[/color] {
print $db_field['username'] . "<BR>";
print $db_field['password'] . "<BR>";
                                    }

mysql_close($db_handle);
         }
else {
echo "Database NOT Found ";
}
?>
[/color]



when i try it this i always get the error msg about the line while ($db_field = mysql_fetch_assoc($resultz))  not being valid. . . . . .  can any1 help clear this up!?
quadrillio (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #78 on: April 01, 2009, 11:39 AM »

@royalicon

 I need to see more of your code + the error message it's show u when u run it, I can correct on what u jus wrote.

@ruudie
I'll try and run that code BRB



RuuDie (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #79 on: April 03, 2009, 04:35 PM »

@ Quadrillo,

Here's a more elaborate view of the code and error:



put this code in a page to retrieve values from a table and display on the page

<?php
$user_name = "root";
$password = "";
$database = "onlineDating";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
$SQL = "SELECT * FROM tbl_userslogin";
$resultz = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($resultz)) {
print $db_field['username'] . "<BR>";
print $db_field['password'] . "<BR>";
                                    }

mysql_close($db_handle);
         }
else {
echo "Database NOT Found ";
}
?>


but i keep getting this message when the page loads,  can somebody pls help to explain this; how do i go about it?

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\onlineDating\login.php on line 16


quadri20_wale@yahoo.com
softnsmart
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #80 on: April 03, 2009, 04:43 PM »

@ruddie

Nothing is wrong with the code itself, really. I guess you copied the code from somewhere but somehow you copied the text formats. Try this, it'd work, I have edited it.

Quote
<?php
$user_name = "root";
$password = "";
$database = "onlineDating";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
$SQL = "SELECT * FROM tbl_userlogin";
$resultz = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($resultz)) {
print $db_field['username'] . "<BR>";
print $db_field['password'] . "<BR>";
                                    }

mysql_close($db_handle);
         }
else {
echo "Database NOT Found ";
}
?>

If it did not work, make sure you're pointing to the right database table, and that there are records in the table.
Also make sure you have a database "onlineDating" with username "root" and if it requires a password provide it, else leave it as it is.

Also make sure that you have the colums "username" and "password" on the "tbl_userlogin" table. Kindly let me know if it worked.
softnsmart
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #81 on: April 03, 2009, 05:03 PM »

@royalicon

If you have a form with method="post" and an input with name "text_StudentID"
    use this: $text_StudentID = $_POST['text_StudentID'];
else if you have a form with method="get" and an input with name "text_StudentID"
    use this: $text_StudentID = $_GET['text_StudentID'];
   
Calling $text_StudentID directly will not work when your php ini sets register_globals = Off this is good for security reasons, do not turn it on.

Cheers.
RuuDie (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #82 on: April 03, 2009, 05:47 PM »

Thankx Quadri. . . . .  will feed you back when i try it out!
Decryptor (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #83 on: April 18, 2009, 03:24 AM »

Do u have a physical study centre?
noibilism (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #84 on: April 22, 2009, 12:05 PM »

please help with this code it is giving me error msg
Parse error: syntax error, unexpected T_VARIABLE in line 11
<php
$host = "localhost";
$user = "*****";
$pass = "*****";
$dbname = "****";
$matNo = $_POST['Matric_no']

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "SELECT * FROM results WHERE matricNo = $matNo";
echo $query;

$result= mysql_query($query);
$num_results = mysql_num_rows($result);

while ($row = mysql_fetch_array($result))
{

echo "Matric Number:" $row[0];
echo "Surname:" $row[1];
echo "Other Names:" $row[2];
echo "Sex:" $row[3];
echo "GP:"  $row[4];
echo "TNU:" $row[5];
echo "Remarks:"$row[6];
}
?>

and line 11 happens to be
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
softnsmart
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #85 on: April 23, 2009, 12:30 PM »

Hi,

After $matNo = $_POST['Matric_no'] add ';'
i.e $matNo = $_POST['Matric_no'];

Cheers
hymnha (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #86 on: May 02, 2009, 10:02 AM »

STUMBLED accross the class. had some having the wampserver put online. It shows red/white instead of yellow/white, if i choose start all service, it shows yellow/white for some time and then later red/white and cos of this, i can't view the localhost. What do i do

Another problem is that even if by chance the yellow/white stays for sometime; when posting a form using "action= xxxx.php" the expected form does not display. it rather shows the code of the xxxx.php. Please does this have anything to do with installation i.e not being able to pass data to a .php file.
quadrillio (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #87 on: May 04, 2009, 03:17 PM »

@ hymnha

Please, reinstall the wamp. let me know if it display any error message,

make sure its wampserver2

Good  Luck
softnsmart
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #88 on: May 13, 2009, 09:49 AM »

I wish to introduce you to PHP Freedom Framework. this framework is the fastest know web development framework. You could develop a fully database driven website/application in 15 minutes without writing a code. It's quite flexible and amazing to use.

And further more it is made in Nigeria.

Website: http://www.phpfreedom.org
Downloads: http://code.google.com/p/phpfreedom/downloads/list
Blog: http://www.nairaland.com/nigeria/topic-271455.0.html
biggjoe (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #89 on: May 13, 2009, 11:37 PM »

Quote from: royalicon on March 31, 2009, 12:40 PM
Hello NL, can anyone help me with this PHP code.

Pls help me to finetune this PHP code to mine from my Db with particular reference to a form item.
e.g.
select *from DB where StudentID = "$text_StudentID"

What I want here is ("$text_StudentID") is a form item that will use the studentID in the form as a basis of searching the dD among other items.
Pls correct the SQL for me as i know its wrong, not fecthing from the db.

Thanks.

assuming you know about POST and GET method of passing parameters and you used the POST method in your form,

What i will do first is capture the studentID  from the form in a variable like this:
$text_StudentID = $_POST['studentID'];

and then do this to the query:
$query = mysql_query("SELECT * FROM DB WHERE StudentID ='".$text_StudentID."'");
 
Note on bolded parts: after the = sign, the texts in bold goes thus: single quotes ('), double quotes("), a dot (.), the variable($text_STudentID), another dot (.), another double quote(") and then another single quote(').
RuuDie (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #91 on: May 16, 2009, 06:24 PM »

@ Quadrillo / Smartsoft / Anybody who can help. . . . .

Need help to implement a login page which will also create session variables etc. can anyone help out with very simple code listing and explanation!?

Been reading a php tutorial but the explanation's quite complex and confusing.
*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #92 on: May 27, 2009, 12:05 PM »

Dont worry, i am sure they can help you. . .but make sure you have a basic idea of how to use mysql database. . .


Lemme give you a 3 page sample:

index.php : this is your home page. It will display login or logout depending on the state.
login.php: the page to process the login.
logout.php: to process your logout


index.php
Quote
<?php
session_start();

if($_SESSION['login_user_mode']==true) { ?>
Welcome Mr User to my secure php page
<a href="logout.php">Logout here</a>

<?php }  else { ?>

Please login to get started: [username: dhtml, password: ole]<br>
<form action="login.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit">
</form>

<?php } ?>

login.php
Quote
<?php
session_start();

$username=$_POST['username'];
$password=$_POST['password'];

if($username=="dhtml"&&$password=="ole") {
$_SESSION['login_user_mode']=true; //set this variable to true if login is correct
} else {
$_SESSION['login_user_mode']=false; //set this variable to false if login is in-correct
}

ob_clean();
header("Location:index.php"); //redirect back to the home page
?>


logout.php
Quote
<?php
session_start();

$_SESSION['login_user_mode']=false; //logout user

ob_clean();
header("Location:index.php"); //redirect back to the home page
?>


Check online demo here: http://mwebng.net/demos/login2/
Download here: http://mwebng.net/demos/login2/login2.zip


Then step it up a lil bit advanced:

http://mwebng.net/demos/login/step1
http://mwebng.net/demos/login/step1.zip

http://mwebng.net/demos/login/step2
http://mwebng.net/demos/login/step2.zip

Any further questions, ask them, in case i am not around
RuuDie (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #93 on: May 28, 2009, 04:06 PM »

Thanks dhtml, try it out and get back to ya!
mavtrevor3
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #94 on: June 11, 2009, 01:11 PM »

Worked out perfectly. Though it is still a simple and working script, alot still need t be added to it.
*dhtml (m)
Re: Php Class For Beginners. Question Will Be Treated With High Priority.
« #95 on: June 11, 2009, 07:44 PM »

Well the intention is to be simple enough to be used by anyone. When i am teaching, i write simple, when i am working, it gets more
complicated than that. . . .
 We're Working On Online Payment  The Traffic Rank Of The Most Popular Nigerian Websites  How To Get a .NG Domain Name?  Page 2
Pages: (1) (2) (3) (4) (5) (6) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.