RevCMS PHP Displaying Error

Kristopher

Photographer
Dec 25, 2010
803
68
I'm currently trying to get the script created below to show information from 2 tables, users and users_settings and so far its not displaying either. I know for a fact this script created works when you are just calling for one table in the database just not sure how to join both tables in one query if that makes sense.

<?php


$query = "SELECT username, respects_received, look FROM users AND users_settings WHERE rank < 7 ORDER BY respects_received DESC LIMIT 10";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){


?>

To call it <?php echo $row['respects_received']; ?>
 

Kristopher

Photographer
Dec 25, 2010
803
68
Can you explain better, i could not understand
So if you check the code below in the spoiler

<?php


$query = "SELECT username, respects_received, look FROM users AND users_settings WHERE rank < 7 ORDER BY respects_received DESC LIMIT 10";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){


?>



<div class="toplist">

<img src=" echo $row['look']; ?>&size=m&direction=3&head_direction=3&gesture=sml">

<div class="toplist">
<h1><?php echo $row['username']; ?></h1>
<p><?php echo $row['respects_received']; ?></p>
</div>

You see:
$query = "SELECT username, respects_received, look FROM users AND users_settings WHERE rank < 7 ORDER BY respects_received DESC LIMIT 10";

I'm trying to get that to display
<h1><?php echo $row['username']; ?></h1>
<p><?php echo $row['respects_received']; ?></p>
Which shows the username, figure, then the other table which is called at "AND users_settings" for the respects.
 

Haid

Member
Dec 20, 2011
363
449
You probably want to use an INNER JOIN, you should catch any errors as well as running the query, it'd tell you your query is failing.
Code:
SELECT u.username, u.look, us.respects_received FROM users u INNER JOIN user_settings us ON u.id = us.user_id

That's off the top of my head, assuming the settings table is using a user_id field; if not you'll need to change it to your own column name.
 

Kristopher

Photographer
Dec 25, 2010
803
68
You probably want to use an INNER JOIN, you should catch any errors as well as running the query, it'd tell you your query is failing.
Code:
SELECT u.username, u.look, us.respects_received look FROM users u INNER JOIN user_settings us ON u.id = us.user_id WHERE rank < 7 ORDER BY respects_received DESC LIMIT 10";

That's off the top of my head, assuming the settings table is using a user_id field; if not you'll need to change it to your own column name.
I'm very new when it comes to PHP, So it would look like whats above? I don't want it to display over a certain rank. So I need respects usernames and look to be called.
 

Haid

Member
Dec 20, 2011
363
449
Assuming you want something like
Code:
<div class="toplist">
    <?php 
    $query = "SELECT u.username, u.look, us.respects_received FROM users u INNER JOIN user_settings us ON u.id = us.user_id WHERE u.rank < 7 ORDER BY us.respects_received DESC LIMIT 10"; 
    $result = mysql_query($query);
       
    while($row = mysql_fetch_array($result)){
    ?>
        <div class="toplist">
            <img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure=<?=$row['look']?>&size=m&direction=3&head_direction=3&gesture=sml">
            <h1><?=$row['username']?></h1>
            <p><?=$row['respects_received']?></p>
        </div>
    <?php
    }
    ?>
</div>
 

Kristopher

Photographer
Dec 25, 2010
803
68
Assuming you want something like
Code:
<div class="toplist">
    <?php
    $query = "SELECT u.username, u.look, us.respects_received FROM users u INNER JOIN user_settings us ON u.id = us.user_id WHERE u.rank < 7 ORDER BY us.respects_received DESC LIMIT 10";
    $result = mysql_query($query);
      
    while($row = mysql_fetch_array($result)){
    ?>
        <div class="toplist">
            <img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure=<?=$row['look']?>&size=m&direction=3&head_direction=3&gesture=sml">
            <h1><?=$row['username']?></h1>
            <p><?=$row['respects_received']?></p>
        </div>
    <?php
    }
    ?>
</div>
Yeah accept it isn't showing anything from the tables.
 

Nicholas

Just another user:)
Mar 18, 2015
58
9
The easiest way is
<?php
$query = "SELECT u.username, u.look, s.respects_received FROM users u, user_settings s WHERE u.rank < 7 ORDER BY s.respects_received DESC LIMIT 10";
?>
Then use a stmt to execute the query and use while($stmt->fetch) { } for echoing multiple results
 
Oh yea some php versions do not support <?= ?>
 

Users who are viewing this thread

Top