Jump to content

horaliar

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

About horaliar

  • Birthday 06/24/1970

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling

horaliar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm not sure if I already asked this question before in this forum, here goes: I have an Access background, that's why I'm asking for subforms. I have a project involving the following database: mysql> describe press_schedule; +--------------+----------------------+------+-----+---------+----------------+ | Field        | Type                | Null | Key | Default | Extra          | +--------------+----------------------+------+-----+---------+----------------+ | press_sch_id | smallint(5) unsigned | NO  | PRI | NULL    | auto_increment | | press_date  | date                | YES  |    | NULL    |                | | rgj_lst_pte  | datetime            | YES  |    | NULL    |                | | rgj_prs_str  | datetime            | YES  |    | NULL    |                | | rgj_prs_stp  | datetime            | YES  |    | NULL    |                | | maint_str    | time                | YES  |    | NULL    |                | | maint_stp    | time                | YES  |    | NULL    |                | +--------------+----------------------+------+-----+---------+----------------+ 7 rows in set (0.00 sec) mysql> describe press_schedule_sections; +--------------+----------------------+------+-----+---------+-------+ | Field        | Type                | Null | Key | Default | Extra | +--------------+----------------------+------+-----+---------+-------+ | press_sch_id | smallint(5) unsigned | NO  | PRI | NULL    |      | | section_id  | smallint(5) unsigned | NO  | PRI | NULL    |      | | lst_pte      | time                | YES  |    | NULL    |      | | prs_str      | time                | YES  |    | NULL    |      | | prs_stp      | time                | YES  |    | NULL    |      | | prd_dte      | date                | YES  |    | NULL    |      | +--------------+----------------------+------+-----+---------+-------+ 6 rows in set (0.00 sec) mysql> describe sections; +--------------+----------------------+------+-----+---------+----------------+ | Field        | Type                | Null | Key | Default | Extra          | +--------------+----------------------+------+-----+---------+----------------+ | section_id  | smallint(5) unsigned | NO  | PRI | NULL    | auto_increment | | section_name | varchar(100)        | NO  |    | NULL    |                | +--------------+----------------------+------+-----+---------+----------------+ 2 rows in set (0.01 sec) As you can see from the db structure, one record in press_schedule can have many records in press_schedule_sections associated with it. The same for sections. I'm fairly new to this area, so I'm completely at a lost as to how to even start creating a form that could accomplish this. I have done some other database driven applications, but none that involved the use of something like this. Can anyone give me some pointers? I'm very desperate for help, I'm the only one in my department that codes, and I really don't want to create this in Access. Thanks!
  2. Can subforms be created in PHP? I have a form that is filled in by user's on a daily basis. There is a section where they place errors in case any happened and the time they occurred. Some times there might be 5 errors, some nights only one, etc. What I want to avoid is needing to place a big amount of input fields that won't be needed. I did something similar to this in MS Access, but have no idea how to implement this is PHP. In another forum I was told to use frames, but I didn't get a very big explanation. Any ideas will be welcome. Thanks!
  3. Thank you sanfly. Actually, I posted all of the code in my next posting. It's called compact code. I appreciate any help you can give me, I've been going nuts trying to get this going on. It's actually named compact script.
  4. This is my first script that I wrote for my department. It runs queries against a mysql database depending on parameters that the user has entered. I'm running into trouble because I wrote everything in one file, except some javascript functions, and now I'm having problems adding to it. I would like to have some ideas on how to divide the code in different files and make it more manageble. Any ideas will be welcomed. Thanks! <html> <head> <link rel="stylesheet" href="myStyle.css" type="text/css"> <script LANGUAGE="javascript" TYPE="text/javascript" SRC="tools.js"></SCRIPT> <script LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT> <script LANGUAGE="JavaScript"> var cal = new CalendarPopup(); </SCRIPT> </head> <body> <?php //Connect to the server. $link = mysql_connect("", "", ""); //Connect to the db. mysql_select_db("dbads", $link); ?> <form method="POST" name="data" action="adserv.php"> <input type="hidden" name="command"> <input type="hidden" name="periodname"> <input type="hidden" name="pstartdate"> <input type="hidden" name="penddate"> <!-- Table Title--> <table class="title" height="20" cellSpacing="0" cellPadding="0" width="750" border="0"> <tr> <th class="title" valign="bottom" class="title"> New and Late Ad Report </th> </tr> </table> <br> <!-- Table Data to Enter --> <table height="20" cellSpacing="0" cellPadding="0" width="750" border="0"> <!-- Row Headings --> <tr> <th class="heading" width="150" align="left">Select a date:</th> <th class="heading" width="300" align="left">Select a start/end date:</th> <th class="heading" width="150" align="left">Select a period:</th> <th class="heading" width="150" align="left">Select a user:</th> </tr> <!-- Row containing items to enter data --> <tr> <!-- ENTER A DATE --> <td class="item" width="150"> <input class="textbox" type="text" name="selDate" value="" size="10"> <input type="image" align="middle" value="cal1" src="pdate.gif" name="cal1" onclick="cal.select(document.forms['data'].selDate,'cal1','MM/dd/yyyy'); return false;"> </td> <!-- ENTER START AND END DATE --> <td class="item" width="300"> <input class="textbox" type="text" name="startDate" value="" size="10"> <input type="image" align="middle" value="cal2" src="pdate.gif" name="cal2" onclick="cal.select(document.forms['data'].startDate,'cal2','MM/dd/yyyy');return false;"> <input class="textbox" type="text" name="endDate" value="" size="10"> <input type="image" align="middle" value="cal3" src="pdate.gif" name="cal3" onclick="cal.select(document.forms['data'].endDate,'cal3','MM/dd/yyyy');return false;"> </td> <!-- SELECT A PERIOD --> <td class="item" width="150"> <select size="1" class="textbox" id="periodname" name="periodname" onChange="getPeriodDates(this)"> <option value="">-</option> <?php //Creates query to retrieve the data to be used in the drop down box. $query="SELECT PeriodName, StartDate, EndDate FROM tblPeriod"; if ($hResult=mysql_query($query)) { while ($hFetch=mysql_fetch_array($hResult)) { $periodname=$hFetch["PeriodName"]; $pstartdate=$hFetch["StartDate"]; $penddate=$hFetch["EndDate"]; echo "<option value='$periodname||$pstartdate||$penddate'\">".$periodname."</option>"; } } ?> </select> </td> <!-- SELECT A USER --> <td class="item" width="150"> <select size="1" class="textbox" id="username" name="username"> <option value="">-</option> /* <?php //Creates query to retrieve the data to be used in the drop down box. $query="SELECT PeriodName, StartDate, EndDate FROM tblPeriod"; if ($hResult=mysql_query($query)) { while ($hFetch=mysql_fetch_array($hResult)) { $periodname=$hFetch["PeriodName"]; $startdate=$hFetch["StartDate"]; $enddate=$hFetch["EndDate"]; echo "<option value='$periodname||$startdate||$enddate'\">".$periodname."</option>"; } } ?> */ </select> </td> </tr> </table> <input class="add" type="button" value="Submit" onclick="doSave(this, 'Save')"></td> <?php //COMMAND if (isset($_POST["command"])) $command = $_POST["command"]; //SELECTED DATE if (isset($_POST["selDate"])) $postselDate = $_POST["selDate"]; //START DATE if (isset($_POST["startDate"])) $poststartdate = $_POST["startDate"]; //END DATE if (isset($_POST["endDate"])) $postenddate = $_POST["endDate"]; //PERIOD NAME if (isset($_POST["periodname"])) $postperiodname = $_POST["periodname"]; //PERIOD START DATE if (isset($_POST["pstartdate"])) $postpstartdate = $_POST["pstartdate"]; //PERIOD END DATE if (isset($_POST["penddate"])) $postpenddate = $_POST["penddate"]; //COMPARE COMMAND, IF IT IS SAVE, CHECK INFO AND RUN APPROPRIATE QUERIES. DISPLAY INFO. if (strcmp("Save", $command) == 0) { //CHECK FOR MISSING PARAMETERS //Check that a date has been entered. if ($postselDate == null AND $poststartdate == null AND $postenddate == null AND $postperiodname == null) die("Enter a date"); //Check that only a date or period has been entered. if ($postselDate != null AND $postperiodname != null) die("Either enter a date or select a period"); //Check that only a date or a date range has been selected. if ($postselDate != null AND ($poststartdate != null OR $postenddate != null)) die("Either enter a single date or a date range"); //Check that only a period or a date range has been selected. if ($postperiodname != null AND ($poststartdate != null OR $postenddate != null)) die("Either enter a date range or select a period"); //Check that if a start date has been entered, an end date has also been entered. if ($poststartdate == null AND $postenddate != null) die("Enter a start date"); if ($poststartdate != null AND $postenddate == null) die("Enter an end date"); //Check that end date is higher than start date. if ($poststartdate > $postenddate) die("End date must be later than start date."); //Assign a variable to be used in case statement. if ($postselDate != null AND $poststartdate == null AND $postenddate == null AND $postperiodname == null) { $parameterType = "sglDate"; } elseif ($poststartdate != null AND postenddate != null AND $postselDate == null AND $postperiodname == null) { $parameterType = "dteRange"; } elseif (postperiodname != null AND $postselDate == null AND $poststartdate == null AND $postenddate == null) { $parameterType = "dtePeriod"; } else { die("Error"); } //Create queries depending on what parameter has been entered. switch ($parameterType) { case "sglDate": $queryNew = "SELECT COUNT(job_id) from tblads WHERE DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');"; $queryLate = "SELECT COUNT(if(TIMEDIFF(deadline, adintime)<0,'late','')) FROM tblads WHERE ((if(TIMEDIFF(deadline, adintime)<0,'late','')='late')) AND DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');"; $queryResults = "SELECT * from tblads WHERE DATE(action_time)=STR_TO_DATE('$postselDate','%m/%d/%Y');"; break; case "dteRange": $queryNew = "SELECT COUNT(job_id) from tblads WHERE DATE(action_time)>=STR_TO_DATE('$poststartdate','%m/%d/%Y') AND DATE(action_time)<=STR_TO_DATE('$postenddate','%m/%d/%Y');"; $queryLate = "SELECT COUNT(if(timediff(deadline,adintime)<0,'late','')) FROM tblads WHERE ((if(timediff(deadline,adintime)<0,'late','')='late')) AND DATE(action_time)>=str_to_date('$poststartdate','%m/%d/%Y') AND DATE(action_time)<=str_to_date('$postenddate','%m/%d/%Y');"; break; case "dtePeriod": $queryNew = "SELECT COUNT(job_id) FROM tblads WHERE DATE(action_time)>='$postpstartdate' AND DATE(action_time)<='$postpenddate';"; $queryLate = "SELECT COUNT(if(timediff(deadline,adintime)<0,'late','')) FROM tblads WHERE ((if(timediff(deadline,adintime)<0,'late','')='late')) AND DATE(action_time)>='$postpstartdate' AND DATE(action_time)<='$postpenddate';"; } //Closes switch //Runs both queries $resultNew = mysql_query($queryNew, $link); if(!$resultNew) die("Invalid query: ".mysql_error()."<br>".$queryNew); $resultLate = mysql_query($queryLate, $link); if(!$resultLate) die("Invalid query: ".mysql_error()."<br>".$queryLate); //Fetches the query's result while($row = mysql_fetch_array($resultNew)) { $NewAds = $row[0]; } while($row = mysql_fetch_array($resultLate)) { $LateAds = $row[0]; } if ($NewAds == 0) { echo "There are no ads for this date."; } else { //Create table to hold queries results. ?> <table class="title" height="20" cellSpacing="0" cellPadding="0" width="300" border="0"> <tr> <th class="heading" width="100" align="center">Total New Ads</th> <th class="heading" width="100" align="center">Total Late Ads</th> <th class="heading" width="100" align="center">Percentage</th> </tr> <tr> <td class="item" width="100" align="center"><?php echo $NewAds ?></td> <td class="item" width="100" align="center"><?php echo $LateAds ?></td> <td class="item" width="100" align="center"><?php echo number_format($LateAds/$NewAds*100,2,'.','').'%' ?></td> </tr> </table> <?php echo '<input type="button" value="Go To" onClick="location.href=\'view_results.php\'">'; } } ?> </table> </form> </body> </html>
  5. I'm trying to display the table results in a new page and haven't been able to do so. Basically, what my script does, is run two count queries against a mysql table and display the results. If there are results, an additional button is displayed and from here the user would click the button in case the query details are needed. This is where I'm stuck.... I can redirect the page to another one, but the variables are not passed to the new page so I can run my query. I can't even find out a way to display the results in the same page! Please help! Any ideas will be appreciated, I haven't found any help anywhere else.
  6. I did some reading and found out that I can't do it this way, that I have to reload the form and run the code from JavaScript?
  7. Thanks! What I am really looking for is that the textboxes be updated every time a selection is made. I enclosed your code in a function: <?php function mine() { $query = "SELECT custname, datprd FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcustomers.mcustnbr AND tblappearance.appnbr=$APPNBR1"; $result = mysql_query ( $query ); $data = mysql_fetch_array($result); // no need to loop since we are only concerned with row 1.. } ?> And I tried calling it using the onchange event, but I don't think I'm using the right syntax: <select name="APPNBR" onchange="<?php "mine" ?>">" Any ideas? Thanks!
  8. I have the following code which populates a drop down list from a MySQL database: <html> <head> <title>Imaging Scanning Log</title> </head> <?php //Connect to the db. require_once('mysql_connect.php'); ?> Select Insertion Order Number: <select name="APPNBR"> <?php //Build query to retrieve data to populate drop-down list $query = "SELECT APPNBR FROM tblAppearance"; //Execute query $result = @mysql_query($query); //Loop through the results while($row = mysql_fetch_array($result)) { //Assign returned values to the variables $APPNBR1 = $row['APPNBR'];?> <option value="<?php echo $APPNBR1;?>"><?php echo $APPNBR1;?></option> <?php } ?> </select> <p></p> Customer Name: <input type="text" name="custname"> <p></p> Date Published: <input type="text" name="pubdate"> </html> I would like to run the following query to insert the results into "custname" and "pubdate". "SELECT custname, datprd FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcustomers.mcustnbr AND tblappearance.appnbr=$APPNBR1" How can I do this? The only programming experience I have is with Access, and this task is accomplished so easily using this database, that I'm getting a little overwhelmed. Thanks!
  9. [!--quoteo(post=344207:date=Feb 9 2006, 12:40 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Feb 9 2006, 12:40 PM) [snapback]344207[/snapback][/div][div class=\'quotemain\'][!--quotec--] If its only asking you for a password, you have not set up any additional accounts, and as such it is auto logging you into root - I guess. You can open a persistant connection with mysql_pconnect() - Check the PHP manual for more info. [/quote] Sorry for not answering, I thought I would receive an e-mail notification once a post was made to the question. My problem was solved and you are completely right, I haven't set up any accounts so that's why it automatically logs me in as root only. Thanks!
  10. I'm totally new to the php and mysql world. I just downloaded the required software to start learning and I have a bit of a problem. I don't have a server and I installed MySQL on my machine and I've found on several tutorials that a persistent database conection is required in order to complete such tutorial. How can I create this type of conection? Another thing, I'm not so sure if I installed MySQL correctly, when I log in, I'm not asked for a username, only for a password. Help! Thanks!
×
×
  • 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.