Jump to content

Recommended Posts

this works when customer_id = 46

 

mysql_select_db($database_imcrecycle, $imcrecycle);

$query_GetStates = "SELECT state_id, state_name, country FROM other_states WHERE customer_id = 46 UNION SELECT state_id, state_name, country FROM states ORDER BY country, state_name";

$GetStates = mysql_query($query_GetStates, $imcrecycle) or die(mysql_error());

$row_GetStates = mysql_fetch_assoc($GetStates);

$totalRows_GetStates = mysql_num_rows($GetStates);

 

 

 

This doesn't work even though $custID is 46

$custID=46;

 

mysql_select_db($database_imcrecycle, $imcrecycle);

$query_GetStates = "SELECT state_id, state_name, country FROM other_states WHERE customer_id = $custID UNION SELECT state_id, state_name, country FROM states ORDER BY country, state_name";

$GetStates = mysql_query($query_GetStates, $imcrecycle) or die(mysql_error());

$row_GetStates = mysql_fetch_assoc($GetStates);

$totalRows_GetStates = mysql_num_rows($GetStates);

 

This has got to be a syntax thing for $custID.  Which do I use

 

.$custID.

 

 

'".$custID."'

 

'.$custID.'

 

Link to comment
https://forums.phpfreaks.com/topic/55315-syntax-issue-i-think/
Share on other sites

The first section works i get my recordset just fine.

 

 

This is the error i get when I try to load with the other one.

I'm running php, dreamweaver 8, and mySQL 4.1.21

 

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 'UNION SELECT state_id, state_name, country FROM states ORDER BY country, state_n' at line 1

Link to comment
https://forums.phpfreaks.com/topic/55315-syntax-issue-i-think/#findComment-273432
Share on other sites

Precendence can be controlled by using (parenthesis), try separating your union out by using such. Also, you might want to reduce the ambiguous of which fields you have in the WHERE clause, so use aliasing... FROM other_stats AS ost.customer_id = 46... Also, there are a few flags that can be applied to the union, such as DISTINCT or ALL. Finally, MySQL 4.1.x doesn't effecienly use unions correctly, if not at all.

Link to comment
https://forums.phpfreaks.com/topic/55315-syntax-issue-i-think/#findComment-273447
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.