
ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
You can also accomplish this by using CSS. Give each div a class so they all have the same width and add float: left; If the total size of your divs is greater than it's containing div then it will be automatically be pushed to the next line.
-
if (!mysql_select_db($databaseName)) { //database not present or no server (MySQL) connection }
-
You should make the Username column a unique key to prevent that. You need to store the 'last access' date/time in the online table as well. You would UPDATE the last access date/time on every page request to keep it current. You can then check and remove records in the online table that have a last access date/time older than a value you pick (typically 10-20 minutes is used.) You can apply this method to your users table aswell just add a last_access field and update on each request. UPDATE users SET last_access = now() WHERE id = $uid To select all 'logged in' users: SELECT username FROM users WHERE unix_timestamp(last_access) + 300 > now() A user is allowed 5 minutes to be idle before he is considered logged out
-
Because in Mchl's example it will die() when you have a query error. In your example the script ends (blank page) whenever mysql_num_rows() returns 0
-
Yes³. No. 1. Add a field signup_date (DATETIME) to your people table 2. function get_latest_signups($number = 10, $db = null) { $number = intval($number); $number = 0 === $number ? 10 : $number; $latest_registrations = array(); $query = "SELECT name, profileurl FROM people ORDER BY signup_date DESC LIMIT $number"; $result = mysql_query($query, $db); if ($result && mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $latest_registrations[] = $row; } } return $latest_registrations; } $latest_signups = get_latest_signups(); foreach ($latest_signups as $user) { echo '<a href="', $user['profileurl'], '">', $user['username'], '</a>'; }
-
That's because you should use \" instead of "
-
That would be: !=
-
You where on the right track the correct is: <form action="index.php"> <input type="hidden" name="site" value="clans"> <input type="hidden" name="action" value="clanregister"> <input type="hidden" name="cupID" vlaue="<?php echo $dl['ID']; ?>"> <select name="clanID"> <option><?php print $clan; ?></option> </select> <input type="submit" value="Go"> </form>
-
LOL I laughed at: elseif($state =! 1){ $state = !1 <=> $state = 0 which means that the body (between { and }) of elseif($state = !1) never executes $synopsis = substr($row['story'],0,50); Is not a good idea you could get: while the long text would have been Use $synopsis = substr($row['story'], 0, strpos($row['story'], ' ', 50)); It also looks nicer if(substr($row['story']) > 50) /* OR */ if(substr($row['story'] > 50)) 'hello world' > 50 <=> 0 > 50 = always false in both above cases. You probably meant: if(strlen($row['story']) > 50)
-
There aren't any traditional methodologies specific for webdevelopment. Possibly because a small website never needs the help of any software engineering methodology and is possibly just overkill. The real advantage can be found in large, enterprise-grade websites (or web applications). My recommended reading: OO Analysis & Design (by Grady Booch) Applying UML and Patterns (by Craig Larman)
-
Is there a more efficient way to do this username check?
ignace replied to Merdok's topic in PHP Coding Help
function my_generate_username($prefix) { return $prefix . implode('', array_rand(range(0, 9), 3)); } $usernames = array_map('my_generate_username', array_fill(0, 12, $usr_username)); // generate 12 usernames (~$usr_username[0-9]{3}) // return all taken usernames $query = 'SELECT usr_username FROM core_users WHERE usr_username IN (' . implode(', ', $usernames) . ')'; $result = mysql_query($query); if ($result) { $row_count = mysql_num_rows($result); if (0 === $row_count) { // none of the generated usernames were taken $free_usernames = array_rand($usernames, 3); // select 3 usernames from the collection } else { while (list($username) = mysql_fetch_array($result, MYSQL_NUM)) { $key = array_search($username, $usernames); if (false !== $key) { unset($usernames[$key]); // already taken } } $free_usernames = array_rand($usernames, 3); } print_r($free_usernames); } -
if it's in the form $array[0]['Stat']; function stat_get_max($stat_array) { $max = 0; if (!is_array($stat_array)) return $max; $sizeof = sizeof($stat_array); for ($i = 0; $i < $sizeof; ++$i) { $max = $stat_array[$i]['Stat'] > $max ? $stat_array[$i]['Stat'] : $max; } return $max; } $max_stat = stat_get_max($stat_array); The sorting will not be possible. Are you retrieving this from a database? Then add this to your query: ORDER BY Stat DESC For the above you can add: max(Stat) AS max_stat to your query to get the max
-
Try: echo "<a href=\"profile.php?userid={$row['userid']}\">" Also remember for valid HTML use " around values for attributes (href)
-
echo '<select name="select">'; echo '<option value="1">Size 9" - '.$row["price"].'</option>'; echo '<option value="2">Size 12" - '.$row["price"].'</option>'; echo '<option value="3">Size 14" - '.$row["price"].'</option>'; echo '</select>'; // $prices = array(1 => '', 2 => 4.39, 3 => 5.59); if (isset($_POST['select'])) { if (isset($prices[$_POST['select']])) { echo 'You have selected price ', $_POST['select'], '(', $prices[$_POST['select']], ')'; } }
-
echo '<p><a href="profile.php?id=',$row['id'],'">',$row['surname'],' ',$row['firstname'],'</a></p>';
-
www.google.com is a human-friendly version of an IP-address in order to translate www.google.com to an IP-address it uses reverse DNS lookup. To do that it reverses the URL and prepends a dot and asks their DNS server for the IP-address (every server in the network knows atleast one DNS server) .com.google.www A URL is normally www.google.com. but the extra dot in the end is optional and your browser will append it (http://www.google.com./) The first dot refers to the root-servers (ARPA) and they have the IP-addresses of every top-level domain server (com, be, net, org, ..) these individual top-level domains have the IP-address of every domain (google, phpfreaks, ..) these in turn have the IP-address of the actual server (www, www2, www3, ..) it's also possible to add more and get an URL like: ignace.developers.community.mazeltov.forum.domain.com You find these URL in academic communities but are rarely used by companies as an internet address (intranet is possible) due to usability reasons (to hard to remember).
-
My Tips: 1. Constructor should never do real work 2. The $encrypt = false|true is IMO bad use encrypt() and decrypt() instead or if that's not possible use a separate class for each. 3. If your using PHP5 then make everything PHP5 (format appropriatly) 4. MD5 is for hashing not encryption/decryption and dictionary lookups don't count (+ are to slow) see http://stackoverflow.com/questions/1240852/is-it-possible-to-decrypt-md5-hashes
-
There are a few ways you can do this however how do you want to keep track of these errors? Do they go into a file? multiple files? Please be more specific
-
need to create a link which deletes a record based on login info.
ignace replied to webguync's topic in PHP Coding Help
No otherwise you would have gotten the same error in that previous script. Otherwise remove all those lines ($temp = .. to $value = $temp : and just keep $value = addslashes($value); and see if the error then still turns up. -
Possibly because you are running XAMPP on the background?
-
need to create a link which deletes a record based on login info.
ignace replied to webguync's topic in PHP Coding Help
Same here so what line did you get that error? and what is on that line and the line above and below? -
Well sure but I'm gonna need some more info because your code does not make a lot of sense like what are the "else" for? When I rewrite it I get: $course_title = trim($course_title); $course_maxweeks = 48; if ('Business English' === $course_title) { $course_maxweeks = 2;//?? } else if ('IELTS Exam Preparation' === $course_title) { for ($week = 4; $week <= $course_maxweeks; $week += 4) { echo '<option>', $week, '</option>'; } } else if ('IELTS Foundation Test Course' === $course_title) { for ($week = 4; $week <= $course_maxweeks; $week += 4) { echo '<option>', $week, '</option>'; } } else { for ($week = 2; $week <= $course_maxweeks; ++$week) { echo '<option>', $week, '</option>'; } } Notice the question marks on top
-
Check if a user is following another user (social networking site)
ignace replied to adambedford's topic in PHP Coding Help
SELECT (CASE WHEN f.follower IS NULL THEN 'Yes' ELSE 'No' END) AS following, b.* FROM businesses b LEFT JOIN followers f ON b.id = f.followee What this code does is it selects all records from the table businesses and then left joins it with relationships. So let's assume we have 3 businesses and one user is following 2 of them: businesses 1, business_name1, telephone1, .. 2, business_name2, telephone2, .. 3, business_name3, telephone3, .. relationships 1, 1 1, 2 If I know perform a left join I get as a result: business_id, business_name, business_telephone, .., relationships_follower, relationships_followee 1, business_name1, telephone1, .., 1, 1 2, business_name2, telephone2, .., 1, 2 3, business_name3, telpehone3, .., NULL, NULL Notice the NULL these indicate businesses the user is not following so we could to this in PHP itself but MySQL has the data... (CASE WHEN r.follower IS NULL THEN 'Yes' ELSE 'No' END) AS following In PHP I can check if the user is following the business with: echo $row['following'];//Yes|No I use follower and followee to make it easier to read then to use id1, id2. You should also notice that a business does not follow a user so the followee column always contains the id of a business never that of a user therefor we don't need hard-to-read stuff like: (id1 = u.id or id1 = b.id) and (id2 = u.id or id2 = b.id) SELECT (CASE WHEN r.follower IS NULL THEN 'Yes' ELSE 'No' END) AS following, b.* FROM businesses b LEFT JOIN relationships r ON b.id = r.followee WHERE r.follower = $uid -
Cant add anything to this page, otherwise it will be blank...
ignace replied to KC8Alen's topic in PHP Coding Help
foreach ($_FILES ++ as $file) Is wrong and should be: foreach ($_FILES['upload'] as $file) But this only works if you uploaded multiple files or you declared name="upload[]"