Jump to content

Projects Database in PHP Using MYSQL


ijamal

Recommended Posts

Dear forum,

I am trying to create a GUI using PHP4 that contains the following dropdown multiselect comboboxes,

Project Sector (1-Education, 2-Health etc.), Sub Sector(1-Drinking Water, Irrigation Water etc.), Donor(ECHO,USAID,SIDA etc.), Province(1-DRD, 2-Sughd, 3-Khatlon), District( Dist1, Dist2, etc.), Jamoat(Jam1, Jam2 etc.)

A user can choose to search the MYSQL database by selecting one or more items in each dropdown list. Once the selection is made. The user can choose what fields are to be viewed, I will create checkboxes with the names of fields that will be visible when the request is submitted.

I have already designed and populated the database, including assignment of primary and secondary keys.

I just need some pointers about where to start. I have also learnt how to connect to an MYSQL database from PHP and am able to view tables in HTML format.

Any help on how to proceed with this project will be most appreciated.

Thanks in advance.

Irshad
Link to comment
Share on other sites

[code]$one=$_POST['field1'];
$two=$_POST['field2'];
$three=$_POST['field3'];
//etc'

$select="";
if(isset($_POST['checkbox1']){$select.="col1";};
if(isset($_POST['checkbox2']){$select.=",col2";};
if(isset($_POST['checkbox3']){$select.=",col3";};
//etc'

if(empty($select)){die("Error: Select something!");}

$sql="SELECT $select FROM `tablename` WHERE col1='$one' AND col2='$two' AND col3='$three' ....";
$result=mysql_query($sql);

//Display data[/code]

Orio.
Link to comment
Share on other sites

Dear Orio,

I tried to implement the code you kindly gave me however I am not sure how to get it to execute. I am just starting to learn on my own and so please pardon my ignorance. I assume I need to have a checkbox.html doc that contains the checkboxes (Checkbox1, Checkbox2, Checkbox3).

I created Checkbox.html with the following code, I am not sure what to assign the value of Checkbox1.

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=POST ACTION=Checkbox.php">
<INPUT NAME="Checkbox1" TYPE="Checkbox" VALUE=??


In the code you posted previously, I am not sure what these lines mean. Would sincerely appreciate your help.

***********************************
$one=$_POST['Project.Project_ID'];
$two=$_POST['Project.Project_Sector_ID'];
$three=$_POST['Project.Sub_Sector_ID'];

$select="";
if(isset($_POST['checkbox1']){$select.="col1";};
if(isset($_POST['checkbox2']){$select.=",col2";};
if(isset($_POST['checkbox3']){$select.=",col3";};
****************************************

This is the code you have given me which I have incorporated into my code...

Many thanks for taking your time to help me.

Irshad


[code]

<body bgcolor=#E4E4E4>
<FONT COLOR= "blue" face="Verdana"</FONT>
<center><h1> CP PROJECTS 1996-2006</h1></center>
<?php
$db = mysql_connect("localhost","root");
mysql_select_db("CP_PROJECT",$db);

$one=$_POST['Project.Project_ID'];
$two=$_POST['Project.Project_Sector_ID'];
$three=$_POST['Project.Sub_Sector_ID'];

$select="";
if(isset($_POST['checkbox1']){$select.="col1";};
if(isset($_POST['checkbox2']){$select.=",col2";};
if(isset($_POST['checkbox3']){$select.=",col3";};

if(empty($select)){die("Error: Select something!");}

$sql="SELECT $select FROM Project";
$result=mysql_query($sql);

print "<table border=2 cellspacing=6 cellpadding=6 bordercolor=red>\n";

//get field names
print "<tr BGCOLOR = #FCB103>\n";
while ($field = mysql_fetch_field($result)){
  print " <th>$field->name</th>\n";
} // end while
print "</tr>\n\n";

//get row data as an associative array
while ($row = mysql_fetch_assoc($result)){
  print "<tr>\n";
  //look at each field
  foreach ($row as $col=>$val){
    print " <td BGCOLOR= #B8F475 ALIGN = middle VALIGN = Middle>$val</td> \n";
  } // end foreach
  print "</tr>\n\n";
}// end while

print "</table>\n";
?>
</body>
</html>
[/code][code][quote]
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.