Jump to content

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.

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.