Jump to content

multiple table query


gwolff2005

Recommended Posts

Hi guys I need your help,

 

I am trying already for days to sort it out but does not work.

My file "pback.php" displays the mysql table "sp_users". I want to add the columns "school_name" and "school_address" from another table "sp_schools" (same database) at the right end of the displayed table in "pback.php" (after the column update)

I tried with leftjoin but it does not work.

Please help me. I am getting really frustrated.

Thank you...

 

<?php
$host="xxx"; // Host name
$username="xxx"; // Mysql username
$password="xxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="sp_users"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY user_id";
$result=mysql_query($sql);
?>
<style type="text/css">
<!--
.style2 {font-weight: bold}
.style3 {
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}
.style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; }
-->
</style>

<title>User overview</title><table width="486" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600">
<tr>
<td width="427">
  
    <div align="left">
      <table width="486" border="1" cellspacing="0" cellpadding="3">
        <tr>
          <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td>
        </tr>
        <tr>
          <td width="26" align="center"><span class="style2">id</span></td>
          <td width="70" align="center"><span class="style2">Name</span></td>
          <td width="114" align="center"><span class="style2">Lastname</span></td>
          <td width="146" align="center"><span class="style2">Email</span></td>
          <td width="88" align="center"><span class="style2">Update</span></td>
        </tr>
        <?php
while($rows=mysql_fetch_array($result)){
?>
        <tr>
          <td><span class="style10"><? echo $rows['user_id']; ?></span></td>
          <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td>
          <td><span class="style10"><? echo $rows['user_surname']; ?></span></td>
          <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td>
          <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td>
        </tr>
        <?php
}
?>
      </table>
    </div></td>
</tr>
</table>

<div align="left">
  <p>   </p>
  <p> </p>
  <p> </p>
  <p>
    <?php
mysql_close();
?>
  </p>
</div>

Link to comment
Share on other sites

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.