Jump to content

j3rmain3

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

j3rmain3's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks Very Much Mjdamato. Its Working Perfectly. Your help was much appreciated. J£rmain£  :) :D ;D 8)
  2. Im having trouble implementing this into my coding: This is how i am using it (its coming out with the wrong outcome so its wrong) [code] <?php $query = "SELECT * FROM doc_data, fin_rate,tech_rate,doc_rate WHERE doc_data.doc_id = fin_rate.doc_id AND doc_data.doc_id = tech_rate.doc_id AND doc_data.doc_id = doc_rate.doc_id ORDER BY doc_data.session,doc_data.idea,doc_data.doc_id "; $average = "SELECT *,((tech_rate.tech_rating + fin_rate.fin_rating + doc_rate.doc_rating)/3) as average FROM doc_data, doc_rate, fin_rate, tech_rate WHERE doc_data.doc_id=fin_rate.doc_id AND doc_data.doc_id=tech_rate.doc_id AND doc_data.doc_id=doc_rate.doc_id"; $r_average = mysql_query($average) or die ("ERROR:Unable to run $average".mysql_error()); $result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error()); while ($row=mysql_fetch_assoc($result)){ //this is the calculation which is used to work out the average off all the ratings #$average = ($row['fin_rating'] + $row['tech_rating'] + $row['doc_rating']) / 3  ; //This is the section of the table which displays the results from the dB. echo "<tr>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>"; echo "<td><font face=Verdana size=-1><a href=http://pws.stonehouse.oilfield.slb.com/SHTC/SER/IP-1/August_2006_Brainstorm/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['inventor_name']."</p></td>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['tech_rating']."</p></td>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['fin_rating']."</p></td>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['doc_rating']."</p></td>"; echo "<td><p align=center><font face=Verdana size=-1>".sprintf('%01.2f',$r_average)."</p></td>"; #echo "<td><font face=Verdana size=-1>$average</td>"; echo "</tr>"; ?>[/code] The number which appears in the table is not the average. I tested this out by changing the number which the total is being divided by to see if the results changed. But the number did not change. Here are the ratings which i was testing the script on: tech_rating = 5; fin_rating = 4; doc_rating = 3; The answer is 4 but i keep on getting 3. Whats going wrong? I am making a big fuss about this because i was also hoping to use a sort function on the average field so the client can see the best document. Sorry about bothering you about this alot, im just having trouble getting this done. Thanks for your advice though. Much appreciated
  3. I dont think i understand what you mean. Please excuse me if i say explain this wrong. The average has not been stored in the DB yet. When the ratings are being submitted i want the average to change. For example if the tech_rating = 3 then the average which should be 1 because (3 + 0 + 0) / 3 = 1. When fin_rating was submitted as 2 then (3 + 2 + 0) / 3 = 1.67. and so on. Its more of an update query so the number in the average keeps on changing.
  4. Just a quick question. I have a rating system, which is working fine. Before i decided to store the average system into i used this: [code]<?php $average = ($row['fin_rating'] + $row['tech_rating'] + $row['doc_rating']) / 3  ; ?>[/code] This just stored the average in a variable and i simply showed it on the screen as [code]<td>$average</td>[/code] But now i want to store that average in the database. The $average is not being POSTed from anywhere so i cannot use the foreach function or $_POST['average']. The average is created on the fly. Is there a way i can still use [code]<?php $average = ($row['fin_rating'] + $row['tech_rating'] + $row['doc_rating']) / 3  ; ?>[/code] and get the results stored in the database? Do i use while --> [code] <?php $query = "select * from doc,fin,tech WHERE doc.id=fin.id AND doc.id=fin.id AND doc.id=tech.id"; $result = mysql_query($query) or die ("ERROR"); while ($row=mysql_fetch_assoc($query){ $average = ($row['fin_rating'] + $row['tech_rating'] + $row['doc_rating']) / 3  ; //And then somehow turn $average into a form method foreach ($_POST as $average){ $update_average = "UPDATE doc_data SET average = $average WHERE doc.id = $id"; $result_average = mysql_query($update_average) or die ("ERROR"); } ?> [/code] I am also confused on which page im supposed to put this on. On the rating form i am using isset so should i place the script beyond the } else { section or place the script in the file where the overall table is shown. If you need any coding just say! Thanks
  5. Im going to bare all bcz i have been working on this problem for too long. I have created a DB in mySQL which stores records of drinks. I have created a form which allows me to enter records. This works fine. To rate the drinks i have displayed the DB in PHP with dropdown menus to the right so the user can rate the drink. This is my MySQL table >>> id int unsigned NOT NULL auto_increment doc varchar(255) rating int(11) >>> In the rating column are dropdown menus which has these options 1 - Poor; 2 - Average; 3 - Excellent Here is the coding >>> [CODE] <?php $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error()); mysql_select_db($db) or die ("ERROR: Unable to connect to DB".mysql_error()); $query = "SELECT * FROM menu"; $result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error()); $count = "SELECT COUNT(*) FROM menu"; $count_result = mysql_query($count) or die ("ERROR: Unable to $count".mysql_error()); #for ($i=1;$i<$count_result;$i++){ #} #if (mysql_fetch_row($result) > 0 ){ echo "<form action=formprocess4.php method=POST name=rating>"; echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>ID</td>"; echo "<td><font face=Verdana size=-1><b>Document Title</td>"; echo "<td><font face=Verdana size=-1><b>Rating</b></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><font face=Verna size=-1>".$row['doc_id']."</td>"; echo "<td><font face=Verdana size=-1>".$row['doc']."</td>"; /* $rating1= ' '; $rating2= ' '; $rating3= ' '; switch($row['rating']) { case 1: $rating1=' 1'; break; case 2: $rating2=' 2'; break; case 3: $rating3=' 3'; break; } */ echo "<td><select name=rates><option value= ' '></option><option value=1 name=' $row[doc]'rw>1 - Poor</option><option value=2 name=' $row[doc]'rw>2 - Average<option value=3 name=' $row[doc]'rw>3 - Excellent</option></select>"; echo "</td>"; echo "</tr>"; #echo "<br>"; } echo "</table>"; echo "<br>"; echo "<input type=submit name=submit value=submit>"; echo "</form>"; #} echo "<a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a>"; ?> </body> </html>[/CODE] I think i have done this wrong bcz there is not way to identify were the dropdown menu is postioned on the table. I have currently named the dropdown menus $row['doc']rw. --- I do not know what to name the dropdown menus so that they can be linked to the id or doc name of the document being updated. And also my update query is not working >> this is shown in the code below. This is the coding i have placed in the table which is supposed to display the ratings. [CODE] <?php $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error()); mysql_select_db($db) or die ("ERROR:Unable to connect to DB".mysql_error()); $query = "SELECT * FROM menu"; $result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error()); $row1 = mysql_fetch_assoc($result); $doc1 = "$row1[doc]; $update_table = "UPDATE menu SET rating = '$_POST[$doc]' WHERE doc = '$row1[doc]'"; $update_result = mysql_query($update_table) or die ("ERROR: $update_table".mysql_error()); $count = "SELECT COUNT(*) FROM menu"; $count_result = mysql_query($count) or die ("ERROR: Unable to $count".mysql_error()); echo "<h3><font face=Verdana>Table</h3>"; #if (mysql_fetch_row($result) > 0 ){ echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1>ID</td></font>"; echo "<td><font face=Verdana size=-1>Document Title</td></font>"; echo "<td><font face=Verdana size=-1>Rating</td></font>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><font face=Verdana size=-1>".$row['doc_id']."</td>"; echo "<td><font face=Verdana size=-1>".$row['doc']."</td>"; echo "<td><font face=Verdana size=-1>".$row['rating']."</td>"; echo"</tr>"; } echo "</table>"; #} echo "<br><a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a><br></font>"; ?>[/CODE] What i think i need to do is name the dropdown with a number so i could use that as the position in the table. But i am not sure how to get the database to register the number from the dropdown menu. Can someone help me please. Thanks j3rmain3
  6. Anyone know how i can do the above??  ???
  7. I have built a form to populate the DB. The DB has data in it but form also has dropdown menus on each row so the user can add a rating to whether the document is good or not. i am confused on how to link the position of the rating to the position in the table. I was thinkin of doing a rate_id and link it to the dropdown menu which is being altered and the match it with the document id, but i do not know how to place a id to a dropdown menu bcz i do not know how a dropdown can be placed in the DB. Can anyone help? Here is the coding for the form and table. form [code]<html> <head> <title>Dropdown Menu</title> <head> <body> <?php $host = "localhost"; $user = "root"; $pass = "mysql"; $db = "test"; $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error()); mysql_select_db($db) or die ("ERROR: Unable to connect to DB".mysql_error()); $query = "SELECT * FROM menu"; $result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error()); if (mysql_fetch_row($result) > 0){ echo "<form action=formprocess4.php method=POST name=rating>"; echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>ID</td>"; echo "<td><font face=Verdana size=-1><b>Document Title</td>"; echo "<td><font face=Verdana size=-1><b>Rating</b></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><font face=Verdana size=-1>".$row['id']."</td>"; echo "<td><font face=Verdana size=-1>".$row['doc']."</td>"; echo "<td><select name=rates><option value= SELECTED><option value=1 name=$row[doc]rw>1 - Poor<option value=2 name=$row[doc]rw>2 - Average<option value=3 name=$row[doc]rw>3 - Excellent</select>"; echo "</td>"; echo "</tr>"; } echo "</table>"; echo "<br>"; echo "<input type=submit name=submit value=submit>"; echo "</form>"; } echo "<a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a>"; ?> </body> </html>[/code] table [code]<html> <head> <title>Dropdown Menu</title> <head> <body> <?php $host = "localhost"; $user = "root"; $pass = "mysql"; $db = "test"; $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error()); mysql_select_db($db) or die ("ERROR:Unable to connect to DB".mysql_error()); $query = "SELECT * FROM menu"; $result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error()); $update_table = "UPDATE menu SET rating=$_POST['rating'] WHERE /* while ($row=mysql_fetch_assoc($result)){ $ */ echo "<h3><font face=Verdana>Table</h3>"; if (mysql_fetch_row($result) > 0 ){ echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1>Document Title</td></font>"; echo "<td><font face=Verdana size=-1>Rating</td></font>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><font face=Verdana size=-1>".$row['doc']."</td>"; echo "<td><font face=Verdana size=-1>".$row['rating']."</td>"; echo"</tr>"; } echo "</table>"; } echo "<br><a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a><br></font>"; ?> </body> </html>[/code] thanks J3rmain3
  8. i have to use a Color class to change the properties of a graph but i dont really understands graphs very well. I have read the Intro to Classes on the phpfreaks site but applying it to the class i have to use is what im ahving problems with. Here is the class: [code] function Color($red, $green, $blue, $alpha = 0) { $this->red = (int)$red; $this->green = (int)$green; $this->blue = (int)$blue; $this->alpha = (int)round($alpha * 127.0 / 255); $this->gdColor = null; } /** * Get GD color * * @access public * @param $img GD image resource */ function getColor($img) { // Checks if color has already been allocated if(!$this->gdColor) { if($this->alpha == 0 || !function_exists('imagecolorallocatealpha')) $this->gdColor = imagecolorallocate($img, $this->red, $this->green, $this->blue); else $this->gdColor = imagecolorallocatealpha($img, $this->red, $this->green, $this->blue, $this->alpha); } // Returns GD color return $this->gdColor; } } [/code] With the function underneath do i use as: [b]$colour = new Color $colour -> Color("255","0","0",$alpha);[/b] [code] function Color($red, $green, $blue, $alpha = 0) { $this->red = (int)$red; $this->green = (int)$green; $this->blue = (int)$blue; $this->alpha = (int)round($alpha * 127.0 / 255); $this->gdColor = null; } [/code] Thanks J3rmain£
  9. I have created a form which should allow me to add values into a database. I am using dropdown menus to input the values. I am having trouble moving the values into the database. This is supposed to be a rating system. Here is the coding for the form [code]<html> <head> <title>Brainstorm Table</title> </head> <body> <?php if (!isset($_POST['submit'])){ ?> <?php $host = "myserver"; $user = "myself"; $pass = "password"; $db = "help"; $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable To Connect".mysql_error()); mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error()); $query = "SELECT * FROM doc_data ORDER BY session "; $result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error()); echo "<h3><font face=Verdana>Department: Technical</h3>"; if (mysql_num_rows($result) > 0) { echo "<form name=ratings method=POST action=btable.php>"; echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>Session</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Rating</b></font></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>"; echo "<td><font face=Verdana size=-1><a href=http://www.mysite.com/$row[url]><font face=Verdana size=-1>".$row['idea']. "</td>"; echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>"; echo "<td><select name=rates> <option value=  selected> <option value=1 name=$row[idea]tech>1 - Poor <option value=2 name=$row[idea]tech>2 - Fair <option value=3 name=$row[filename]tech>3 - Average <option value=4 name=$row[filename]tech>4 - Good <option value=5 name=$row[filename]tech>5 - Excellent</select></td>"; echo "</tr>"; } echo "</table>"; } else { echo "No Rows Found"; } echo "<br>"; echo "<input type=submit name=submit value=Submit><br><br>"; echo "<b><font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>"; ?> <?php } else { $host = "myserver"; $user = "myself"; $pass = "password"; $db = "help"; $conn = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to Connect".mysql_error()); mysql_select_db($db) or die ("ERROR:Unable to Connect to DB"); $query = "SELECT * FROM doc_data ORDER BY session"; $result = mysql_query($query) or die ("ERROR:Unable to Run Query".mysql_query()); while ($row=mysql_fetch_assoc($result)){ #$num = $row; #for ($i=1;$i<=$row;$i++) { $posttech = $row['filename']."tech"; # $postfin = $row['filename']."fin"; $postt = $_POST[$posttech]; # $postf = $_post[$postfin]; $query1 = "UPDATE doc_rate SET tech_rating=$_POST[$postt] WHERE $rate_id = $doc"; $result = mysql_query($result) or die ("ERROR:Unable To Run Query".mysql_query()); } #$row['filename'] = empty($_POST[$postt]) } ?> </body> </html>[/code] Here is the coding for the table which the results are supposed to be displayed in: [code]<html> <head> <title>Brainstorm Table</title> </head> <body> <?php $host = "myserver"; $user = "myself"; $pass = "password"; $db = "help"; $connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable To Connect".mysql_error()); mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error()); $query = "SELECT * FROM doc_data ORDER BY session "; $result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error()); if (mysql_num_rows($result) > 0) { echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>Session</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Technical Rating</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Finance Rating</b></font></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>"; echo "<td><font face=Verdana size=-1><a href=http://www.mysite.com/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>"; echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>"; #$num = $row; #for ($i=1;$i<=$row;$i++) { # $posttech = $row['filename']."tech"; # $postfin = $row['filename']."fin"; # $postt = $_post[$posttech]; # $postf = $_post[$postfin]; #} #echo "<td><font face=Verdana size=-1>".${$postt}"</td>"; #echo "<td><font face=Verdana size=-1>".${$postf}"</td>"; #echo "<td><font face=Verdana size=-1>"$row['filename']."fin</td>"; echo "</tr>"; } echo "</table>"; } else { echo "No Rows Found"; } echo "<br>"; echo "<b><font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>"; ?> </body> </html>[/code] Can anyone help me work out how to place the data into the table. Here are the problems i have encountered: 1. I have placed $_POST in a loop but that didnt seem to work. This is the way i done the loop: [code] while ($row=mysql_fetch_assoc($result)){ for ($i=1;$i<=$row;$i++) { $posttech = $row['filename']."tech"; $postfin = $row['filename']."fin"; $postt = $_post[$posttech]; $postf = $_post[$postfin]; } [/code] Should this work? 2. Do i record the ratings by creating another table in MySQL. I thought i had to, but then i created a foreign key so that i could match the $rate_id from the rating table to the $id in the doc table. Is this right? I stopped this because i was confused on how to populate the FK with the $id from the doc table. 3. I was using UPDATE so that the rating did not have to be placed in numerically. It could be placed in anywhere in the database. This is the coding i was using: [code]$update = "UPDATE doc_rate SET tech_rating = $postf WHERE $rate_id = $id [/code] $id is supposed to come from another table which is doc_data, thats is why i added a FK in doc_rate. But like i said above i do not know how to populate the FK with data from another table. Someone help me plz  ??? J3RMAIN3
  10. [quote author=mgallforever link=topic=115058.msg468310#msg468310 date=1163591899] You can't have a double $. You could always just replace it with $post .= $_POST[$post]; or $post1 = $_POST[$post]; [/quote] mgallforever: I thought that is how i use variable variable? with double $ And the error was mentioning the row under it, so i think it accepted the $$ ok.
  11. I have nearly finished creating a rating system but i am stuck on one last thing I am about to use UPDATE to add data to my databases but i have a problem trying to write the query here is what i want to do: UPDATE doc_rate SET tech_rating = $_POST[$post] WHERE $fileID = $ID [b]my problem is the $ID is part of another table(doc_data).[/b] How do i get $fileID from the doc_rate table look for a matching ID in the doc_data table. J3RMAIN3
  12. I am trying to display numbers which have been sent from a form but i get the error message: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\Apache\Apache2\PHPFiles\brainstorm\btable.php on line 42 This is the code: while ($row=mysql_fetch_assoc($result)){ $num = $row; for ($i=1;$i<=$row;$i++) { $post = $row['filename']."tech"; $$post = $_POST[$post]; } [b]42:[/b]  echo "<td><font face=Verdana size=-1>".${$post}"</td>"; Can anyone see what is wrong IN LINE 42? Isn't that the way i display something using variable variable Thanks J3RMAIN3
  13. I am trying to display numbers which have been sent from a form but i get the error message: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\Apache\Apache2\PHPFiles\brainstorm\btable.php on line 42 This is the code: while ($row=mysql_fetch_assoc($result)){ $num = $row; for ($i=1;$i<=$row;$i++) { $post = $row['filename']."tech"; $$post = $_POST[$post]; } [b]42:[/b]  echo "<td><font face=Verdana size=-1>".${$post}"</td>"; Can anyone see what is wrong IN LINE 42? Isn't that the way i display something using variable variable Thanks J3RMAIN3
  14. [code] $num=5; // number of variable(num) to extract for ($i=1;$i<=$num;$i++) {     $go="variable".$i;     $$go=$_POST[$go]; } [/code] I have used the coding which MonkeyMat has explained. I looked up extract but did not understand it very well. I have been able to use the foundations of the coding above and applied it to my table, but i am confused about something. To see if the coding comes out correct i used [b]echo[/b] >>>>> This is how i printed out the coding, [code] $x = "$"; echo "$x$go = ${$go}"; [/code] the output to this is $variable1 = But the $_POST[variable1] bit doesnt appear. I understand that it will not appear because its a reserved function (or something like that ) but how do i get this to be recognised by the server so that i can send information from the form to the table. Thanks J3rmain3
  15. One more problem im having, i have created a form and a table which i want to display the data in. To move the data from the form to the table, i know that i have to place something like this in at the top: $variable1 = $_POST['variable1']; $variable2 = $_POST['variable2']; $variable3 = $_POST['variable3']; Is there anyway i can turn this into a loop so that variable4 will appear next without having to do it manually. Thanks, J3rmain3. N.B. I have asked this question 3 times b4 and nobody as helped me so please (thats me pleading) somebody help me.
×
×
  • 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.