PDA

View Full Version : Can't make it work, loop MySQL rows


Ludatha
03-28-2008, 09:54 PM
<?php
session_start();
include("header.php");

// START GET NAME OF CATEGORIE

require_once("classes/DbConnector.php");
$id = $_GET['id'];
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM forum_categorys WHERE id='$id'";
$result=mysql_query($query);
$exists = mysql_num_rows($result);
$rows=mysql_fetch_array($result);
$cat_name = $rows['name'];

// GET NAME OF CATEGORIE


?>
<!-- C. MAIN SECTION -->
<div class="main">
<h1 class="pagetitle">Ludatha : Forum : <?php echo"$cat_name"; ?></h1>

<!-- C.1 CONTENT -->
<div class="content">

<!-- CONTENT CELL -->
<div class="corner-content-1col-top"></div>
<div class="content-1col-nobox">
<h1>Forum, <?php echo"$cat_name"; ?></h1>
<center><?php include "ads/inline.php" ?></center>
<p>
<?php

// START LOOP OF TOPICS

echo"<table><tr><th class=\"top\" colspan=\"2\">Topics</th></tr>";
require_once("classes/DbConnector.php");
$cat_id = $_GET['id'];
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM forum_topics";
$result=mysql_query($query);
$exists = mysql_num_rows($result);
while($rows=mysql_fetch_array($result)){
echo" <tr><td><a href=viewpost.php?id=",$rows['id'],">",$rows['title'], "</a></td><td>Posts <b>",$rows['posts'], "</b>, Views <b>",$rows['views'], "</b></td></tr>";
}
mysql_close();
echo"</table>";

// END LOOP OF TOPICS




?></p></div><div class="corner-content-1col-bottom"></div></div><?php require_once("footer.php"); ?>

Using a similar code I can loop the categories but I cannot seem to get this code working.
The error that I get is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\wamp\www\Beta\setup\release\cat.php on line 45

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\wamp\www\Beta\setup\release\cat.php on line 46

Can anyone help me get this working?

Len Whistler
03-28-2008, 10:03 PM
Wrong reply

tomws
03-28-2008, 10:27 PM
You need to find out why you're not getting a result. Do something like this for line 45...
if ( !($result=mysql_query($query)) )
{
die (mysql_error()); // I think that's it :o
}


... in your favorite error detection coding. (You DO code up error detection, yes?)

Ludatha
03-28-2008, 11:09 PM
hey thanks I got it working :D