TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   <a href...> question (http://www.talkphp.com/absolute-beginners/5092-href-question.html)

Dave 11-06-2009 11:52 AM

<a href...> question
 
The code below is from a simple social networking application that I'm studying (not interested in making a social network app, but the code is interesting to follow).

The table USERS has the following fields:
id (IDs are assigned in order of registration.)
username
PASSWORD
firstname
lastname
dob
gender
email
location
html
CODE
valid
lastlogin

Two questions:

1. Is it a good idea to use the same variable ($new) in each line below (although I'm sure that PHP doesn't care)?

2. I don't understand the last line (echo "Our...) at all. (Let's say that the last user to register is "Snicker.")

PHP Code:

<?php

$new 
mysql_query("SELECT * FROM users WHERE valid='1' ORDER BY id DESC LIMIT 1");

$new mysql_fetch_assoc($new);

$new $new['username'];

echo 
"Our newest member is <a href='$new/'>$new</a><br>";
?>

Thanks,

Dave

ioan1k 11-06-2009 02:24 PM

php Code:
$new = $new['username'];

echo "Our newest member is <a href='$news/'>$new</a><br />';

It's very simple, the variable $new becomes the username from the SQL Query :)

And as far as using the same variable for each line, it will make no difference, but it is bad practice, as any data in the variable will be overwritten, especially in this case for pulling SQL Results

Dave 11-06-2009 03:39 PM

Thanks.

I take it that, when PHP is directed to a location, e.g., http://localhost/myfolder/mysubfolder, it will automatically try to open an index.php file within "mysubfolder." Is this correct?

Dave

adamdecaf 11-07-2009 06:34 PM

Not always, the default file that is loaded is called the "DirectoryIndex". Your server (I'm guessing Apache) will use what are called .htaccess files.

When apache receives the request for a page it looks for the closest .htaccess file (often they can be cached in RAM) and uses those guidelines to display the correct page and headers.

If you want to change what default page is loaded just put this in a file called ".htaccess" in the directory you want to change. Note: You will not be able to just rename a file to ".htaccess" on Windows, Open->File->Save As.

Code:

DirectoryIndex index.php

# Note, if you want to have it check for multiple files just
# list them with a space between.
DirectoryIndex index.php home.php install.php error.php



All times are GMT. The time now is 10:12 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0