Jump to content

klinmy

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

klinmy's Achievements

Member

Member (2/5)

0

Reputation

  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
×
×
  • 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.