Jump to content

Can't figure out this error


Darkmatter5

Recommended Posts

Here's the error.

 

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 '.genre_id=4' at line 1

 

Here's the tables

 

games

game_id

title

url_wikipedia

1

Fallout3

none

2

Fable 2

url_wikipedia

 

game_genres

game_id

genre_id

1

1

2

1

 

genres

genre_id

genre

1

Action Role-Playing

2

Sports

 

Here's the query:

SELECT g.game_id, g.title, g.url_wikipedia, ge.genre

FROM games AS g

INNER JOIN game_genres AS gg ON gg.game_id=g.game_id

INNER JOIN genres AS ge ON ge.genre_id=gg.genre_id

WHERE ge.genre_id=1

GROUP BY g.title

ORDER BY g.title ASC

LIMIT 0, 20

 

What's with the error?  It'll get the data correctly, but produces this error and messed up things when it's all run in PHP.

Link to comment
Share on other sites

case "games";
                    $quebeg="SELECT g.game_id, g.title, g.url_wikipedia, ge.genre";
                    $quemid="FROM games AS g
                             INNER JOIN game_genres AS gg ON gg.game_id=g.game_id
                             INNER JOIN genres AS ge ON ge.genre_id=gg.genre_id";
                    if(is_numeric($system)) {
                        $queend="GROUP BY g.title ORDER BY g.title ASC";
                        if(is_numeric($genre)) {
                            if($char=='num') { $quewr="WHERE gs.system_id=$system AND ge.genre_id=$genre AND title REGEXP '^[0-9]'"; }
                            elseif(is_string($char)) {
                                if($char=='all') { $quewr="WHERE gs.system_id=$system AND ge.genre_id=$genre"; }
                                else { $quewr="WHERE gs.system_id=$system AND ge.genre_id=$genre AND title LIKE '$char%'"; }
                            }
                        }
                        else {
                            if($char=='num') { $quewr="WHERE gs.system_id=$system AND title REGEXP '^[0-9]'"; }
                            elseif(is_string($char)) {
                                if($char=='all') { $quewr="WHERE gs.system_id=$system"; }
                                else { $quewr="WHERE gs.system_id=$system AND title LIKE '$char%'"; }
                            }
                        }
                    }
                    else {
                        $queend="GROUP BY g.title ORDER BY g.title ASC";
                        if(is_numeric($genre)) {
                            if($char=='num') { $quewr="WHERE ge.genre_id=$genre AND title REGEXP '^[0-9]'"; }
                            elseif(is_string($char)) {
                                if($char=='all') { $quewr="WHERE ge.genre_id=$genre"; }
                                else { $quewr="WHERE ge.genre_id=$genre AND title LIKE '$char%'"; }
                            }
                        }
                        else {
                            if($char=='num') { $quewr="WHERE title REGEXP '^[0-9]'"; }
                            elseif(is_string($char)) {
                                if($char=='all') { $quewr=" "; }
                                else { $quewr="WHERE title LIKE '$char%'"; }
                            }
                        }
                    }
                    //echo "$quebeg $quemid $quewr $queend LIMIT $offset, $rowsPerPage<p>";
THIS IS THE LINE->  $result=mysql_query("$quebeg $quemid $quewr $queend LIMIT $offset, $rowsPerPage") or die(mysql_error());
                    if(mysql_num_rows($result)==0) { echo "No games fitting that query found!"; }
                    else {
                        echo "<table class='listings' width='700' cellpadding='4' cellspacing='0' border='0'><tr><th>Title</th><th width='200'>System(s)</th><th width='100'>Genre</th><th>Wikipedia link</th><th width='50'> </th></tr>";
                        while($row1=mysql_fetch_array($result)) {
                            if($i==0) { $tgcolor="#B0B0B0"; }
                            elseif($i==1) { $tgcolor="#888888"; }
                            $query="SELECT GROUP_CONCAT(DISTINCT s.name ORDER BY s.name ASC SEPARATOR ', ') AS sysnames
                                    FROM games AS g
                                    INNER JOIN game_systems AS gs ON g.game_id=gs.game_id
                                    INNER JOIN systems AS s ON gs.system_id=s.system_id
                                    WHERE g.game_id=$row1[game_id]
                                    GROUP BY g.title";
                            $row2=mysql_fetch_array(mysql_query($query));
                            echo "<tr bgcolor=$tgcolor><td class='medium_text'><b><a href='title.php?s=all&g=all&c=all&i=$row1[game_id]'>$row1[title]</a></b></td><td align='center' class='small_text'>" .wordwrap($row2['sysnames'],30,"<br>",FALSE). "</td><td align='center' class='small_text'>$row1[genre]</td><td align='center'>";
                            if(empty($row1['url_wikipedia'])) { echo " "; }
                            else { echo "<a href='$row1[url_wikipedia]'>Click here</a>"; }
                            if($rights['priv_admin']==1) { echo "</td><td><input type='button' onclick='parent.location=\"res_editgame.php?i=$row1[game_id]\"' value='Edit game'></td></tr>"; }
                            else { echo "</td><td> </td></tr>"; }
                            if($i==0) { $i=1; }
                            elseif($i==1) { $i=0; }
                        }
                        $quecnt="SELECT COUNT(*) AS numrows FROM games$quewr";
                        $rescnt=mysql_query($quecnt) or die(mysql_error());
                        $row=mysql_fetch_array($rescnt);
                        $numrows=$row['numrows'];
                        //How many pages we have
                        $maxPage=ceil($numrows/$rowsPerPage);
                        $self=$_SERVER['PHP_SELF'];
                        $nav='';
                        for($page=1; $page<=$maxPage; $page++) {
                            if($page==$pageNum) { $nav.=" $page "; }
                            else { $nav.=" <a href=\"$self?s=$_GET[s]&g=$_GET[g]&c=$_GET[c]&page=$page\">$page</a> "; }
                        }
                        if($pageNum>1) {
                            $page=$pageNum-1;
                            $prev=" <a href=\"$self?s=$_GET[s]&g=$_GET[g]&c=$_GET[c]&page=$page\">[Prev]</a> ";
                            $first=" <a href=\"$self?s=$_GET[s]&g=$_GET[g]&c=$_GET[c]&page=1\">[First Page]</a> ";
                        }
                        else {
                            $prev=' ';
                            $first=' ';
                        }
                        if($pageNum<$maxPage) {
                            $page=$pageNum+1;
                            $next=" <a href=\"$self?s=$_GET[s]&g=$_GET[g]&c=$_GET[c]&page=$page\">[Next]</a> ";
                            $last=" <a href=\"$self?s=$_GET[s]&g=$_GET[g]&c=$_GET[c]&page=$maxPage\">[Last Page]</a> ";
                        }
                        else {
                            $next=' ';
                            $last=' ';
                        }
                        echo "<tr><td colspan='4' align='center'><span class='large_text'>$first $prev $nav $next $last</span></td></tr>";
                        echo "</table>";
                    }
                    break;

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.