Codeman0013 Posted September 22, 2006 Share Posted September 22, 2006 Hey is it possible to run a query and not allow the others to run until the ones above it have been executed like on page load i only want one thing to load and as the user submits then run the next on and so on here is my code if its possible ot change it i would appreciate any tips.. mysql_select_db($database_conn_dj, $conn_dj);$query_rs_industry = "SELECT industry_id, industry_name FROM tbl_industry ORDER BY industry_name ASC";$rs_industry = mysql_query($query_rs_industry, $conn_dj) or die(mysql_error());$row_rs_industry = mysql_fetch_assoc($rs_industry);$totalRows_rs_industry = mysql_num_rows($rs_industry);mysql_select_db($database_conn_dj, $conn_dj);$query_rs_productcategory = "SELECT productCat_id, productCat_name, industry_id FROM tbl_productcat WHERE industry_id = '$_GET[industry_id]' ORDER BY productCat_name";$rs_productcategory = mysql_query($query_rs_productcategory, $conn_dj) or die(mysql_error());$row_rs_productcategory = mysql_fetch_assoc($rs_productcategory);$totalRows_rs_productcategory = mysql_num_rows($rs_productcategory);mysql_select_db($database_conn_dj, $conn_dj);$query_rs_product = "SELECT products_id, products_name, productCat_id FROM tbl_products WHERE productCat_id = '$_GET[productCat_id]' ORDER BY products_name";$rs_product = mysql_query($query_rs_product, $conn_dj) or die(mysql_error());$row_rs_product = mysql_fetch_assoc($rs_product);$totalRows_rs_product = mysql_num_rows($rs_product);mysql_select_db($database_conn_dj, $conn_dj);$query_rs_outsidena = "SELECT * FROM intl_countries ORDER BY intl_countries.name";$rs_outsidena = mysql_query($query_rs_outsidena, $conn_dj) or die(mysql_error());$row_rs_outsidena = mysql_fetch_assoc($rs_outsidena);$totalRows_rs_outsidena = mysql_num_rows($rs_outsidena); Link to comment Share on other sites More sharing options...
aquatsr Posted September 23, 2006 Share Posted September 23, 2006 you could do something like this, say you want to run queries in $sql1, #sql2 and $sql3 in order: <?php$result1 = mysql_query($sql1);if (isset($result1)) {$result2 = mysql_query($sql2);}if (isset($result2)) {$result3 = mysql_query($sql3);}?> Something along those lines. Link to comment Share on other sites More sharing options...
redsun Posted September 23, 2006 Share Posted September 23, 2006 aquatsr's code is running third query after second and second after first…If you want to run 'query_rs_industry' only if user submitted form data that have to be loaded from tbl_industry or run query 'query_rs_productcategory' only if user submitted form data that have to be loaded from tbl_productcat etc., then you can specify your criteria in If-Then-Else statement.For example (change field_name to your one): If ($_POST["field_name"] == "industry")mysql_select_db($database_conn_dj, $conn_dj);$query_rs_industry = "SELECT industry_id, industry_name FROM tbl_industry ORDER BY industry_name ASC";$rs_industry = mysql_query($query_rs_industry, $conn_dj) or die(mysql_error());$row_rs_industry = mysql_fetch_assoc($rs_industry);$totalRows_rs_industry = mysql_num_rows($rs_industry);ElseIf ($_POST["field_name"] == "productcategory")mysql_select_db($database_conn_dj, $conn_dj);$query_rs_productcategory = "SELECT productCat_id, productCat_name, industry_id FROM tbl_productcat WHERE industry_id = '$_GET[industry_id]' ORDER BY productCat_name";$rs_productcategory = mysql_query($query_rs_productcategory, $conn_dj) or die(mysql_error());$row_rs_productcategory = mysql_fetch_assoc($rs_productcategory);$totalRows_rs_productcategory = mysql_num_rows($rs_productcategory);ElseIf ($_POST["field_name"] == "product")mysql_select_db($database_conn_dj, $conn_dj);$query_rs_product = "SELECT products_id, products_name, productCat_id FROM tbl_products WHERE productCat_id = '$_GET[productCat_id]' ORDER BY products_name";$rs_product = mysql_query($query_rs_product, $conn_dj) or die(mysql_error());$row_rs_product = mysql_fetch_assoc($rs_product);$totalRows_rs_product = mysql_num_rows($rs_product);ElseIf ($_POST["field_name"] == "outsidena")mysql_select_db($database_conn_dj, $conn_dj);$query_rs_outsidena = "SELECT * FROM intl_countries ORDER BY intl_countries.name";$rs_outsidena = mysql_query($query_rs_outsidena, $conn_dj) or die(mysql_error());$row_rs_outsidena = mysql_fetch_assoc($rs_outsidena);$totalRows_rs_outsidena = mysql_num_rows($rs_outsidena);Else echo "No valid data submitted"; Just see: http://www.w3schools.com/php/php_if_else.aspRedsun Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now