Jump to content

klinmy

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Everything posted by klinmy

  1. Hi, I'm having problem to display the selected data in the table. The codes are as follow, // To print table header of Date and Time echo " <table width='120%' border='1' cellspacing='0' cellpadding='0'>"; echo "<tr> <th bgcolor='#CCCCCC'>Date</th> <th bgcolor='#CCCCCC'>Time</th>"; // To print table header for the selected variables ($var) for ($i=0; $i<$c; $i++) { $var=$v[$i]; // the selected variable. eg: $v[0] is Height; $v[1] is Weight; echo "<th bgcolor='#CCCCCC'>$var</th>"; } // <- no problem with this echo "</tr>"; while ($row = mysql_fetch_array($result)) { echo '<tr><td align=center>' . $row['Date'] . '</td>'; echo '<td align=center>' . $row['Time'] . '</td>'; echo '<td align=center>' . $row[$var] . '</td>'; echo "</tr>"; } //end while And it's an example of the output: Date Time Height Weight 12 feb 10.00am 40 <-(it's the weight) 15 feb 11.00am 60 16 feb 12.00am 70 17 feb 11.00am 20 18 feb 01.00am 40 It displayed only the weight ($v[1]) values under Height. And when I tried putting the while loop inside the for loop, it displayed only the height values. What it should be done in order to print both selected variables (height & weight) together with the date and time into the table? thanks in advance.
  2. Hi, I would like to display the selected data in a table. echo "<tr><td>"; echo "Data1; echo "</td></tr>"; while ($row=mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "$row["data1"]; echo "</td></tr>"; } -----some other codes------- echo "<tr><td>"; echo "Data3; echo "</td></tr>"; while ($row2=mysql_fetch_assoc($result)) { echo "<tr><td>"; echo "$row2["data3"]; echo "</td></tr>"; } The result I got is something like ths, Data1 12 4 1 2 3 Data3 5 4 2 6 4 Is there a way that i can make the table looks like this? Data1 Data2 12 5 4 4 1 2 2 6 3 4 Thanks in advance
  3. klinmy

    Array

    wow thanks ALOT premiso! seriously, i've been trying to figure it out for the whole freaking day. thanks for helping!
  4. klinmy

    Array

    Hi, i would need this type of array data e.g. $new=array(12,23,9,2) to be used to plot the graph (axis-y), $plot = new BarPlot($new); however, if the array data is retrieved from the database, how can i map the retrieved data (eg: temperature = 21, 20, 19, 15) into $new = array (21,20,19,15)? while ($row = mysql_fetch_assoc($result)) { $temp = $row["Temperature"]; } it retrieved the data as (21201915), what should i do to map this into $new=array (21,20,19,15). thanks in advance.
  5. yea, i tried this, $query="UPDATE City SET CityName='$CityName'" . " WHERE ID='7'"; where for example the auto_increment ID for New York is 7. It updated New York with no problem. thanks
  6. Thanks KingPhilip, i tried this. it popped up "record updated" but in fact it didn't. It did nothing to the edition.
  7. thanks blueman378, but it shows the same error after changed it to $result=mysql_query($query) or die(mysql_error()); "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" <html> <head> <title>City</title> </head> <body> <form name="frm" form action="" method="post" > <?PHP function check_mysql() { if(mysql_errno()>0) { die("MySQL error". mysql_errno() . ":" . mysql_error()); } } $db=mysql_connect("localhost","root",""); if(!$db) { die("Failed to open connection to MySQL server."); } mysql_select_db("TPS"); check_mysql(); mysql_select_db("TPS"); check_mysql(); if(!isset($_POST['ID'])) { $ID=0; } if(isset($_POST['save'])) { $CityName=$_POST["CityName"]; $errors=0; if($errors==0) { $query="INSERT INTO city" . "( CityName) VALUES ('$CityName')"; $result=mysql_query($query); check_mysql(); $ID=mysql_insert_id(); } } elseif(isset($_POST['update'])) { $error=0; if($error==0) { $query="UPDATE City SET CityName='$CityName'" . "WHERE ID=$ID "; $result=mysql_query($query) or die(mysql_error()); $message="<script>" ." alert('Record Updated');" ."</script>"; } } ?> </div> <div id="Layer1" style="position:absolute; left:238px; top:105px; width:662px; height:131px; z-index:4"> <p>City Name : <input type="text" name="CityName" <?php echo "VALUE=\"$CityName\""?> > </p> <p><span class="style16">.</span> </p> <input name="update" type="submit" id="update" value="Update "style=" width:8em;" /> <input name="save" type="submit" id="save2" value="Save " style=" width:7em;" / > <input type="HIDDEN" name="ID" <?php echo "VALUE=\"$ID\""?>> <?PHP if(isset($message)) { echo "<BR><BR>$message"; } ?> </body> </html> this is the simplify code which is from A-Z just in case there's other possibility that causes the error. i've tried every way i know to solve the problem, killed my whole day. thanks in advance.
  8. Tried this as well, yet the record is not updated. elseif(isset($_POST['update'])) { $error=0; $ID=$_POST["ID"]; if($error==0) { $query="UPDATE City SET CityName='$CityName'" . "WHERE ID=$ID"; $result=mysql_query($query); check_mysql(); $message="<script>" ." alert('Updated');" ."</script>"; } } What seems to be wrong?
  9. Thanks blueman378, my mistake. But after changing it, it shows this error when i click the update button. "MySQL error1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" Any possible answer for this? Dun find anything wrong with the update function. Thanks.
  10. I've been trying it for the whole day, but i just can't figure what's the problem with the code.. It's a form to record the city name, where the table (City) contains only 2 fields which are ID (auto_increment) and CityName. Below is the code for the form. There'r no problem on 'search', 'save', and 'delete', but the conditions for the functions have to be set as, for example $query="DELETE FROM City where CityName='$CityName' rather than $query="DELETE FROM City where ID='$ID' So there's where the "update" function comes. if(isset($_POST['ID'])) { $ID=0; } if(isset($_POST['save'])) { $CityName=$_POST["CityName"]; $errors=0; if($errors==0) { $query="INSERT INTO city" . "( CityName) VALUES ('$CityName')"; $result=mysql_query($query); check_mysql(); $message = "<script>" ." alert('Record Saved');" ."</script>"; $CityName=""; $ID=mysql_insert_id(); } } elseif(isset($_POST['search'])) { $ID=0; $CityName=$_POST["CityName"]; $query5="SELECT CityName FROM City ". "WHERE CityName= '$CityName' AND ID > $ID"; $result5=mysql_query($query5); check_mysql(); $row5=mysql_fetch_row($result5); check_mysql(); if($row5>0) { $CityName=$row5[0]; $message = "<script>" ." alert('Found $IDfound');" ."</script>"; $IDfound='$IDfound'; } else { $message = "<script>" ." alert('No Record Found');" ."</script>"; //$CityName=""; } } elseif(isset($_POST['update'])) { $query="UPDATE City SET CityName='$CityName'" . "WHERE ID=$ID"; $result=mysql_query($query); check_mysql(); $message="<script>" ." alert('Record Update');" ."</script>"; } elseif(isset($_POST['delete'])) { $CityName=$_POST["CityName"]; $error1=0; if($error1==0) { $query="DELETE FROM City where CityName='$CityName'" ; $result=mysql_query($query); check_mysql(); $message="<script>" ." alert('Record deleted');" ."</script>"; $CityName=""; } } thanks in advance. I tried looking at other codes too, but still can't able to find the solution for it..
  11. it's done. :D thanks really
  12. sorry, i have another question regarding to this. can i save the value of "echo date('F',strtotime($date));" into database? how am i suppose to tht?? thanks
  13. i would like to ask how to extract the month from a date? i saved the date in yyyy/mm/dd format, and how do i need todo in order to know whether the date is in Jan, Feb or so on? thanks.
  14. yea thanks alot khendar! it works now
  15. thanks khendar, i've change the name to answer as u taught, and canceled off the '!', but it's still the same..
  16. radio.php [code]<form method="post" action="nextpage.php"> <? $query=mysql_query("SELECT name FROM staff WHERE id='1122' "); while ($row = mysql_fetch_array($query)) {     echo "$row[name]";     $name=$row[name];      } ?> <input type="radio" name="answer" value="<? $_POST['name'] ?>"> <input type="radio" name="answer" value="B"> <input type="submit" name="Submit" value="Submit"> </form>[/code] nextpage.php [code]<? echo '1122 is  '.$_POST['name']!; ?>[/code] when i clicked in the 1st radio button, it displayed "[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]1122 is ! [!--colorc--][/span][!--/colorc--]" why cant it display the name as it's shown in radio.php? thanks
  17. thanks alot.. i will try todo tht. i need the duration, coz it involves in another calculation in other forms
  18. i'm doing a form which the admin can enter a particular date for the system's users. Different users may have different dates which will be deducted by the current date in order to get the duration. my question is, can i make a button which can update all the duration of the system's users in the database, so that the admin doesn't need to update the duration one by one when it enters a new year? thanks
  19. it's now working fine after changing to ths.. [code]if(isset($save)) {                       $query="INSERT INTO apply " . "(  name, sex) VALUES ( '$name', '$sex')";     $result=mysql_query($query);     check_mysql();     $id=mysql_insert_id();              header("Location: FormB.php?id=$id&name=$_POST[name]&sex=$_POST[sex]");exit;      }[/code] thanks guys
  20. there isn't any GET for id in Form A. or is there?? i'm trying to get the value of id to Form B. i've tried using both $_POST[id] and $_POST['id']. but it just made no different..name and sex can stil get the values as entered in form A
  21. it's the code i tried on form A i now change the next button to save. [code]mysql_select_db("onlineleave"); check_mysql(); if(!isset($id))     $id=0; if(isset($save)){              $query="INSERT INTO apply " . "(name, sex) VALUES ( '$name', '$sex')";     $result=mysql_query($query);     check_mysql();     $id=mysql_insert_id();                 echo "id = $id"; }[/code] the message showed the correct id as in database, no problem it seems. but when i bring the info to Form B, [code]if(isset($save)) {                       $query="INSERT INTO apply " . "(  name, sex) VALUES ( '$name', '$sex')";     $result=mysql_query($query);     check_mysql();     $id=mysql_insert_id();              header("Location: FormB.php?id=$_POST[id]&name=$_POST[name]&sex=$_POST[sex]");exit;      }[/code] and placing this in Form B, [code]<?php echo '<pre>'.print_r($_GET,true).'</pre>'; ?>[/code] it came out like this, Array ( [name] => john [id] => 0 [sex] => male ) why is it cant get the value id (auto_increment)? thanks alot!
  22. thanks txmedic03, but all the other values (name and sex) are working fine except for id only. i tried to close my Form B. by running only Form A, nomatter how many times i enter data, the id still remains '0'..
  23. when i fill up form A, the information will be displayed in the next page (form B) when i click the "next" button. [!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]example data that i entered in Form A in the 1st time, id = (auto_increment) name=john sex = male example data which is displayed in Form B in the 1st time, id=0 (supposely 221) name=john sex = male[!--colorc--][/span][!--/colorc--] [!--coloro:#993399--][span style=\"color:#993399\"][!--/coloro--]example data that i entered in Form A in the 2nd time, id = (auto_increment) name=selina sex = female example data which is displayed in Form B in the 2nd time, id=221 (supposely 222) name=selina sex = female[!--colorc--][/span][!--/colorc--] the problem is when the first time i fill up the form, the auto_increment id will not be displayed in form B, it will only be displayed with the first id when i fill up for the second time. below is parts of my script in form A, [code]$db=mysql_connect("localhost","ky","pw"); if(!$db) {     die("Failed to open connection to MySQL server."); } mysql_select_db("onlineleave"); check_mysql(); if(!isset($id)) {     $id=0; } elseif(isset($next)) {              if($errors==0)     {                  check_mysql();     $id=mysql_insert_id();          header("Location: applyBa.php?name=$_POST[name]&id=$_POST[id]&sex=$_POST[sex]"); exit;          }     } <input type="hidden" name="id" <?php echo "VALUE=\"$id\""?>>[/code] Form B [code]<?php echo $_GET[name] ?> is <?php echo $_GET[sex] ?> with ID <?php echo $_GET[id] ?>. if(isset($save)) {          $query="INSERT INTO tableB " . "( name, sex) VALUES ( '$name, '$sex)";     $result=mysql_query($query);     check_mysql();     $id=mysql_insert_id();[/code] thanks the id value in the database is correct, just the display in form B has problem.
×
×
  • 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.