27. august 2008 - 07:52Der er
13 kommentarer og 1 løsning
Hjælp til SQL syntax
Hvordan får jeg "indflættet" følgende:
$sql = "SELECT `bruger_id` FROM `brugere` WHERE EXISTS (SELECT `ip` FROM `online` WHERE `online`.`ip` = `brugere`.`ip` AND `brugere`.`bruger_id` != '')";
i:
$query=mysql_query("SELECT *,ROUND((UNIX_TIMESTAMP(`time`)-UNIX_TIMESTAMP(`first_time`))/60) AS online_time FROM `online`,`brugere` WHERE `online`.`ip` = `brugere`.`ip` AND `brugere`.`bruger_id` != '' ORDER BY time DESC"); while($row = mysql_fetch_array($query)) {
SELECT `b.bruger_id`, `o.ip`,*,ROUND((UNIX_TIMESTAMP(`o.time`)-UNIX_TIMESTAMP(`o.first_time`))/60) AS online_time FROM `brugere` b INNER JOIN `online` o ON `o.ip` = `b.ip`
Nu bliver jeg i tvivl, hvilken af nedenstående er korrekt?
1)
$query=mysql_query("SELECT `b.bruger_id`, `o.ip`,*,ROUND((UNIX_TIMESTAMP(`o.time`)-UNIX_TIMESTAMP(`o.first_time`))/60) AS online_time FROM `brugere` b INNER JOIN `online` o ON `o.ip` = `b.ip`");
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /customers/............
2)
$sql = "SELECT `b.bruger_id`, `o.ip`,*,ROUND((UNIX_TIMESTAMP(`o.time`)-UNIX_TIMESTAMP(`o.first_time`))/60) AS online_time FROM `brugere` b INNER JOIN `online` o ON `o.ip` = `b.ip`";
$result=mysql_query($sql,$db) or die (mysql_error()); while($myrow = mysql_fetch_assoc($result)) if ($result)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*,ROUND((UNIX_TIMESTAMP(`o.time`)-UNIX_TIMESTAMP(`o.first_time`))/60) AS online_' at line 1
$sql = "SELECT `bruger_id` FROM `brugere` WHERE EXISTS (SELECT `ip` FROM `online` WHERE `online`.`ip` = `brugere`.`ip` AND `brugere`.`bruger_id` != ''ORDER BY time DESC)"; $result=mysql_query($sql,$db) or die (mysql_error()); while($myrow = mysql_fetch_assoc($result)) if ($result) { echo '<tr><td>'.$myrow['bruger_id'].'</td><td>' .$row['ip'].'</td><td>'.$row['url'].'</td><td>'.$row['tid'].'</td><td>'.$row['online_time'].' min.</td></tr>';
}
Bruger_ID: IP-adresse: Befinder sig på: Log in tid: Online tid: Find min. Find (Job) min. Totter min.
Og denne giver:
$query=mysql_query("SELECT *,ROUND((UNIX_TIMESTAMP(`time`)-UNIX_TIMESTAMP(`first_time`))/60) AS online_time FROM `online`,`brugere` WHERE `online`.`ip` = `brugere`.`ip` AND `brugere`.`bruger_id` != '' ORDER BY time DESC"); while($row = mysql_fetch_array($query)) {
Bruger_ID: IP-adresse: Befinder sig på: Log in tid: Online tid: 85.81.20.*** / 09:50:27 1 min. 83.92.34.*** / 15:04:21 0 min. 80.62.130.*** / 09:55:00 0 min.
Resultatet jeg ønsker:
Bruger_ID: IP-adresse: Befinder sig på: Log in tid: Online tid: Find 85.81.20.*** / 09:50:27 1 min. Find (Job) 83.92.34.*** / 15:04:21 0 min. Totter 80.62.130.*** / 09:55:00 0 min.
$sql = "SELECT *,ROUND((UNIX_TIMESTAMP(`time`)-UNIX_TIMESTAMP(`first_time`))/60) AS online_time FROM online LEFT JOIN brugere ON online.ip = brugere.ip WHERE `bruger_id` != '' ORDER BY time DESC";
$result=mysql_query($sql,$db) or die (mysql_error()); while($myrow = mysql_fetch_assoc($result)) if ($result)
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.