Jump to content

[SOLVED] I'm new to MYSQL and need a bit of help...


Tylor_Famous

Recommended Posts

Ok I am new to MySQL and this is the first real thing I am working on. I am making a forum and so far I managed to get half of it working. I can make the topics by sending them to the database (figured out how to do that last night thanks to a kind member here!) and now I am trying to display the stuff that is in the database. I am however having a bit of trouble with that...

 

I get the following error

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /mylink/mysqlforum/topiclist.php on line 37

 

Lines 36 - 41 are as follows

 

		$get_num_posts_sql = "SELECT COUNT(post_id) AS post_count FROM forum_posts WHERE topic_id = '".$topic_id."' ";
	$get_num_posts_res = mysql_query($mysql, $get_num_posts_sql) or die (mysql_error() );

	while ($posts_info = mysql_fetch_array($get_num_posts_res) ) {
		$num_posts = $posts_info['post_count'];
	}

 

I am using mysqladmin through godaddy.

 

Here is the whole code.

 

<?php
//connect to server
$host = 'XXXXXXX.myserver.net'; 
$user = 'XXXXX';
$pass = '#######';
$database = 'TylorsDB';
$mysql = mysql_connect($host,$user,$pass) or die(mysql_error());

//Get all topics and order them by date
$get_all_topics = "topic_id, topic_title, topic_create_time, topic_owner";

mysql_select_db ("TylorsDB");
$get_topics_res = mysql_query ("SELECT $get_all_topics FROM forum_topics ORDER BY topic_create_time DESC") or die(mysql_error());

if (mysql_num_rows($get_topics_res) < 1){
//If it is less then one then there is nothing in the dadabase. We will say then...
$display_block = "<p><em>No topics exist</em></p>";
}else{
//Create the displaly string
$display_block = "
<table cellpadding=\"3\" cellspacing=\"1\" border=\"1\">
<tr>
<th>TOPIC TITLE</th>
<th># of POSTS</th>
</tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {
	$topic_id = $topic_info['topic_id'];
	$topic_title = stripslashes($topic_info['topic_title']);
									//////////not sure if the fmt is needed here?
	$topic_create_time = $topic_info['fmt_topic_create_time'];
	$topic_owner = stripslashes($topic_info['topic_owner']);

	//Get number of posts

	$get_num_posts_sql = "SELECT COUNT(post_id) AS post_count FROM forum_posts WHERE topic_id = '".$topic_id."' ";
	$get_num_posts_res = mysql_query($mysql, $get_num_posts_sql) or die (mysql_error() );

	while ($posts_info = mysql_fetch_array($get_num_posts_res) ) {
		$num_posts = $posts_info['post_count'];
	}

	//add to display
	$display_block .="
	<tr>
	<td><a href=\"showtopic.php?topic_id=".$topic_id." \"> 
	<strong> ".$topic_title." </strong></a><br />
	Created on ".$topic_create_time." by ".$topic_owner." </td> 
	<td align=center> ".$num_posts." </td>
	</tr>";
}


	//free results
	mysql_free_result($get_topics_res);
	mysql_free_result($get_num_posts_res);

	//Close the table
	$display_block .= "</table>";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Topics in my forum</title>
</head>

<body>
<h1>Topics in My Forum</h1>
<?php echo $display_block; ?>

<p>Would you liked to <a href="addtopic.html">add a topic</a>?</p>

</body>
</html>

 

Any help would be great! Thanks so much.

Link to comment
Share on other sites

Ok I removed the $mysql and I believe I made a connection because now I get a new error

 

Unknown column 'topic_id' in 'where clause'

 

I think that is from this section

 

$get_num_posts_sql = "SELECT COUNT(post_id) AS post_count FROM forum_posts WHERE topic_id = '".$topic_id."' ";

 

Any ideas?

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.