0

im trying to make a news page but i get this error

Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\News\Index.php on

line 37

and this is the code

    $category = mysql_query("SELECT icon FROM website.catnews WHERE ncatid=\'".         mysql_real_escape_string($news['category']). '\'');
    echo '<td>
    <td><a href = "news.php?cat='. $news['category'].'"><img src="./img/'.mysql_result($category, 'icon').'" alt="" /></a></td>';

and this is the whole source in mssql

    <br />
    <table style="width: 100%;">
        <tr>
        <td></td>
            <td id="key">Title</td>
            <td id="key" style="text-align: center;">Author</td>
            <td id="key" style="text-align: center;">Comments</td>
            <td id="key" style="text-align: center;">Views</td>
            <td id="key" style="text-align: center;">Date</td>
        </tr>
    <?php
        odbc_exec($mssql, 'USE [WEBSITE_DBF]');
        $count = odbc_exec($mssql, 'SELECT COUNT(*) as count FROM [web_news]');
        if(odbc_result($count, 'count') > 0) {
            $query = odbc_exec($mssql, 'SELECT TOP 10 * FROM [web_news] ORDER BY datetime DESC');
            while($news = odbc_fetch_array($query)) {
                $title = $news['title'];
                if(strlen($title) > 35) {
                    $title = substr($title, 0, 35).'...';
        }
                $comments = odbc_exec($mssql, 'SELECT COUNT(*) as count FROM [web_newscomments] WHERE nid=\''.mssql_escape_string($news['nid']).'\'');
                $category = odbc_exec($mssql, 'SELECT icon FROM [web_newscategories] WHERE ncatid=\''.mssql_escape_string($news['category']).'\'');
                echo '<tr>
                    <td><a href="news.php?cat='.$news['category'].'"><img src="./img/'.odbc_result($category, 'icon').'" alt="" /></a></td>
                    <td><a href="news.php?nid='.$news['nid'].'">'.$title.'</a></td>
                    <td style="text-align: center;">'.$news['author'].'</td>
                    <td style="text-align: center;">'.odbc_result($comments, 'count').'</td>
                    <td style="text-align: center;">'.$news['views'].'</td>
                    <td style="text-align: center;">'.date('Y-m-d', strtotime($news['datetime'])).'</td>';
            }
        } else {
            echo 'No news available!';
        }
    ?>
    </table>
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Dec 28 '13 at 23:16
  • Your query...its all in the query....try saving the query in an aux var and do an echo before the mysql query – Hackerman Dec 28 '13 at 23:17
  • 2
    `\'` in double quotes will be treated as `\'` not as `'`... but please it's 2013 now, so please start using a modern interface like MySQLi or PDO with prepared statements/bind variables – Mark Baker Dec 28 '13 at 23:18
  • @ Mark Baker i normaly use the odbc keys such as odbc_exec and ik need the \ thats why is done \'" because its for a link – Deathslayer Dec 29 '13 at 08:37

1 Answers1

0

SOLVED!

moved the icon table part into the news table and used:

<td><a href="news.php?cat='.$news['category'].'"><img src="./img/'. $news['icon'] .'" alt="" /></a></td>
instead of
<td><a href="news.php?cat='.$news['category'].'"><img src="./img/'.odbc_result($category, 'icon').'" alt="" /></a></td>