Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Cannot get fields from the MySql table
Old 03-24-2005, 10:57 AM Cannot get fields from the MySql table - Code Update
Experienced Talker

Posts: 36
Trades: 0
Hi:

I'm using the following code to retrieve tables and fields from the database:

PHP Code:
<?php

if ($_POST['submit']) {

//=========================== TABLE NAMES ==============================================
//Connect to the database
$conn mysql_connect("localhost""root") or die(mysql_error());

//choose the database to be used
$db mysql_select_db("brc_dbase"$conn) or die(mysql_error());


//Get all tables that exist in the database
$result=mysql_list_tables("brc_dbase");


//Assign the values

mysql_fetch_array($result);


//Get the tablenames and display them

echo "<select name =\"select_table\">";

for (
$i=0$i mysql_fetch_array($result); $i++) {

    echo 
"<pre>     <option value=".mysql_tablename($result$i).">".mysql_tablename($result$i)."     </pre>";

    }
}

echo 
"    <tr>
            <td><input type=submit name=\"submit\" value=\"   GO     \"><td><strong>    SET     </strong></td>
            </td>
        </tr>"
;

//===================================================   GET FIELDS FOR EACH TABLE  =============================

//Get all fields that exist in the MAINLOGIN table

    
$result=mysql_list_fields("brc_dbase""mainlogin");


//Get all fields that exist in the COMPANY_INFO table

      
$result=mysql_list_fields("brc_dbase""company_info");


//Get all fields that exist in the FINISHING table

    
$result=mysql_list_fields("brc_dbase""finishing");


//Get all fields that exist in the ORDER_DESC table

      
$result=mysql_list_fields("brc_dbase""order_desc");


 
//Get all fields that exist in the ORDER_INFO table

     
$result=mysql_list_fields("brc_dbase""order_info");


 
//Get all fields that exist in the PAPER_NEEDED table

       
$result=mysql_list_fields("brc_dbase""paper_needed");


 
//Get all fields that exist in the PRESSMAN table

     
$result=mysql_list_fields("brc_dbase""pressman");


//===================================================   ASSIGN AND DISPLAY FIELDS  =============================

//Assign the values

    
mysql_fetch_array($result);


//Get the fieldnames and display them

    
echo "<select name =\"select_field\">";


if (
$option_value == $mainlogin) {

for (
$i=0$i mysql_fetch_field($result); $i++) {

    echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

    }

}


else if (
$option_value == $company_info) {

    for (
$i=0$i mysql_fetch_field($result); $i++) {

          echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

          }
  }


else if (
$option_value == $finishing) {

    for (
$i=0$i mysql_fetch_field($result); $i++) {

          echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

          }
  }


  else if (
$option_value == $order_desc) {

      for (
$i=0$i mysql_fetch_field($result); $i++) {

            echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

            }
    }


else if (
$option_value == $order_info) {

     for (
$i=0$i mysql_fetch_field($result); $i++) {

           echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

           }
   }


else if (
$option_value == $paper_needed) {

    for (
$i=0$i mysql_fetch_field($result); $i++) {

          echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

          }
  }


else if (
$option_value == $pressman) {

    for (
$i=0$i mysql_fetch_field($result); $i++) {

          echo 
"<pre><option value=".mysql_field_name($result$i).">".mysql_field_name($result$i)."</pre>";

          }
  }

else {

        echo 
"ERROR!!!!";

        }
It should work as follows: Get all tables from the database, place it in a drop-down menu.
Select a table from the menu, press GO, get corresponding fields.

I get the tables, but no fields. Also, how can I make sure that the fields are retrieved only when I press "GO" and not before? Can someone show me where I'm wrong? Thanks!

Last edited by common_sense; 03-24-2005 at 04:31 PM.. Reason: Code Update
common_sense is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Cannot get fields from the MySql table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.86280 seconds with 12 queries