A lot of PHP Questions PART 2
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!
Opera 8 Beta 2 (build 7483) º Windows XP Professional SP2 º Pentium III 702MHz º 10GB Hard Drive º 128MB RAM º 17" Monitor º CMI8738 Sound Card º 28.8Kbps º ISP Reloaded Prepaid Internet Card º Trillian 2.013 Pro º Ad Muncher 4.61 (build 16020) BETA
My Website | My Blog
Busy posted this at 08:25 — 28th February 2005.
He has: 6,151 posts
Joined: May 2001
While shortcuts can be easier they aren't always the easiest.
A perfect example is comments. There are several ways to do comments in PHP
// single line
# single line
/*
multi line
*/
above is three examples, the two short methods are quicker but can also create problems if you change editors (text or wysiwyg) as tab spacing and even word spacing can be totally different.
You could have something like
<?php
echo "you are sick and may";
// make them live or die
echo "heal or";
/* do a check to see where the sun is to the moon or something fancy */
echo "die tomorrow";
?>
This is a very bad example but in some editors the above could come out like:
<?php
echo "you are sick and may"; // make them live or die echo "heal or"; /* do a check to see where the sun is to the moon or something fancy */ echo "die tomorrow";
?>
which would output "you are sick and may die tomorrow" because echo "heal or"; is now commented because of the single line text.
Like I said bad example but hopefully you get the jist of it.
If you are still in the early stages of learning PHP/MySQL learn the full way now, can always do the short cuts later but knowing the full method will put you lengths ahead down the track.
Welcome to your new addiction - PHP
As for MySQL, are you using PEAR, what version of PHP under 5 or 5? Do you want seperate queries or a class function?
php.net and mysql.org have the manuals for both and are very interesting to browse over
thisnew posted this at 12:31 — 17th March 2005.
They have: 8 posts
Joined: Feb 2005
Below is a copy and paste from the PHP manual.
Check it out here: http://de.php.net/manual/en/ref.mysql.php
<?php
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo \"<table>\n\";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo \"\t<tr>\n\";
foreach ($line as $col_value) {
echo \"\t\t<td>$col_value</td>\n\";
}
echo \"\t</tr>\n\";
}
echo \"</table>\n\";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.