Jump to content

[SOLVED] Extracting Database arrays


ueon

Recommended Posts

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
")
?>

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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
")
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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"

Link to comment
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.