There is showing error but i am not able to solve, please help:

error is :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/s/c/h/schowhan/html/mm/wp-content/themes/limauorange/single.php on line 67

code is here:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

		<div class="post" id="post-<?php the_ID(); ?>">
			<h2><?php the_title(); ?></h2>
			

			<div>
				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
<?php if ( function_exists('the_tags') ) { the_tags('<p>Tags: ', ', ', '</p>'); } ?>
				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<br />

				<p>
					<small>

						<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
							// Both Comments and Pings are open ?>
							

						<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
							// Only Pings are Open ?>
							Reviews are currently closed, but you can <a href="<?php trackback_url(true); ?> " rel="trackback">trackback</a> from your own site.

						<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
							// Comments are open, Pings are not ?>
							You can skip to the end and write a review.
						<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
							// Neither Comments, nor Pings are open ?>
							
						<?php } edit_post_link('Edit this entry.','',''); ?>

					</span>
</small>
				</p>

			</div>
					</div>

	<?php comments_template(); ?>
			<div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
			<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>

	<?php endwhile; else: ?>

		<p>Sorry, no posts matched your criteria.</p>

<?php endif; ?>
<?
$phoneid=the_ID();
echo $phoneid;
$query="SELECT testable.id, testable.name, testable.wpid, wp_posts.ID, wp_posts.post_title FROM testable, wp_posts where testable.wpid=$phoneid";  // query string stored in a variable
$rt=mysql_query($query);          // query executed 
echo mysql_error();                    // if any error is there that will be printed to the screen

while($nt=mysql_fetch_array($rt)){
echo "$nt[id] $nt[name] $nt[color] $nt[network] $nt[wpid]<br>";     // name class and mark will be printed with one line break at the end
}
?>

What is issue, please guide and help me, I am not expert to php, but trying to learn it. thanks.

One thing I notice, which is more than likely the problem, you are doing an old style join which is fine but you are not stating the column to join them on. for example, you need to make the following change:

$query="SELECT testable.id, testable.name, testable.wpid, wp_posts.ID, wp_posts.post_title FROM testable, wp_posts where testable.wpid=$phoneid";  // query string stored in a variable

needs to be

$query="SELECT testable.id, testable.name, testable.wpid, wp_posts.ID, wp_posts.post_title FROM testable, wp_posts where testable.testablepk = wp_posts.testablepk and testable.wpid=$phoneid";  // query string stored in a variable

or something of that nature to inform mysql on what columns you want to join the two tables on.

please explain the testable.testablepk = wp_posts.testablepk and testable.wpid=$phoneid

Thanks

OK, when you join two or more tables together you need a condition to join them on. What I am referring to is the primary key - foreign key relationship which is one of the main properties that defines a relational database. I think the standard join format is easier to understand and this is how the query would look in standard format.

$query="SELECT testable.id, testable.name, testable.wpid, wp_posts.ID, wp_posts.post_title FROM testable inner join wp_posts on testable.testablepk = wp_posts.testablepk where testable.wpid=$phoneid"; // query string stored in a variable

or if the primary key and foreign key columns are named the same:

$query="SELECT testable.id, testable.name, testable.wpid, wp_posts.ID, wp_posts.post_title FROM testable inner join wp_posts using(testablepk) where testable.wpid=$phoneid"; // query string stored in a variable

I just used "testablepk" as an example of what I would call the primary key of testable. But you would replace "testablepk" with what ever your primary key column is called in testable or wp_posts or whatever the relationship may be, but there has to be a relationship of some type. The relationship refers to a one to many relationship where if I have two tables, one named users and one named orders. One user can have multiple orders but one order cannot have more that one user so in the users table I would make the primary key of userpk and in the orders table I would have a foreign key called userpk which would refer to the primary key in the user table called userpk. This is the one to many relationship.

Does this help?

OK, when you join two or more tables together you need a condition to join them on. What I am referring to is the primary key - foreign key relationship which is one of the main properties that defines a relational database. I think the standard join format is easier to understand and this is how the query would look in standard format.

Does this help?

thanks R0bb0b ,

your explaination clears my confusion, got accurate result whatever I want.

Thanks Again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.