Jump to content

MySQL query causing problems


unplugged_web

Recommended Posts

I've trying to make too queries to different tables in the database but one query causes problems with the other.

This query works okay
usedb( $GLOBALS['country_modules'][$GLOBALS['code']]['db_ex'],"dbExter" );$query="select id,name from symbols,symbols_map where symbol_id=symbols.id and visible=1 and id=".$GLOBALS['group_id'][$key]['id']." order by name";$symbols_group=dbselect( $query,"dbExter" );
but if I then use this one too:
usedb( $GLOBALS['country_modules'][$GLOBALS['code']]['db_ex'],"dbExter" );$query="select * from bullets where group_id=".$GLOBALS['group_id'][$key]['id']." and country like "%".$GLOBALS['code']."%" order by pos";$bullets_group=dbselect( $query,"dbExter" );
then I get this error:

 

Query failed:
select * from bullets where group_id= order by pos
(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 'order by pos' at line 1)
The second query works on it's own without any errors though.
Link to comment
Share on other sites

Well, look at the query, what's wrong with it? The error message is a major hint.

 

I understand the the first query is stopping the second one from getting the values for id and country but what I don't understand is why it' doing that and how to stop it doing it. It also appears that the first query is preventing any following arrays from displaying the results

Link to comment
Share on other sites

The query isn't "doing" anything except running a query on the database and returning the results. It's not "stopping" you from doing anything else, or otherwise interfering in any way. You didn't show the code that produces the query in the error message, but there is a value missing from that query. You're probably assuming that a certain variable has a value that it doesn't actually have.

Link to comment
Share on other sites

If I don't run the first query then the second one does have a variable (it's actually the same one in both queries). That's why I though it was removing it because it's the same variable. This is the code that produces the error message:

usedb( $GLOBALS['country_modules'][$GLOBALS['code']]['db_ex'],"dbExter" );$query="select * from bullets where group_id=".$GLOBALS['group_id'][$key]['id']." and country like "%".$GLOBALS['code']."%" order by pos";$bullets_group=dbselect( $query,"dbExter" );

The $GLOBALS['group_id'][$key]['id'] is the one thats in both queries

Link to comment
Share on other sites

That's not the code that produces this query:select * from bullets where group_id= order by posThat code has "country like ..." which is not in the query shown in the error message. It's not that code. But, yeah, something is missing. I would guess that you need to verify the value of $key and then the rest of that expression.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...