Ecommerce web host - Hey, a function. Shouldn t this go in an

Hey, a function. Shouldn t this go in an include file, such as outputfunctions.php? Perhaps, and you could certainly do that if you wanted to. However, this function is very specific to this file, so it really doesn t need to go in an include file. It s up to you, really. function echoUserList($lvl) { To use the array you created earlier within this function, you must declare it global. Now the function can access the data in the array. global $a_users; This function will be called more than once. Each time, a different value will be contained in the $lvl variable. The following SQL pulls the appropriate data according to the $lvl value: $sql = SELECT user_id, name, email FROM cms_users . WHERE access_lvl = $lvl ORDER BY name ; $result = mysql_query($sql) or die(mysql_error()); If no users are found in the database for this access level, you display a message explaining that those users were not found. You do this by using the array you created earlier: if (mysql_num_rows($result) == 0) { echo No . $a_users[$lvl] . created. ; Auser cannot modify his or her own record. Instead, his or her name is shown in plain text, with no link. } else { while ($row = mysql_fetch_array($result)) { if ($row[ user_id ] == $_SESSION[ user_id ]) { echo htmlspecialchars($row[ name ]) .
n ; Otherwise, the user s name is displayed on the screen, as a link that loads useraccount.php. } else { echo . htmlspecialchars($row[ name ]) .
n ; } Here s the end of the function. Note that nothing has been output to the screen yet. } } } 457 Building a Content Management System
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Leave a Reply