[MySQL/PHP] CMS

Elite Diviner
Joined
Feb 28, 2007
Messages
446
Reaction score
4
I'm working on a Custom Mini-CMS for MapleStory. What I'm trying to do is display the users character's name once they login, so far all I have displaying is the information from one table, but since this requires two tables how would I do that? I'm not sure This is all I have so far.

PHP:
<?
session_start(); 
$myuser = $_SESSION['name'];
if(!session_is_registered(name)){
header("location:index.php");
}
?>
<html>
<body>
Coming Soon<br>(<?php echo $myuser;?> You have Logged in Successfully)
<a href="./logout.php">Logout</a><br>
</body>
</html>
<?php
include("./includes/config.php");
$result = mysql_query("SELECT * FROM odinms.accounts,odinms.characters WHERE name='$myuser'");
echo "<center>My, AmoraMS DB information";  
echo "<table border='0'>
<tr>
<th>Username</th>
<th>Last Login</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['lastlogin'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
echo "</center>";
?>
 
I don't think you understand what Im trying to do, I NEED to fetch data from 2 tables and display them, how could I do that? Also the 1st and 2nd table only have the row "Id" in common.
 
are you talking about something such as

PHP:
$sql = "SELECT
                c.Customer as Customer,
                c.ItemID as ItemID
                FROM
                customers as c
              LEFT JOIN
                items as i
              ON
                (c.Customer = i.CustomerID)
              WHERE
                i.Status=Online
              ORDER BY
                c.JoinDate
              DESC
              LIMIT 0,50
              ";
$result = @mysql_query($sql) or die(mysql_error());

This will allow you to use data from two different tables in a database?
 
Yeah, I just don't know what to add exactly, This is basically what I need it to do, Grab the account Id from the table called accounts, and then its also in the table called characters, and then display it. I can do the rest from there.
 
Hard to do without knowing exactly what name of accountid field is etc. but this should be able to point u in the right direction
PHP:
$sql = "SELECT
                a.AccountID as AccountID,
                FROM
                accounts as a
              LEFT JOIN
                characters as c
              ON
                (a.AccountID = c.AccountID)
              ";
$result  = mysql_query($sql) OR die(mysql_error());
$row = mysql_fetch_array($result);
echo $row['AccountID'];
 
You want to SELECT odinms.accounts.id,odinms.characters.account id FROM odinms.accounts and odinms.characters WHERE name=$myuser ..?
PHP:
$result = mysql_query("SELECT odinms.accounts.id,odinms.characters.`account id` 
                              FROM odinms.accounts 
                                  AND odinms.characters 
                              WHERE name='$myuser'");
 
Whats wrong with this?

PHP:
//================
// SQL Query
//================
include("./includes/config.php");
$result = mysql_query("SELECT * FROM odinms.accounts WHERE name='$myuser'");
echo "<center>My, AmoraMS DB information";  
echo "<table border='0'>
<tr>
<th>Username</th>
<th>ID</th>
<th>Character</th>
</tr>";
$row = mysql_fetch_array($result);
$_SESSION['id'] = $row['id'];
$accountid = $_SESSION['id'];
echo "SELECT * FROM odinms.characters WHERE id='$accountid <br>'";
while($row2 = mysql_fetch_array(mysql_query("SELECT * FROM odinms.characters WHERE id=".$accountid)))
{
echo "<tr>";
  	echo "<td>" . $row['name'] . "</td>";
	echo "<td>" . $row['id'] . "</td>";
	echo "<td>" . $row2['name'] . "</td>";
  	echo "</tr>";
}
echo "</table>";
echo "</center>";
//================
// End
//================
?>
 
Whats wrong with this?

PHP:
//================
// SQL Query
//================
include("./includes/config.php");
$result = mysql_query("SELECT * FROM odinms.accounts WHERE name='$myuser'");
echo "<center>My, AmoraMS DB information";  
echo "<table border='0'>
<tr>
<th>Username</th>
<th>ID</th>
<th>Character</th>
</tr>";
$row = mysql_fetch_array($result);
$_SESSION['id'] = $row['id'];
$accountid = $_SESSION['id'];
echo "SELECT * FROM odinms.characters WHERE id='$accountid <br>'";
while($row2 = mysql_fetch_array(mysql_query("SELECT * FROM odinms.characters WHERE id=".$accountid)))
{
echo "<tr>";
      echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row2['name'] . "</td>";
      echo "</tr>";
}
echo "</table>";
echo "</center>";
//================
// End
//================
?>

Well for starters it's a bit sloppy. Indent a little and separate HTML from PHP

stealarcher, I think that's a test.

Try this, and tell me what the error is if one happens.
PHP:
<?php

    //================
    // SQL Query
    //================
    include("./includes/config.php");
    $result = mysql_query('SELECT `id` FROM `odinms`.`accounts` WHERE `name`="'.$myuser.'"') or die(mysql_error());
    $find_id = mysql_fetch_array($result);
    $_SESSION['id'] = $find_id['id'];
    $query = mysql_query('SELECT `name` FROM `odinms`.`characters` WHERE `id`="'.$_SESSION['id'].'"') or die(mysql_error());
?>
<center>My, AmoraMS DB information
    <table border="0">
    <tr>
        <th>Username</th>
        <th>ID</th>
        <th>Character</th>
    </tr>
    <?php
        if(mysql_num_rows($query)<1) die( 'There are no results :( -> ' . $query . '<br />');
        
        while($row2 = mysql_fetch_array($query))
        {
        
            echo '
    <tr>
        <td>' . $myuser . '</td>
        <td>' . $_SESSION['id'] . '</td>
        <td>' . $row2['name'] . '</td>
    </tr>';
            
        }
        //================
        // End
        //================
    
    ?>
    </table>
</center>
 
Back