5 Replies - 707 Views - Last Post: 09 February 2009 - 02:53 AM Rate Topic: -----

#1 Linz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-November 08

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!


<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> 
 




Is This A Good Question/Topic? 0
  • +

Replies To: Display tables

#2 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

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:

    <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

Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3100
  • View blog
  • Posts: 10,889
  • Joined: 08-August 08

Re: Display tables

Posted 08 February 2009 - 07:55 PM

echo "DISPLAY TABLES” 


is missing a semicolon.
Was This Post Helpful? 0
  • +
  • -

#4 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Display tables

Posted 08 February 2009 - 08:01 PM

View PostCTphpnwb, on 8 Feb, 2009 - 06:55 PM, said:

echo "DISPLAY TABLES” 


is missing a semicolon.



Good call! Did I miss anything else? :P
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3100
  • View blog
  • Posts: 10,889
  • Joined: 08-August 08

Re: Display tables

Posted 08 February 2009 - 08:11 PM

:D
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.
;)
Was This Post Helpful? 0
  • +
  • -

#6 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

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>";
	   } 


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1