Jump to content

Query categories and games


Davie33

Recommended Posts

Hi all am haiving abit of a problem am trying to query 6 categories with 6 games each.With the code i done is only showing one cat with 6 games.

How can i fix this ?.

If you go to games-flash.co.uk you will see at the bottom of the home page that only one cat shows.

 

php code.

    <div class="catgames">    <?php    $query = yasDB_select("SELECT * FROM categories WHERE active='yes' AND home='yes' ORDER BY id DESC LIMIT 6",false);    while ($row = $query->fetch_array(MYSQLI_ASSOC)) {    $catid = $row['id'];    $query = yasDB_select("SELECT id, title, thumbnail, description, plays, active FROM games WHERE category=".$catid." AND active='1' ORDER BY id DESC LIMIT 6",false);    echo '<ul><li class="even"><div id="catheadergms">';    if ($setting['seo'] == 'yes') {    echo '<a href="' . $setting['siteurl'] . 'category/' . $row['id'] .'/1.html">'.$row['name'].'</a>';    } else {    echo '<a href="' . $setting['siteurl'] . 'index.php?act=cat&id=' . $row['id'] .'">'.$row['name'].'</a>';    }    echo '</div>';    while ($games = $query->fetch_array(MYSQLI_ASSOC)) {    $pic_settings = array('w'=>115,'h'=>72);    $gameurl = prepgame($games['title']);    $games['description'] = stripslashes($games['description']);    if (file_exists($games['thumbnail'])) {    $thumbnail = urldecode($games['thumbnail']);    } else {    $thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';    }    if ($setting['seo']=='yes') {    $gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';    } else {    $gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];    }    $hinttext = '<h2 class="title">'.$games['title'].'</h2>'.$games['description'];    $hinttext = str_replace(array("\r\n", "\r", "\n"), '<br/>', $hinttext);    $hinttext = str_replace(array('"',"'"),array('"','’'),$hinttext);    ?>                    <div class="inner_box4"><a href="<?php echo $gurl;?>"><img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays" width="115" height="72" /></a>    </div>       <?php }    echo '</li></ul>';    }    $query->close();    ?>    <div class="clear"></div>        </div>

Edited by Davie33
Link to comment
Share on other sites

The query would be something like this

SELECT c.id as catid
    , c.name 
    , g.id as gameid
    , g.title
    , g.thumbnail
    , g.description
    , g.plays
    , g.active
FROM categories c
    INNER JOIN games g ON c.id = g.category AND g.active='1' 
WHERE c.active = 'yes' AND c.home='yes' 
ORDER BY catid DESC , gameid DESC
Link to comment
Share on other sites

Thanks Barand,sry was reading up on what Jacques1 said.

I think i need to recode the code again to get it to work with what you got but with a small tweak on the sql as you don't really need g. or c.added.

As i have seen this in my script which i forgot about i had something like that sql for my forum.

Link to comment
Share on other sites

... but with a small tweak on the sql as you don't really need g. or c.added.

 

You do if you have the same column names in both tables otherwise you get an ambiguous column name error. And purely as a form of documentation I prefer to be explicit about which tables the columns are coming from

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.