ueon Posted May 12, 2008 Share Posted May 12, 2008 Hello when I execute this script, the loop is incorrect. <?php include 'connect.php'; $css_num = mysql_query("SELECT css_file FROM stageone WHERE id = '1'"); $js_num = mysql_query("SELECT js_file FROM stageone WHERE id = '1'"); $div_num = mysql_query("SELECT div FROM stageone WHERE id = '1'"); echo "$css_num/$js_num/$div_num"; $css_int = 0; $js_int = 0; $div_int = 0; $css_id = 0; $js_id = 0; $div_id = 0; echo '<form name="stagetwo1" method="post" action="stagethree.php">'; while ($css_int != $css_num) { echo " <p>\n <input name='css_name$css_id' type='text' id='css_name$css_id' value='CSS file'>\n </p>\n\n "; $css_int++; $css_id++; } while ($js_int != $js_num) { echo (" <p>\n <input name='js_name$js_id' type='text' id='js_name$js_id' value='JS file'>\n </p>\n\n "); $js_int++; $js_id++; } while ($div_int != $div_num) { echo (" <p>\n <input name='div_name$div_id' type='text' id='div_name$div_id' value='DIV Image'>\n </p>\n\n "); $div_int++; $div_id++; } echo (" <p> <input type='submit' name='Submit' value='Submit'>\n </p>\n </form>\n ") ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted May 13, 2008 Share Posted May 13, 2008 That's a PHP issue -- I assume the mysql queries return the desired results. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 13, 2008 Share Posted May 13, 2008 Hello when I execute this script, the loop is incorrect. your query processing is incorrect. replace your 3 queries with <?php $sql = "SELECT css_file, js_file, div FROM stageone WHERE id = '1'"; $result = mysql_query ($sql) or die (mysql_error()); list ($css_num, $js_num, $div_num) = mysql_fetch_row($result); // get the data from the returned results ?> Quote Link to comment Share on other sites More sharing options...
ueon Posted May 14, 2008 Author Share Posted May 14, 2008 Thank you does that set the data into the variables? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 14, 2008 Share Posted May 14, 2008 Yes, that will put whatever was in css_file, js_file, div and put into $css_num, $js_num, $div_num Quote Link to comment Share on other sites More sharing options...
ueon Posted May 17, 2008 Author Share Posted May 17, 2008 I've used the code previously provided, but I'm still having troubles :-\ "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 'div FROM stageone WHERE id = '1'' at line 1" This is the code I'm using <?php include 'connect.php'; // Extracting Data $sql = "SELECT 'css_file', 'js_file', 'div' FROM stageone WHERE id = '1'"; $result = mysql_query ($sql) or die (mysql_error()); list ($css_num, $js_num, $div_num) = mysql_fetch_row($result); //Set initial loop vars $css_int = 0; $js_int = 0; $div_int = 0; $css_id = 0; $js_id = 0; $div_id = 0; //form echo '<form name="stagetwo1" method="post" action="stagethree.php">'; //CSS loop while ($css_int != $css_num) { echo " <p>\n <input name='css_name$css_id' type='text' id='css_name$css_id' value='CSS file'>\n </p>\n\n "; $css_int++; $css_id++; } //JS Loop while ($js_int != $js_num) { echo (" <p>\n <input name='js_name$js_id' type='text' id='js_name$js_id' value='JS file'>\n </p>\n\n "); $js_int++; $js_id++; } //Div Loop while ($div_int != $div_num) { echo (" <p>\n <input name='div_name$div_id' type='text' id='div_name$div_id' value='DIV Image'><BR />\n <input name='div_top$div_id' type='text' id='div_top$div_id' value='Top PX'><BR />\n <input name='div_left$div_id' type='text' id='div_left$div_id' value='Left PX'><BR />\n </p>\n\n "); $div_int++; $div_id++; } echo (" <p> <input type='submit' name='Submit' value='Submit'>\n </p>\n </form>\n ") ?> Quote Link to comment Share on other sites More sharing options...
ueon Posted May 17, 2008 Author Share Posted May 17, 2008 The previous problem has be fixed, but now the original problem is back. the data extracted from the database is incorrect. data in Columns css_file = 1 js_file = 2 div = 3 table = 4 it returns: "css_file js_file div" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Webgen 2.0</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div align="center"> <b>Webgen 2.0</b><br /> [stage 2]<br /> <?php include 'connect.php'; // Extracting Data $sql = "SELECT 'css_file', 'js_file', 'div', 'table' FROM stageone WHERE id = '1'"; $result = mysql_query ($sql) or die (mysql_error()); list ($css_num, $js_num, $div_num, $table_num) = mysql_fetch_row($result); echo $css_num; echo $js_num; echo $div_num; //Set initial loop vars $css_int = 0; $js_int = 0; $div_int = 0; $table_int = 0; $css_id = 0; $js_id = 0; $div_id = 0; $table_id = 0; //form echo '<form name="stagetwo1" method="post" action="stagethree.php">'; //CSS loop while ($css_int != $css_num) { echo " <p>\n <input name='css_name$css_id' type='text' id='css_name$css_id' value='CSS file'>\n </p>\n\n "; $css_int++; $css_id++; } //JS Loop while ($js_int != $js_num) { echo (" <p>\n <input name='js_name$js_id' type='text' id='js_name$js_id' value='JS file'>\n </p>\n\n "); $js_int++; $js_id++; } //Div Loop while ($div_int != $div_num) { echo (" <p>\n <input name='div_name$div_id' type='text' id='div_name$div_id' value='DIV Image'><BR />\n <input name='div_top$div_id' type='text' id='div_top$div_id' value='Top PX'><BR />\n <input name='div_left$div_id' type='text' id='div_left$div_id' value='Left PX'><BR />\n </p>\n\n "); $div_int++; $div_id++; } //Div Loop while ($div_int != $div_num) { echo (" <p>\n <input name='table_name$div_id' type='text' id='table_name$div_id' value='Table'><BR />\n <input name='table_width$div_id' type='text' id='table_width$div_id' value='Width'><BR />\n <input name='table_length$div_id' type='text' id='table_length$div_id' value='Length'><BR />\n <input name='table_top$div_id' type='text' id='table_top$div_id' value='Top PX'><BR />\n <input name='table_left$div_id' type='text' id='table_left$div_id' value='Left PX'><BR />\n </p>\n\n "); $div_int++; $div_id++; } echo (" <p> <input type='submit' name='Submit' value='Submit'>\n </p>\n </form>\n ") ?> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Barand Posted May 17, 2008 Share Posted May 17, 2008 Your query selects literal string values and not column values. Remove the quotes. Quote Link to comment Share on other sites More sharing options...
ueon Posted May 17, 2008 Author Share Posted May 17, 2008 I tried doing that, but it returns his error "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 'div FROM stageone WHERE id = '1'' at line 1" Quote Link to comment Share on other sites More sharing options...
Barand Posted May 17, 2008 Share Posted May 17, 2008 DIV is a MySQL reserved word. Put it in backticks ie `div` or, better, change column name Quote Link to comment Share on other sites More sharing options...
ueon Posted May 18, 2008 Author Share Posted May 18, 2008 thank you, it's working great now Quote Link to comment 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.