根据用户在php中的选择生成信息

I have any information stored in a database which is picked up and displayed with radio buttons. I like to display information from the database based on what radio buttons the user has chosen. For example I have a list of activities a user may have done and based on what they have chosen I would like to display other activities they could do. I can get the system to display random information from the database using RAND(). Can't find any online tutorials for this.

Please give us more information or a concrete example of your problem, all i can tell you is that your SQL request in your second code snippet will probably not give the expected result :

SELECT * FROM activities ORDER BY RAND() LIMIT 1

You probably don't want to ORDER BY RAND() (may be impossible) nor LIMIT 1, you just want to pickup one random row from your mysql results, am i right ?

If i am right just get the full resultset (with no order by / no limit clause), generate a random with php (between 0 and resultset size) the pick the expected row from resultset.

Ok, so i don't know your database structure, but lets say you have a table for activities and table for the activities the user does. For the sake of this example we will call them activities and activities_by_user

The activities table will have columns

activity_id | activity

The activities_by_user will have columns

activity_id | user_id

So your display code will look something like this

$query = "SELECT activities.*, activities_by_user.activity_id AS has_activity FROM activities LEFT JOIN activities_by_user ON activities_by_user.activity_id = activities.activity_id AND user_id = 1 ORDER BY RAND()";
// The user_id in just for example. There should be the id of the logged user
$result = mysqli_query($con, $query) or die('Error');
while($row = mysqli_fetch_object($result)) {
      // If the has_activity field is not null, then the user does that activity
      $checked = (isset($row->has_activity) && $row->has_activity != null) ? 'checked' : '';
      echo '<label><input type="checkbox" name="activities[]" value="' . $row->activity_id . '" ' . $checked . ' />' . $row->activity . '</label>';
}

This will generate checkboxes for all the activities and will check does who are done by the user.