php - Cannot retrieve value of extra query per record? -


im working on table data users picked database.

the problem im not being able put 2 statements on while condition because im getting data different tables , rows.

@code

<?php $con = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database_name") or die(mysql_error());  $result = mysql_query("select * users");  $space_used = mysql_query("select sum(filesize) file file.userid=users.id , file.statusid=1");  $total_files = mysql_query("select count(id) file file.userid=users.id , file.statusid=1");  echo "<table class='table table-striped table-hover table-bordered' id='sample_editable_1'> <tr>     <th>username</th>     <th>type</th>                                        <th>email</th>     <th>last login</th>     <th>last ip</th>     <th>space_used</th>     <th>total_files</th>     <th>status</th> </tr>";  while($row = mysql_fetch_array($result)) {     echo "<tr>";         echo "<td>" . $row['username'] . "</td>";         echo "<td>" . $row['level'] . "</td>";         echo "<td>" . $row['email'] . "</td>";         echo "<td>" . $row['lastlogindate'] . "</td>";         echo "<td>" . $row['lastloginip'] . "</td>";         echo "<td>" . $space_used['space_used'] . "</td>";         echo "<td>" . $total_files['total_files'] . "</td>";         echo "<td>" . $row['status'] . "</td>";     echo "</tr>"; }  echo "</table>"; mysql_close($con); ?> 

what im getting values of username, level, email, lastlogindate, lastloginip & status. 2 not showing on table ones of second condition want implement: space_used , total_files.

what doing wrong? im not expert in php , fact had mix of tutorials , script im chaning result had complicated little bit.

thanks

you need rework query, can resume 3 queries single query using join:

  select u.*,           sum(f.filesize) space_used,           count(f.id) total_files     users u     join file f        on f.userid = u.id , f.statusid = 1 group u.id 

then can read this:

<?php // database info $db_host = 'your mysql server host'; $db_user = 'your username'; $db_pass = 'your password'; $db_name = 'your database name'; $con = new mysqli($db_host, $db_user, $db_pass, $db_name); if($con->connect_error) {         die('connect error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); }  if (!$result = $con->query("select u.*,                                    sum(f.filesize) space_used,                                     count(f.id) total_files                               users u                               join file f                                  on f.userid = u.id , f.statusid = 1                           group u.id")) {     die('select query error: ' . $con->error); } ?> <table class='table table-striped table-hover table-bordered' id='sample_editable_1'>     <tr>         <th>username</th>         <th>type</th>                                            <th>email</th>         <th>last login</th>         <th>last ip</th>         <th>space_used</th>         <th>total_files</th>         <th>status</th>     </tr> <?php while ($row = $result->fetch_array()) { ?>     <tr>         <td><?php echo $row['username']; ?></td>         <td><?php echo $row['level']; ?></td>         <td><?php echo $row['email']; ?></td>         <td><?php echo $row['lastlogindate']; ?></td>         <td><?php echo $row['lastloginip']; ?></td>         <td><?php echo $row['space_used']; ?></td>         <td><?php echo $row['total_files']; ?></td>         <td><?php echo $row['status']; ?></td>     </tr> <?php } $con->close(); ?> </table> 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -