Jump to content

_confused_

Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling
  • Location
    Meow City

_confused_'s Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hi thr, thanks for the responses.teng84, i've tried your last suggestion but it doesn't work. it will only display the first column of my table. i've modified a few parts of my code. this is my drop down list. <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> <? $id = $_POST["progtitle"]; $query="SELECT kid,ktitle FROM kursuslist order by ktitle"; $result = mysql_query ($query); echo "<select name=progtitle value=''>kid</option>"; // printing the list box select command?> <option value="All" <? if (isset($_POST['progtitle'])) {if ($_POST['progtitle']== 'All') {echo "selected";}} ?> >All</option> <? while($nt=mysql_fetch_array($result)){//Array or records stored in $nt if($id==$nt[kid]) { echo "<option value=$nt[kid] selected=\"selected\">$nt[ktitle]</option>"; } else { echo "<option value=$nt[kid]>$nt[ktitle]</option>"; } /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box</p> ?> <input name="courseEva" type="submit" id="courseEva" value="Hantar Borang"> </form> and i can count all my input using the following code... if ($id == "All"){ for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b2=$i"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } } } else { for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b2=$i AND kid=$id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } }} it looks kind of messy to me so i'm wondering if i can simplify it by changing it to the code below but it doesn't work. it is possible for us to concatenate a sql statement? for ($i=1; $i<=5; $i++){ if ($id == "All"){ $query = "SELECT COUNT(bid) FROM boranglist where b1=$i"; } else { $query = $query . " AND kid=$id"; } $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } }
  2. hi teng84, thanks for your response. i'm not quite sure what you meant but let me rephrase my question. the system that i'm trying to develop is an evaluation system whereby i can count the ratings (1-5) according to the questions. below is the code i use to grab total of ratings for question no.1 (b1) for one subject (kid). the value of kid is obtained through my drop down list. i intend to calculate all ratings regardless of the course. my current drop down list uses a loop to grab all data. where should i include the option ALL so that i can query my table without filtering kid? <? for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b1=$i AND kid=$id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } } ?>
  3. hi! i would like to include the option ALL in my drop down list but i'm not quite sure how to do it. pls advise. thanks!! <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> <? $query="SELECT kid,ktitle FROM kursuslist order by ktitle"; $result = mysql_query ($query); echo "<select name=progtitle value=''>kid</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt if($id==$nt[kid]) { //echo "<option value=$nt[kid]>$nt[ktitle]</option>"; echo "<option value=$nt[kid] selected=\"selected\">$nt[ktitle]</option>"; } else { echo "<option value=$nt[kid]>$nt[ktitle]</option>"; } /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box</p> ?> <input name="courseEva" type="submit" id="courseEva" value="Hantar Borang"> </form>
  4. pheww! i've used two sql queries to grab the records separately from both tables and then play around with condition statements...it works perfectly.
  5. i'm running PostgreSQL 7.0.3 and my query using left join gives me this error message. does this mean all hope is gone?? PostgreSQL said: ERROR: OUTER JOIN is not yet supported
  6. help! how to i reference a record from master table when it doesn't have a child record? below is a sample i got from the postgreSQL manual & my problem is rather similar to that. how should i write my sql query so that CAT will also appear but the vegetable column for it is empty? i've tried using MS Access and the records retrieved is correct. The sql query goes like this: SELECT animal.animal_id, vegetable.* FROM animal LEFT JOIN vegetable ON animal.animal_id = vegetable.animal_id; test=> SELECT * FROM animal; animal_id | name -----------+----------------- 507 | rabbit 508 | cat (2 rows) test=> SELECT * FROM vegetable; animal_id | name -----------+----------------- 507 | lettuce 507 | carrot 507 | nut (3 rows) test=> SELECT * test-> FROM animal, vegetable test-> WHERE animal.animal_id = vegetable.animal_id; animal_id | name | animal_id | name -----------+-----------------+-----------+----------------- 507 | rabbit | 507 | lettuce 507 | rabbit | 507 | carrot 507 | rabbit | 507 | nut (3 rows)
×
×
  • 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.