Jump to content

[SOLVED] Help with the error.


cpharry

Recommended Posts

Hi,

 

Whenever I run my script that if being used in development to make a forum I get this message.

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\myprogram\xampp\htdocs\xampp\testcategories.php on line 18

 

 

What can I do to stop it ?

Link to comment
https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/
Share on other sites

$sql="SELECT * FROM forum WHERE ParentID='1'";
$result=mysql_query($sql);

while($row = mysql_fetch_array($result)){
    echo "<td width=\"53%\" align=\"center\" bgcolor=\"#E6E6E6\">
        <div align=\"left\">
            <a href=\"view_forums.php?id=" . $row['ID'] . "\">" . $row['Name'] . "</a>
        </div>
    </td>\n";
}

mysql_close();

<html>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum"; // Table name

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");

$sql="SELECT * FROM forum WHERE ParentID=1";
$result=mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result)){
    echo "<td width=\"53%\" align=\"center\" bgcolor=\"#E6E6E6\">
        <div align=\"left\">
            <a href=\"view_forums.php?id=" . $row['ID'] . "\">" . $row['Name'] . "</a>
        </div>
    </td>\n";
}

mysql_close();
?>
</tr>
</table>
</body>
</html> 

Ok, I got everything working except for I need it to list the categories for example.

 

Categories - Bold

Then the forums related to that under, not sure how to though. The present code dont allow that.

 

If I have them in the database the way that I want them, I mean the order of them. How do I get it so that the categories with a ParentID of 0 to be bold and the other to be normal.

 

Any suggestions ?

Here is the updated code.

 

<?php
$host="localhost"; // Host name
$username="simnetwo"; // Mysql username
$password="Sorry, cant put it in."; // Mysql password
$db_name="simnetwo_test"; // Database name
$tbl_name="forum"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql= "SElECT * FROM `forum` WHERE ParentID='1'";
$result=mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result)){

?>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td width="53%" align="center" bgcolor="#E6E6E6"><div align="left"><a href="view_forum.php?id=<? echo $row['ID']; ?>"><? echo $row['Name']; ?></a></div></td>
    <td width="15%" align="center" bgcolor="#E6E6E6"> </td>
    <td width="13%" align="center" bgcolor="#E6E6E6"> </td>
    <td width="13%" align="center" bgcolor="#E6E6E6"> </td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"><BR></td>
    <td align="center" bgcolor="#FFFFFF"> </td>
    <td align="center" bgcolor="#FFFFFF"> </td>
    <td align="center" bgcolor="#FFFFFF"> </td>
  </tr>
<?php
}
mysql_close();
?>
  <tr>
    <td align="right" bgcolor="#E6E6E6"> </td>
    <td align="right" bgcolor="#E6E6E6"> </td>
    <td align="right" bgcolor="#E6E6E6"> </td>
    <td align="right" bgcolor="#E6E6E6"> </td>
  </tr>
</table>
</body>
</html>

I have uploaded the new files to the net and it all works, displaying all the forums with the ParentID of 1. What I want to do now is the following..

 

----------------------          }

CATEGORY NAME                  } Would obviously like this to

----------------------          } be looped so that it continues.

RELEVANT FORUM                  }

 

 

Is this possible ?

 

The layout of the table would be how it would come out on the page; what I thought was that I could have a field where it has either a 0 or 1.

 

0 = Category

1 = Forum

 

Just how do I do that code wise.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.