Jump to content

Recommended Posts

So I'm using this query to get review information from a database:

 

	$query ="
	SELECT *
	FROM artists, albums, reviews, users
	WHERE reviews.id = '$id'
	AND reviews.artist_id = artists.id	  
	AND albums.id = reviews.album_id
	AND users.id = albums.user_id

		";

 

Now this works fine on my local server but it does not work on my hosting server. It is because the query is not obtaining any results on the hosting server, however it always gets the result on my local.

 

And also, if i remove the "AND users.id = albums.user_id" part from my query, it will show up fine on my hosting server, but the user gets messed up. But apart from this, everything else works. I don't understand why it's doing it :/

 

Can anyone help?

sorry i cant comment further without actually seeing the tables :( just make sure the problem is with this query only, if it is its got something to do with structure and data, or it may turn out to be a problems some where else :) you never know. Best of Luck !

Heh strange way of relating tables. Try doing LEFT JOIN instead. Maybe the different version of MySQL on the hosted server doesn't like using your method.

 

Example:

<?php
$sql = "SELECT t1.*,t2.* FROM table1 t1
          LEFT JOIN table2 t2 on(t2.other_id=t1.id)
          WHERE t1.somefield = 'something'";
?>

Well I was never taught any other way of relating the tables. I've heard of joins, but never used them. Would you be able to explain to me what exactly they are and why they'd be better than what I'm currently using?

 

And no errors occur because I use an: if(mysql_num_rows($result) > 1) {

Okay, so I think I've found the problem. On my local server, the auto increment for my users.id starts from "0", whereas on my hosting server it starts from "1". Therefore, as the user who creates everything so far has had a userid of "0", this exists on my local but not on the hosting.

 

Does anybody know how I can make the users table start from 0 on my hosting (using phpmyadmin) instead of 1?!

That does fix it, thank you. But I wanted to know why it's adding one in the first place? I don't really want to be needing to run that query every time i import the database. I can give you any information you want about the table if you like?

 

Thanks!

A little thing Id like to point out, im not sure if you meant it but..

if(mysql_num_rows($result) > 1) {

will only display results if there are 2 or more records found.

Oh no, I have 0 on my actual php file but that was just an error I made when quickly typing it out. Thanks anyway!

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.