i have 3 different table in 1 database.. and i want to let my user see their own profile by using search.. but, my user will divide by those 3 program and their details may be only in one table..

how can i let my user choose their program using menu/list??

mm.. tell me if you guys don't understand my explanation..

this is my own code...

<title>US1M</title>

<form method="post" action="">
  <div align="center">
    <p>&nbsp;</p>
    <table width="523" height="234" border="0">
      <tr>
        <td width="513">&nbsp;</td>
      </tr>
      <tr>
        <td height="126"><div align="center">
          <p>Sila Pilih Jenis Koperasi dan Masukkan No Kad Pengenalan untuk carian</p>
          <p>Contoh : 880101025432</p>
        </div>
          <p align="center">
            <label>
            <select name="koperasi" id="koperasi">
              <option selected>(Jenis Koperasi)</option>
              <option>Koperasi Sutrawati</option>
              <option>Koperasi Iltizam</option>
              <option>Koperasi Makmur</option>
            </select>
            </label>
          </p>
          <p align="center">
            <label>
            <input type="text" name="noIC" id="noIC" />
            </label>
            <input type="submit" name="cari" id="cari" value="Submit" />
          </p></td>
      </tr>
      <tr>
        <td><?php

//connect to database
require("connect.inc");

$SQL_FROM = 'koperasi';


if (isset($_POST['cari'])) 
{ 
 if(isset($_POST['noIC']))
 $data = mysql_query("SELECT * FROM {$_POST['koperasi']} where noic='{$_POST[ 'noIC' ]}'  LIMIT 1") or die(mysql_error()); 
  
 while($info = mysql_fetch_array( $data )) { 

//Outputs the data
echo "<tr><td><center><table border=0 width=70%><tr><td><b>Nama Pemilik</b></td><td>".$info['namaPemilik'] . "</td></tr>"; 

$infodata = mysql_num_rows($data);
}

}
  

if ($no_ic == ''){
		echo "<font color='red'>SILA PASTIKAN ANDA MASUKKAN NOMBOR KAD PENGENALAN YANG SAH!";
		} else
		if ($infodata == 0){
		echo "<font color='red'>MAAF, MAKLUMAT YANG DICARI TIADA DALAM PANGKALAN DATA KAMI!";
		}

?></td>
      </tr>
      </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>
    <label></label>
  </p>
  <p>&nbsp;</p>
  
</form>

thank you...

No, sorry, but I really don't understand you explaination.
What means program in your post?
And What do you want to accomplish?

Nothing, just answered to bad question.

Member Avatar for diafol

You need to explain further.
As I understand you, an user has their profile in a table, but that profile may be in one of 3 different tables. Is that right?

If this is the case, you need to change your DB structure to have just one table for profiles.

i have 3 table for 3 program.. one for each... the user can register their account in which program they want to...

now, i want to make sure the user can search their profile back.. but their profile are in 3 different table.. how can i let user to pick one of the 3 program using menu/list??

Hmm, I don't really understand it however I will have a stab in the dark:

Ok in your search form just create a list to choose from for this example I will call the three programs your on about ( thinking they are like teaching programs) like so :

<select name="programs">
<option value="program1">course 1</option>
<option value="program2">course 2</option>
<option value="program3">course 3</option>
</select>

When this form is posted, to look for their profile or something like that do the following, which is a very simple example, as I do not know your database structure, and I am assuming that your program tables are numbed as the following ('program1','program2','program3') :

$tableName = mysql_real_escape_string ( $_POST['programs'] ) ;

$query = sprintf ( "SELECT * FROM %s WHERE something = 'something' " , $tableName ) ;

The above creates a query that will search a table that was defined by the user. That is all I can help you with considering the amount of information provided. Well I hope it helps :)

thanks.. actually you understand what i want.. can you please explain to me what this code mean??

$tableName = mysql_real_escape_string ( $_POST['programs'] ) ;

i don't understand that code....
anyway, thanks...

thanks.. actually you understand what i want.. can you please explain to me what this code mean??

Ok you have a form, that the user fills in, but if you have not been told or found out the hard way, it is that you can never trust a user :).

When you submit a form it is Posted to you script that handles the data and does what you want with it. So this is the reason for the $_POST[] with the name of the drop down we make in the form between the brakets, this means that we want this section of the posted data.

Now we know what data we want and where to get it, like I said before we can't trust users, so we want to clean the data up before we place it into the database, this is incase the data has been tampered with. So we use the mysql_real_escape_string () passing it the data from $_POST[] , this will then produce clean data. Then the end result is passed into the variable on the left, remember normally with programming things happen from right to left.

However if this is purely for profiles I would suggest that you follow the guidence of with the following :

If this is the case, you need to change your DB structure to have just one table for profiles.

As the method that your using can cause data redundancy problems later on.

Do you understand that would you like an other example? If not I hope that helps :)

i think it may be easier if i just have one table than 3 table?? than, i don't need to use menu/list.. is that so??

Member Avatar for diafol

It depends on whether user can have more than 1 program. It's unclear whether this is the case.

mikulucky's dropdown may work if you're a member of one only, otherwise you could make the the dropdown a multiselect, in which case more than one could be selected.

The user profile fields would sit better as part of the users table IMO.

actually, the user can only choose 1 from 3 program.. that's why i make 3 different table.. when, they want to search their profile back, i need them to pick which program they have choose earlier.

but, i don't know how to use menu/list to do this...

Member Avatar for diafol

Read up on 'forms and php' and 'select fields'. Explaining how to use a select field with php can be found on loads of tutorial pages.

actually, the user can only choose 1 from 3 program.. that's why i make 3 different table.. when, they want to search their profile back, i need them to pick which program they have choose earlier.

but, i don't know how to use menu/list to do this...

Member Avatar for diafol

See my previous post. If you have no or little idea of php, you need to learn it. Buy a book or read some online tutorials. Giving you a demo script won't help you as it won't meet your needs and you won't be clued-up enough to customize it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.