Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,729 members, 7,809,781 topics. Date: Friday, 26 April 2024 at 02:48 PM

Php Class For Beginners. Question Will Be Treated With High Priority. - Webmasters (3) - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Php Class For Beginners. Question Will Be Treated With High Priority. (35146 Views)

How Should Archive And Label Pages Be Treated? / Blogging Advice For Beginners / Designing A Website: For Beginners (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (13) (Reply) (Go Down)

Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 2:27am On Mar 04, 2009
I don try that your number tire sef.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 1:08am On Mar 07, 2009
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. . .
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by kolexinfos: 1:02pm On Mar 07, 2009
@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 ur 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
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 8:03pm On Mar 10, 2009
kolexinfos:

@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 ur 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. . .
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 10:47am On Mar 11, 2009
.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by chukslist(m): 9:31am On Mar 12, 2009
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!
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by neeyee(m): 7:27pm On Mar 12, 2009
Quadrillio needs commendation!!! This will serve as a way of encouraging him. He's trying.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 5:47pm On Mar 13, 2009
Yeah right, he is really doing a great job here. . .i get motivation from him and webdezzi on all these tutorial stuffs. . .
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 10:25am On Mar 18, 2009
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"wink;



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 = "Dick";
$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
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 10:28am On Mar 18, 2009
see u in the next class
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by chessman: 10:52am On Mar 23, 2009
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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by royalicon(m): 12:40pm On Mar 31, 2009
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"wink 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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by RuuDie(m): 6:26pm On Mar 31, 2009
whats wrong with this line of code

<?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!?
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 11:39am On Apr 01, 2009
@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
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by RuuDie(m): 4:35pm On Apr 03, 2009
@ 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
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by softnsmart: 4:43pm On Apr 03, 2009
@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.


<?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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by softnsmart: 5:03pm On Apr 03, 2009
@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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by RuuDie(m): 5:47pm On Apr 03, 2009
Thankx Quadri. . . . . will feed you back when i try it out!
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Decryptor(m): 3:24am On Apr 18, 2009
Do u have a physical study centre?
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by noibilism(m): 12:05pm On Apr 22, 2009
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>"wink;
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>"wink;
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by softnsmart: 12:30pm On Apr 23, 2009
Hi,

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

Cheers
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by hymnha(m): 10:02am On May 02, 2009
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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 3:17pm On May 04, 2009
@ hymnha

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

make sure its wampserver2

Good Luck
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by softnsmart: 9:49am On May 13, 2009
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: https://www.nairaland.com/nigeria/topic-271455.0.html
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by biggjoe(m): 11:37pm On May 13, 2009
royalicon:

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"wink 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."'"wink;

Note on bolded parts: after the = sign, the texts in bold goes thus: single quotes ('), double quotes("wink, a dot (.), the variable($text_STudentID), another dot (.), another double quote("wink and then another single quote(').

1 Like

Re: Php Class For Beginners. Question Will Be Treated With High Priority. by RuuDie(m): 6:24pm On May 16, 2009
@ 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.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 12:05pm On May 27, 2009
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

<?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

<?php
session_start();

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

if($username=="dhtml"&&$password=="ole"wink {
$_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"wink; //redirect back to the home page
?>


logout.php

<?php
session_start();

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

ob_clean();
header("Location:index.php"wink; //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
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by RuuDie(m): 4:06pm On May 28, 2009
Thanks dhtml, try it out and get back to ya!
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by mavtrevor3: 1:11pm On Jun 11, 2009
Worked out perfectly. Though it is still a simple and working script, alot still need t be added to it.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 7:44pm On Jun 11, 2009
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. . . .

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (13) (Reply)

best BULK SMS provider in Nigeria ? / How To Activate Airtel Night Plan, Get 250mb For N25 And 1.5gb For N150 / The Meaning Of CAPTCHA & 6 Types Of CAPTCHA

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 75
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.