Jump to content

MySQL INNER JOIN won't work on page


rx3mer

Recommended Posts

Hi guys,

 

First of all I am new to this. I managed to create simple inner join request that displays some results. The problem I am having is that the results come up in the HeidiSQL software but they won't come on the page once coded.

 

heidi.jpg

include("../includes/config.php");

mysql_connect("$host", "$username", "$password")or die("cannot connect");
$link = mysql_select_db("$db_name")or die("cannot select DB");
 
$data = mysql_query("SELECT * FROM playlists WHERE HostID IN (SELECT HostID FROM hosts WHERE UserID = 33 ") or die(mysql_error()); 
while($info = mysql_fetch_assoc( $data )) { ?>

<?php ?>
<ul>
	<li>
		<div>
			<span>Name: <?php echo $info['PlaylistName']; ?></span>
		</div>
	</li>
</ul>
<?php  }  ?>

I get: 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

 

I am using MySQL and PHP :)

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/287347-mysql-inner-join-wont-work-on-page/
Share on other sites

the sql statement in your php code is not the same as when you directly ran it.

 

i recommend that your form your sql statement in a php variable, thereby separating the sql from the php code running the query, so that you can echo the sql statement to see exactly what it is.

I just found that MySQL can convert Queries to PHP. I know its probably not the best way to go, but I don't have much time at the moment.

 

SELECT *\n". "FROM playlists\n". "WHERE HostID IN (\n". "SELECT HostID\n". "FROM HOSTS\n". "WHERE UserID = 33)"

 

Thank you for your response!

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.