Jump to content


Photo

Projects Database in PHP Using MYSQL


  • Please log in to reply
3 replies to this topic

#1 ijamal

ijamal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 May 2006 - 09:03 AM

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 May 2006 - 10:21 AM

$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

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 ijamal

ijamal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 May 2006 - 05:47 AM

Hi Orio,

Thanks for your help. I will try this out and see how I progress.

Warm regards,

Irshad

#4 ijamal

ijamal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 May 2006 - 07:15 AM

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



<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=auto:0][quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users