TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-06-2009, 11:52 AM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default <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
Dave is offline  
Reply With Quote
Old 11-06-2009, 02:24 PM   #2 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

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
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
The Following User Says Thank You to ioan1k For This Useful Post:
Dave (11-06-2009)
Old 11-06-2009, 03:39 PM   #3 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

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

Last edited by Dave : 11-07-2009 at 02:37 AM.
Dave is offline  
Reply With Quote
Old 11-07-2009, 06:34 PM   #4 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

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
__________________
My Site
adamdecaf is offline  
Reply With Quote
The Following User Says Thank You to adamdecaf For This Useful Post:
Dave (11-08-2009)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Answer Then PHP Question codefreek The Lounge 14 07-20-2009 07:19 PM
question about ftp kritikal General 3 04-28-2008 03:21 PM
$_SERVER['REQUEST_URI'] question solistus General 4 04-01-2008 09:31 PM
Cleaning data before entering database question Killswitch General 7 12-24-2007 11:29 PM
Important Database Structure Question! AnthonyOS MySQL & Databases 5 12-20-2007 03:26 PM


All times are GMT. The time now is 02:28 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design