thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

User Selection (Email/Id) Admin index. #64

Open siddiquedu opened 10 years ago

siddiquedu commented 10 years ago

Brother, I check all even your code from GitHub...But i can't see the user list from select option in the index.php(admin). here is my code.please help after a long journey to your series I am stuck now.

<div id="form-group">
        <label for="user">User:</label>
        <select class="form-control" name="user" id="user">
        <option value="0">No User</option>

        <?php

        $q = "SELECT email FROM users ORDER BY first ASC";
        $r = mysqli_query($dbc, $q);

        while ($user_list = mysqli_fetch_assoc($r)){

            $user_data = data_user($dbc, $user_list['email']);

            ?>
            <option value="0"><?php echo $user_data['fullname'];?></option>

        <?php } ?>
        </select>

    </div>
thedigicraft commented 10 years ago

hmm I don't see anything wrong. Try tossing a mysqli_error() in there....


<div id="form-group">
        <label for="user">User:</label>
        <select class="form-control" name="user" id="user">
        <option value="0">No User</option>

        <?php

        $q = "SELECT email FROM users ORDER BY first ASC";
        $r = mysqli_query($dbc, $q);
        if($r) {
        while ($user_list = mysqli_fetch_assoc($r)){

            $user_data = data_user($dbc, $user_list['email']);

            ?>
            <option value="0"><?php echo $user_data['fullname'];?></option>

        <?php } }else{

            echo mysqli_error($dbc); // See if mysql has any error to report.
            echo '<br>'.$q; // Output the query just to see if there is an obvious mistake.

         ?>
        </select>

    </div>
siddiquedu commented 10 years ago

Brother, I found no error. However, I re-arranged the codding like below: and I found only current user(who is logged in out of all).

here is points.

  1. If I use $data_user, i don't get member list at all.
  2. I found in functions there is $data_user but in my setup there is only $user
  3. If I use $user in index, I get only current member name.
  4. Now, I chnaged $user to $data_user in in setup, navigation and in index.
  5. Using email/id gives same phenomenon .
  6. If I use $data_user with php block like below I don't get no member at all again.

How can I get all member. How can I fix php block in this case.

creptor commented 9 years ago

seems like a database mistake

<div id="form-group">
        <label for="user">User:</label>
        <select class="form-control" name="user" id="user">
        <option value="0">No User</option>

        <?php

        $q = "SELECT email FROM [(users)<----check that it's the actual table name] ORDER BY [(first) check that this colum exist in the table]ASC";
        $r = mysqli_query($dbc, $q);

        while ($user_list = mysqli_fetch_assoc($r)){

            $user_data = data_user($dbc, $user_list['email']);<---- check the data_user function and that it's linked properly

            ?>
            <option value="0"><?php echo $user_data['fullname'];?></option>

        <?php } ?>
        </select>

    </div>

this should be your data_user function:

function data_user($dbc, $id) {     
    if(is_numeric($id)) {
        $cond = "WHERE id = '$id'";
    } else {
        $cond = "WHERE email = '$id'";
    }
    $q = "SELECT * FROM users $cond";   
    $r = mysqli_query($dbc, $q);

    $data = mysqli_fetch_assoc($r); 

    $data['fullname'] = $data['first'].' '.$data['last'];
    $data['fullname_reverse'] = $data['last'].', '.$data['first'];

    return $data;
}