Jump to content
xisto Community
karlo

A Lot Of Php Questions Part 2

Recommended Posts

Ok, here's another. After looking at many PHP codes, I will call it "PHP Shortcuts". Do you still know any other "PHP Shortcuts"?

Example, to "print" the visitor's IP address, I use

<html><head></head><body><?php print $_SERVER['REMOTE_ADDR']; ?></body></html>
After seeing someone's codes, I saw an easy way
<?=$_SERVER['REMOTE_ADDR'];?>
So, you know any more of that?

And for MySQL, I know there are many ways to retrieve the results. But how? Can you really teach me on how to use MySQL in PHP? Especially in LOOPS. I'm planning to create my own CMS. Please help me again. For my first thread, thank you all for helping me. But in this new thread, please help me!

Share this post


Link to post
Share on other sites

remember that your shortcut method will only work if the short_open_tag config is set to true. anyways for the shortcuts that i know...

another way of writing this:

if ("red" == "red") {	print "red";} else {	print "not red";}

is this way...

"red" == "red" ? print "red" : print "not red";

this is the standard format:

[condition] ? [codes to bexecuted when true] : [codes to be executed when false]

for your mysql question... i have a simple loop for you. it may be simple but the product of your loop will be a multi-dimensional array. don't mind the code ok. it's just an example.

$sql = "SELECT *	FROM armor	WHERE armor_type = '{$type}'   AND SUBSTRING(armor_name, 1, 1) LIKE '{$first_letter}'	ORDER BY armor_name ASC";if(!($result = mysql_query($sql))) {	die(mysql_error());}while ($item[] = mysql_fetch_array($result, MYSQL_ASSOC));//do the processing of data here. i always use a for.. loop.for ($x = $start; $x < $display_item; $x++) {	if ($item[$x]['armor_sold'] == "") {  $armor_sold = "N/A";	} else {  $armor_sold = explode(":", $item[$x]['armor_sold']);  $armor_sold = implode(", ", $armor_sold);	}}

Share this post


Link to post
Share on other sites

Well, I know some code for MySQL that helps you list everything that is select by the query. I mean, so you don't have to use multiple queries.

You would do this:

$query=mysql_query(QUERYGOESHERE);while($row=mysql_fetch_row($query)) echo 'WHATYOUWANTTOECHO; THE ROWS SELECT BY THE QUERY';

Here is something that I made using the SQLoops (while())

$query=mysql_query("SELECT username,realname,age,location,essay FROM mod_apps WHERE status='Approved'");while($row=mysql_fetch_row($query)) echo '<tr ',shade(),'><td>'.$row[0].'</td><td>'.$row[1].'</td><td>'.$row[2].'</td><td>'.$row[3].'</td><td>'.$row[4].'</td></tr>';

It listed every users mod app that was in the database whos status was 'Approved'.

Share this post


Link to post
Share on other sites

remember that your shortcut method will only work if the short_open_tag config is set to true. anyways for the shortcuts that i know...

 

another way of writing this:

 

if ("red" == "red") {	print "red";} else {	print "not red";}

is this way...

 

"red" == "red" ? print "red" : print "not red";

this is the standard format:

 

[condition] ? [codes to bexecuted when true] : [codes to be executed when false]

for your mysql question... i have a simple loop for you. it may be simple but the product of your loop will be a multi-dimensional array. don't mind the code ok. it's just an example.

 

$sql = "SELECT *	FROM armor	WHERE armor_type = '{$type}'   AND SUBSTRING(armor_name, 1, 1) LIKE '{$first_letter}'	ORDER BY armor_name ASC";if(!($result = mysql_query($sql))) {	die(mysql_error());}while ($item[] = mysql_fetch_array($result, MYSQL_ASSOC));//do the processing of data here. i always use a for.. loop.for ($x = $start; $x < $display_item; $x++) {	if ($item[$x]['armor_sold'] == "") {  $armor_sold = "N/A";	} else {  $armor_sold = explode(":", $item[$x]['armor_sold']);  $armor_sold = implode(", ", $armor_sold);	}}

54796[/snapback]

Please explain them to me. I can't understand it. :D

Share this post


Link to post
Share on other sites

And for MySQL, I know there are many ways to retrieve the results. But how? Can you really teach me on how to use MySQL in PHP? Especially in LOOPS. I'm planning to create my own CMS. Please help me again. For my first thread, thank you all for helping me. But in this new thread, please help me!


I suggest that u tipe a look at my tutorial of an login sistem with php and mysql, there are many usefull php lines, mysql querys and looping, I'm sure, if you understand that, it will help you alot! :D
Its on Tut forum (and here on php forum too, but there is alot of topics before)

Share this post


Link to post
Share on other sites

you should really consider exploiting the object oriented features of php especially when it comes to databes and particualarly if you want to create your own cms, its usually faster and simpler to deal with objects than it is to just deal with plain variables, so such google or some php site and find a database class and you will save yourself all the hassle of having to understand databases..

Share this post


Link to post
Share on other sites

that was just a simplified way to write an if..then..else.. statement.the last part is an example of a loop to register the whole rowset into a multi-dimensional array. and then use the for loop to process the each row.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.