Jump to content

getting last entry in database


woodplease

Recommended Posts

i'm trying to get the username of the last person to enter something into a database table,and display it an html table. the problem is, the query is failing, and i get the error

"Table 'forum.posts' doesn't exist". if in the error message "forum" means the name of the database, and "posts" the name of the table, there is something wrong, as they both exist.

 

the code i'm using is below

$list = "SELECT * FROM section_main ORDER BY section_title";
$result = mysql_query($list) or die ("Query failed");
$numofrows = mysql_num_rows($result);
for($j = 0; $j < $numofrows; $j++) { 
   	$row = mysql_fetch_array($result);  
    echo "<tr><th>". $row['section_title']."</th></tr>";

$query2 = "SELECT * FROM section_sub WHERE section_id = '".$row['section_id']."' ORDER BY section_sub_title";
$result2 = mysql_query($query2) or die("Select Error :" . mysql_error()); 
$numofrows2 = mysql_num_rows($result2);
for($i = 0; $i<$numofrows2; $i++){
	$row2 = mysql_fetch_array($result2);
	echo "<tr><td><a href='display_forum.php?id={$row2[section_sub_id]}'>".stripslashes($row2[section_sub_title])."</a></td><td>"; 

	$new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ") or die ("Select Error :" . mysql_error()); //this is where the error message is from
$lastpost = mysql_fetch_assoc($new);
echo $lastpost['username']; 

echo"</td></tr>";
}
}

 

i've checked that the names of the tables and fields in the queries are correct, but i cant think of anything else that might be wrong.

 

any help would be great.

Link to comment
Share on other sites

Depending on the operating system... Capitalization of Table names is case-sensitive.

 

http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

 

Also, Do all of your section_sub_id's have an extra space at the end of them?

 

$new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ")

should be

$new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . "'")

Link to comment
Share on other sites

What method did you use to create this table? Have you successfully executed any queries using the posts table?

 

If you cannot find the reason why mysql would report that the table does not exist, you would need to post your table definition so someone could look.

 

You either have a spelling error, the actual table is in a different database, your have some non-printing characters as part of the table name (likely a space), or the table simply does not exist.

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.