Jump to content

Recommended Posts

Here ill tell u what im doing.. Im trying to make one of those content boxes on my site get the latest users that registered.  Now in order to do this i need to do $result = mysql_query("SELECT * FROM users"); << sumthing like that  and that is php but i dont no how to get it in the content boxes since the content boxes are being called from the database and i made it so i can add,edit, and delete content boxes from the admin panel.  Is there a way that if i type sumthing in the content box such as users it will get all the users. i dont no what i can do plz help :(

Generally speaking, if you need to dynamically include php code from a database, your doing something wrong. You can try using eval on the code pulled from the database, but be far warned that this opens up a whole can of security issues. Re-read my first sentence.

For multiple uses, such as richest user, etc... This is an example of a function to switch based on what you need.

 

function content_box($switch) {

$number = 5;//number of items to display
switch($switch) {

case "newest":
$query = mysql_query("SELECT 'username' FROM `users` SORT BY 'registered_timestamp' DESC LIMIT $number");
while($row = mysql_fetch_array($query)){
echo $row['username']."<br>";
}
break;

case "richest":
$query = mysql_query("SELECT 'username' FROM `users` SORT BY 'money' DESC LIMIT $number");
while($row = mysql_fetch_array($query)){
echo $row['username']."<br>";
}
break;
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.