ben.hornshaw Posted March 4, 2010 Share Posted March 4, 2010 Hi i am new to PHP and this forum and wondered if one of you guys could give me a hand. I have a php page that references 4 tables, this is fine but i need to query one table and then query the other three relative to the first query. this i made work on one table as follows. mysql_select_db($database_entinfo, $entinfo); $query_Manufacturer = sprintf("SELECT * FROM Manufacturer WHERE Manufacturer_ID = %s", GetSQLValueString($colname_Manufacturer, "int")); $Manufacturer = mysql_query($query_Manufacturer, $entinfo) or die(mysql_error()); $row_Manufacturer = mysql_fetch_assoc($Manufacturer); $totalRows_Manufacturer = mysql_num_rows($Manufacturer); So this finds the record in the Manufacturers table that has the same ID as the Manufacturer field from the Equipment Table the page already has a record set for Therefore i just added more of these but i get an error saying unexpected "," my code is as follows $colname_Equipment = "-1"; if (isset($_GET['EquipID'])) { $colname_Equipment = $_GET['EquipID']; } mysql_select_db($database_entinfo, $entinfo); $query_Equipment = sprintf("SELECT * FROM Equipment WHERE Equipment_ID = %s", GetSQLValueString($colname_Equipment, "int")); $query_limit_Equipment = sprintf("%s LIMIT %d, %d", $query_Equipment, $startRow_Equipment, $maxRows_Equipment); $Equipment = mysql_query($query_limit_Equipment, $entinfo) or die(mysql_error()); $row_Equipment = mysql_fetch_assoc($Equipment); if (isset($_GET['totalRows_Equipment'])) { $totalRows_Equipment = $_GET['totalRows_Equipment']; } else { $all_Equipment = mysql_query($query_Equipment); $totalRows_Equipment = mysql_num_rows($all_Equipment); } $totalPages_Equipment = ceil($totalRows_Equipment/$maxRows_Equipment)-1; $colname_Manufacturer = "-1"; if (isset($row_Equipment['Manufacturer'])) { $colname_Manufacturer = $row_Equipment['Manufacturer']; } mysql_select_db($database_entinfo, $entinfo); $query_Manufacturer = sprintf("SELECT * FROM Manufacturer WHERE Manufacturer_ID = %s", GetSQLValueString($colname_Manufacturer, "int")); $Manufacturer = mysql_query($query_Manufacturer, $entinfo) or die(mysql_error()); $row_Manufacturer = mysql_fetch_assoc($Manufacturer); $totalRows_Manufacturer = mysql_num_rows($Manufacturer); mysql_select_db($database_entinfo, $entinfo); $query_Connectors = "SELECT * FROM Connectors WHERE Conn_ID = %s", GetSQLValueString($colname_Standard Connector, "int")); $Connectors = mysql_query($query_Connectors, $entinfo) or die(mysql_error()); $row_Connectors = mysql_fetch_assoc($Connectors); $totalRows_Connectors = mysql_num_rows($Connectors); mysql_select_db($database_entinfo, $entinfo); $query_DataConnectors = "SELECT * FROM Connectors WHERE Conn_ID = %s", GetSQLValueString($colname_Data Connector, "int")); $DataConnectors = mysql_query($query_DataConnectors, $entinfo) or die(mysql_error()); $row_DataConnectors = mysql_fetch_assoc($DataConnectors); $totalRows_DataConnectors = mysql_num_rows($DataConnectors); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/194172-select-from-help/ Share on other sites More sharing options...
harristweed Posted March 4, 2010 Share Posted March 4, 2010 this is the first error $query_Connectors = "SELECT * FROM Connectors WHERE Conn_ID = %s", GetSQLValueString($colname_Standard Connector, "int")); Space in variable name $colname_Standard Connector and same error furter down..... Quote Link to comment https://forums.phpfreaks.com/topic/194172-select-from-help/#findComment-1021642 Share on other sites More sharing options...
ben.hornshaw Posted March 5, 2010 Author Share Posted March 5, 2010 Fantastic but my collumn name has a space in it, i know bad practise, im sorry. but is there a way of getting round this? Quote Link to comment https://forums.phpfreaks.com/topic/194172-select-from-help/#findComment-1021727 Share on other sites More sharing options...
harristweed Posted March 5, 2010 Share Posted March 5, 2010 You can't have a variable name that has a space in it! you have the ID as a variable Why not... $query_Connectors= sprintf("SELECT * FROM Connectors WHERE Conn_ID = %s", mysql_real_escape_string($_GET['EquipID'])); Quote Link to comment https://forums.phpfreaks.com/topic/194172-select-from-help/#findComment-1021843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.