-3

I am a beginner/terrible when it comes to PHP/SQL, keep that in mind. Ok, so what I am trying to do is print some "values" or whatever you could call them with PHP/SQL, like this:

<?PHP

require_once
 ?>

Now this works just fine.

  • 4
    *"but I keep getting syntax errors"* - Being? – Funk Forty Niner Jan 14 '15 at 22:18
  • @Rizier123 sure, why not? – Marcin Orlowski Jan 14 '15 at 22:20
  • So you have an _SQL_ error – then why are you talking about an error _“when trying to print something (PHP)”_ …? – CBroe Jan 14 '15 at 22:22
  • And the error simply seems to be that you added _two_ `FROM` clauses to your statement, where there is only _one_ allowed. Anyone with even the most basic grasp of SQL syntax should be aware of that – and since you are not, it is time for you to go learn some SQL syntax basics. – CBroe Jan 14 '15 at 22:23
  • 3
    **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). *Learn* about **[prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and use [PDO](http://us1.php.net/pdo) – Jay Blanchard Jan 14 '15 at 22:24
  • So, if I understand this right, your syntax error is not in printing out values like you said. Its an SQL snytax error when you try to add two more tables to your already overcomplicated SQL query. I mean, that query is already so overcomplicated I cringe just looking at it. Are you sure you want to join in two more tables? – developerwjk Jan 14 '15 at 22:37

1 Answers1

0

Just add them like you added the rest of your select columns.

require_once("dbb.php");
$SQL="select 
         date_format(timestamp,'%Y %M %d') as datum,
         arena.namn as arena,
         concat(hemma.lagnamn,'-',borta.lagnamn)as lag,
         (select count(*) from mål where matchID=matchID and hemma.lagID=hemma) as h,
         (select count(*) from mål where matchID=matchID and borta.lagID=borta)as b,
         publiksiffror, 
         hemmagoal, 
         bortagoal
     from 
         matcher
     inner join 
         lag as hemma 
     on hemma.lagID = hemma
     inner join
         lag as borta 
     on borta.lagID = borta
     inner join 
         arena
     on matcher.arena=arena.arenaID;";

$result = mysql_query($SQL) or die(mysql_error());
while($rad = mysql_fetch_row($result))
{

 echo "<tr>";
 echo "<td>" . $rad[0] . "</td>";
 echo "<td>" . $rad[2] . "</td>";
 echo "<td>" . $rad[3] . "</td>";
 echo "<td>" . $rad[4] . "</td>";
 echo "<td>" . $rad[1] . "</td>";
 echo "<td>" . $rad[5] . "</td>";
 echo "</tr>";
 }  


 ?>
Richard Christensen
  • 2,046
  • 17
  • 28