<html>
<body>
<?
function make_list ($table, $column, $select)
{
echo "<select name='$select'>";
$result=mysql_query("SELECT * FROM $table");
while( $row=mysql_fetch_array($result))
echo "<option>".$row[strtoupper($column)];
echo "</select>";
}
function connect_to_db()
{
if(!mysql_connect("localhost","ise456","153103"))
{
echo "<h2>Cannot connect</h2>";
echo "<h2>Check Login </h2>";
die();
}
mysql_select_db("ISE456");
}
function make_table($result)
{
echo "<table border=4>";
$row=mysql_fetch_array($result);
for($i = 0; $i < mysql_num_fields($result); ++$i)
{
echo "<tr><th>".mysql_field_name($result,$i)."</th>";
echo "<td>".$row[mysql_field_name($result,$i)]."</td></tr>";
}
echo "</table>";
}
connect_to_db();
// If no table set, then set table to pick from
if (is_null($_POST["Table"]))
{
echo "<form action='view_any.php' method='POST'>";
?>
<select name="Table">
<option>s
<option>p
<option>j
</select>
<?
echo "<input type='submit' />";
echo "</form>";
}
elseif (is_null($_POST["Record"]))
{
echo "<form action='view_any.php' method='POST'>";
make_list ($Table, $Table."NUM", "Record");
echo "<input type='hidden' name='Table' value='" .$Table. "'>";
echo "<input type='submit' />";
echo "</form>";
}
else
{
echo "<table border=4>";
for
echo "DISPLAY TABLES”
}
?>
</body>
</html>
Display tables
Page 1 of 15 Replies - 525 Views - Last Post: 09 February 2009 - 02:53 AM
#1
Display tables
Posted 08 February 2009 - 07:44 PM
Hey, I need help with only about two lines more of my code. I need to display my tables from the drop down menu I have already made, but I can't quite get it. I think I need to set NUM and record equal maybe but im not sure. The problem I am having is at the very bottom of my code where I have display tables. Thanks!
Replies To: Display tables
#2
Re: Display tables
Posted 08 February 2009 - 07:48 PM
Wow ok... lets get started. I see like 20 errors just by looking real quick, so this may be a long post.
I'm going to post the first error I see then edit it with each error fix I update...
(So there may be 10-15 edits over the next 10 minutes. Bear with me.)
First error I saw is:
I just don't see where this is logical, at all.
Fixed.
Give me a minute, I'll peek through the rest of the PHP.
Next:
I don't understand why you need a function for this? Wouldn't mysql_connect("localhost","ise456","153103") or die("error"); do the same exact thing? This is just unnecessary.
Next problem coming... (please hold).
Fixed.
Next: (Please hold).
What is this? Were you intending some form of a foreach(){}; statement? Please clarify this.
I'll go further on once you respond to my questions, and also could you please explain exactly what your script ISN'T doing? I understand there is a problem, and I'm trying to locate it... but it'd help immensely if I knew the symptoms of your problem.
That is all for now.
Thanks!
I'm going to post the first error I see then edit it with each error fix I update...
(So there may be 10-15 edits over the next 10 minutes. Bear with me.)
First error I saw is:
<select name="Table">
<option>s
<option>p
<option>j
</select>
I just don't see where this is logical, at all.
<select name="Table">
<option>s</option>
<option>p</option>
<option>j</option>
</select>
Fixed.
Give me a minute, I'll peek through the rest of the PHP.
Next:
function connect_to_db()
{
if(!mysql_connect("localhost","ise456","153103"))
{
echo "<h2>Cannot connect</h2>";
echo "<h2>Check Login </h2>";
die();
}
mysql_select_db("ISE456");
}
I don't understand why you need a function for this? Wouldn't mysql_connect("localhost","ise456","153103") or die("error"); do the same exact thing? This is just unnecessary.
Next problem coming... (please hold).
if (is_null($_POST["Table"])) // changed to... if (!$_POST["Table"])
Fixed.
Next: (Please hold).
for
echo "DISPLAY TABLES”
}
What is this? Were you intending some form of a foreach(){}; statement? Please clarify this.
I'll go further on once you respond to my questions, and also could you please explain exactly what your script ISN'T doing? I understand there is a problem, and I'm trying to locate it... but it'd help immensely if I knew the symptoms of your problem.
That is all for now.
Thanks!
This post has been edited by pr4y: 08 February 2009 - 08:01 PM
#3
Re: Display tables
Posted 08 February 2009 - 07:55 PM
echo "DISPLAY TABLES”
is missing a semicolon.
#4
Re: Display tables
Posted 08 February 2009 - 08:01 PM
#5
Re: Display tables
Posted 08 February 2009 - 08:11 PM
I didn't look that closely. The op stated:
Quote
The problem I am having is at the very bottom of my code where I have display tables.
so that's all I looked at. Sometimes the best way to learn is by finding your own mistakes.
#6
Re: Display tables
Posted 09 February 2009 - 02:53 AM
You realize that with the following loop you are going to miss the first entry?
for($i = 0; $i < mysql_num_fields($result); ++$i)
{
echo "<tr><th>".mysql_field_name($result,$i)."</th>";
echo "<td>".$row[mysql_field_name($result,$i)]."</td></tr>";
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|