Jump to content

Recommended Posts

19 hours ago, ginerjm said:

All you had to do was add an echo and then cut and paste it to here.

Ok - had enough.

 

That's the echo code I used for all queries

 

<p>Role changing query</p>
<?php

$update = "UPDATE blog.roles SET role_status = '0' WHERE id ='2'";

$uresult = $db->query($update) or die ($update."<br/><br/>".mysql_error());

 if($uresult && $db->affected_rows() === 1)
        {
    echo ('Role status changed successfuly'); }
else {
    echo ('Role status changing failed'); }
?>

<br>

<p>Users with role blocked selecting query</p>
<?php

$selectb = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '0'";

 $sbresult = mysql_query($selectb) or die ($selectb."<br/><br/>".mysql_error());

while($sbrow = mysql_fetch_assoc($sbresult))
    {
    echo $sbrow['username'];    // Print a single column data
    echo print_r($sbrow); }     // Print the entire row data
?>

<br>

<p>Users with role allowed selecting query</p>
<?php

$selecta = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '1'";

 $saresult = mysql_query($selecta) or die ($selecta."<br/><br/>".mysql_error());

while($sarow = mysql_fetch_assoc($saresult))
    {
    echo $sarow['username'];     // Print a single column data
    echo print_r($sarow); }      // Print the entire row data

 

and that's the output

 

Role changing query
Role status changed successfuly

Users with role blocked selecting query
Editor@userArray ( [username] => Editor@user ) 1

Users with role allowed selecting query
Admin@userArray ( [username] => Admin@user ) 1User@userArray ( [username] => User@user ) 1

 Actually, I don't know.. aren't you believe that the queries are working or what!!

19 hours ago, Barand said:

Did you check what the find_by_id() function wasputting in the array?

 

yes the id of the user from the users table ( if you used it with the users )

 

function find_by_id($table,$id)
{
  global $db;
  $id = (int)$id;
    if(tableExists($table)){
          $sql = $db->query("SELECT * FROM {$db->escape($table)} WHERE id='{$db->escape($id)}' LIMIT 1");
          if($result = $db->fetch_assoc($sql))
            return $result;
          else
            return null;
     }
}

 

4 minutes ago, Barand said:

Because it uses "SELECT * ... "  it tells us nothing about what the keys are in the returned array. They will be the same as the column names, but we don't know the user table structure.

That's the users table structure

    id       user_name       user_level       
    ---------------------------------------
    1        Admin               1                                 
    2        Editor1             2                                  
    3        User1               3                                  
    4        Editor2             2                                 
    5        User2               3                                   
    6        User3               3 

 

On 5/5/2023 at 3:13 PM, NaderH said:

It printed all user data

Array
(
    [id] => 
    [name] => 
    [username] => 
    [password] => 
    [user_level] => 
    [image] => 
    [status] => 
    [last_login] => 
)

Where does the above data come from then?

13 minutes ago, Barand said:

Because it uses "SELECT * ... "  it tells us nothing about what the keys are in the returned array. They will be the same as the column names, but we don't know the user table structure.

That's the main structure

Array
(
    [id] => 
    [name] => 
    [username] => 
    [password] => 
    [user_level] => 
    [image] => 
    [status] => 
    [last_login] => 
)

But this this the one I am working on ( for testing)

Array
(
    [id] => 
    [username] => 
    [user_level] => 
)

 

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.