Jump to content

davidcriniti

Members
  • Posts

    93
  • Joined

  • Last visited

Posts posted by davidcriniti

  1. Well I've been bashing away at this and have I guess made some progress. I tried using distinct and noduplicate values and the below is the coding I used when I came closest to success.

     

    My actual application is using different values from the example I provided in my initial post, but basically it's the same thing. I'm looking in a table called editablepage for two columns: pagename and content. In the table there are multiple instances of each pagename, but I only want one instance of each pagename and it's corresponding content.

     

    Using the below code I have successfully produced a table which has unique pagenames. This is what I want. However, the content column in my table is empty.

     

    The code is below. Any tips on where I need to modify would be appreciated.

     

    
      <?php
    
    	  mysql_connect ("localhost", "MYUSERNAME", "MYPASSWORD");
      mysql_select_db ("MYDATABASE");
    
    // Get all the data from the "example" table
    
    	$result = mysql_query("SELECT DISTINCT pagename FROM editablepage ORDER BY id DESC")
    or die(mysql_error());
    
    	echo "<table border='1' align='center' cellpadding='10' cellspacing='0' bordercolor='#000000'>";
    	echo "<tr bgcolor='#6175BE'> <th>Page Name</th> <th>Content </th></tr>";
    
    while($row = mysql_fetch_array( $result )) {
    
          $pagename = $row['pagename'];
    	    $content = $row['content'];
    
    echo "<tr bgcolor='#CCCCCC'><td>";
    echo $row['pagename'];
    	echo "</td><td>";
    		echo $row['content'];
    	echo "</td></tr>";
    
    
    }
    	echo "</table>";
    
    	?>
    

     

  2. Hi, I'm just wondering if there's any way to use the Limit to limit a search to the first instance of multiple items in one column?

     

    Eg, in a table called news I might have:

     

    subject          content

    general          general news1

    general          generalnews2

    faq                faq1

    faq                faq2

    general          generalnew3

     

     

    When I do

     

     SELECT * FROM news ORDER BY content DESC LIMIT 0,1

    (same if I substitute the word subject for content in the line above)

     

    ...I get just the first item.

    Ie:

    subject      content

    general      generalnews1

     

    How would I go about getting the first instance of each subject and its contents to appear?

     

    Ie:

    subject    content     

    general  generalnews1

    faq          faq1

     

     

     

    Thanks,

     

    Dave

  3. ...but I don't necessarily want to round it off. Eg: If the value was 42.195, I'm happy to keep it that 42.195.

     

    I'd only like numbers changed when there is no information on the right-hand-side of the decimal.

     

    Eg: If someone ran exactly 20km, I'd like to see 20      ....rather than 20.000

     

    Not sure if this is possible or not?

  4. Hi guys,

     

    I've got a line of code that asks for a column called "distance_completed" to be displayed as part of a string.

     

    This column tells users how far people have run in a running race.

     

    I set up this field in my database to 11,3 so all distances appear with a decimal at the end, and then 3 digits after the decimal place.

     

    How would I alter the code so that the numbers that don't have any information in the places section just appear as integers Eg: 42 instead of 42.000 (for someone who ran exaclty 42km) and those that do have information in the decimal places appear correctly (eg: if a person ran 42km and 195m, it would appear as 42.195).

     

    I think this is probably the only line of code that would need modification:

     

    
    echo ($row['time'] != null)?$row["time"]:"dnf at ".$row["distance_completed"]."km.";
    

  5. Hi everyone,

     

    I am currently making a page for a friend to upload a bunch of photos at a time.

     

    I was quite pleased that after a bit of googling and trial and error, I figured out how to do this so that multiple records could be added to my table with one submit button.

     

    However, my form has 10 browse iconcs. A few tests have revealed that my problem is that if only one picture is uploaded, I still get 9 entries in my database, which I don't want.

     

    My question is how can I alter the code so that a row is only populated in the database if an image is uploaded.

     

    I guess something that sort of says :

     

    if($imgx!="")

    {

    populate that row in the table

    }

     

    else

     

    {

    don't

    }

     

     

    ...and the same for $imgx002 through to $imgx010

     

     

    The current query is below. Any pointers are much appreciated.

     

    
    
    $query = "INSERT INTO photo_uploads (date, photo_name)" . "VALUES (NOW(), '$imgx'), (NOW(), '$imgx002'), (NOW(), '$imgx003'), (NOW(), '$imgx004'), (NOW(), '$imgx005'), (NOW(), '$imgx006'), (NOW(), '$imgx007'), (NOW(), '$imgx008'), (NOW(), '$imgx009'), (NOW(), '$imgx010')";
    

  6. Hi folks,

     

    I'm using this code to display a picture that is uploaded in a form.

     

    
    print	"<img src='http://www.coast2kosci.com/mylongrun/test/photo_uploads/$imgx' width='300' height='300'  alt='Your photo' />";
    
    

     

    At first I tried specifying only the width, without the height. But for tall photos, the display wasn't really what I was after.

     

    Then I specified both width and height, which results in a mis-scaled photo.

     

    Is there any way that I can specify the height and width atributes as a sort of maximum / or limiter. Ie:  If the height is greater than the width, limit the height to 300, and if the width is greater than the height, limit the width to 300?

     

    Thanks for your time,

     

    Dave

     

     

     

     

  7. There's nothing wrong with it anymore I'm pleased to say!  ;) Thanks again for your help.

     

    All in all it was 3 things:

    - The " ' " after PASSWORD - and yep, that was just inadvertently deleted as I deleted the password.

    - Using  $sex until you advised me to change it to $row['sex'].

     

    - Under the if / else statement, I"d also had (for some reason unbeknownst to myself!)  " echo "<tr bgcolor='#FF99FF'>"; " which I didn't notice until a bit later. That caused all cells to have a pink background, regardless of the sex of the athlete. Goes to show you can't take you're eye off the ball for a second!

     

    Thanks again,

     

    Dave

  8. Thanks ProjectFear,

     

    I got it working.

     

    I notice I'd also thrown in another " echo "<tr bgcolor='#FF99FF'>";  " after the if / else statement which made things a bit more difficult, but I got there in the end.

     

    Just out of interest, was the error you were referring to at the top of my code the missing " ' " after the word PASSWORD, or is there something else?

     

    Cheers,

     

    Dave

  9. ...I'm Australian, hence the 'u' in coloured, in case you're wondering!  :D

     

    Basically I'd like to create a table of results for a running race that has rows shaded pink if the participant is female.

     

    I think my problem is something to do with not declaring 'sex' as a variable, but I'm not really sure how to do this. My code is below. Any advice would be much appreciated.

     

    <?php
    $dbcnx = @mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD);
    if (!$dbcnx) {
      exit('<p>Unable to connect to the ' .
          'database server at this time.</p>');
    }
    
    if (!@mysql_select_db('coast2ko_test')) {
      exit('<p>Unable to locate the results ' .
          'database at this time.</p>');
    }
    
    $sql = mysql_query("SELECT * FROM result_single ORDER BY place ASC");
    
    echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
    echo "<tr> <td><H3>First name</h3></td> <td><H3>Lastname</H3></td>  <td><H3>Sex</H3></td>  <td><H3>Time</H3></td><td><H3>Place</H3></td></tr>";
    // keeps getting the next row until there are no more to get
    while ($row = mysql_fetch_array($sql)) {
    
    
    
    // Print out the contents of each row into a table
    
    
    
      if ($sex=="F")
    echo "<tr bgcolor='#FF99FF'>";
      else
    echo "<tr>";
    
    echo "<tr bgcolor='#FF99FF'>";
    echo "<td>";
    echo $row['firstname'];
    echo "</td><td>";
    echo $row['lastname'];
    echo "</td><td>";
    echo $row['sex'];
    echo "</td><td>";
    echo $row['time'];
    echo "</td><td>";
    echo $row['place'];
    echo "</td></tr>";
    
    
    }
    echo "</table>";
    
    
    
    ?>

  10. Hi,

     

    I've made an online test for my kids at school, which is marked automatically via php.

     

    Most questions have been ok, using this sort of format:

    if ($q001 == "right") {$q001score = 1;}else {$q001score = 0;};

     

    However, I've had a bit of trouble with questions where there is more than one answer.

     

    I've tried using 'or' with little success. I find that '1' gets added to the score regardless of whether I get the right answer, wrong answer, or input no answer when using the following script:

     

    if ($q001 == "right" or "right2") {$q001score = 1;}else {$q001score = 0;};

     

    I've also substituted || for 'or' with no success.

     

     

    I have solved the problem by extending the if-else statement as follows:

    if ($q001 == "right" ) {$q001score = 1;} else if ($q001 == "right2") {$q001score = 1;}else {$q001score = 0;};

     

    I was just wondering if I could reduce the amount of code by altering the 'or' statement above as the if, else if, else statement seems a bit cumbersome?

     

     

    Yours gratefully,

     

    Dave

     

     

     

     

     

     

  11. Thanks cags. I tried to do this and at first glance it seemed i got it right first go. When I searched all results, there was no problem.

     

    However, when I limited the search (by year or course or gender etc), I got the following error (this one is when I tried to select a specific year):

     

    Error retrieving results from database!

    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 'AND year='2004'' at line 1

     

    (note - I sorted by 'timeisnull' and then 'time' because I put a timeisnull column in so that dnfs would be listed under the results based on a time. ie: If a person dnf'd, their time would be 'dnf' which would appear above a the time if sorted by time, but if sorted by time is null with dnfs given a '1', and people who finished getting a '0', those who finished would be sorted first)

     

    Here is the original code:

     

    <?php
    
    $dbcnx = @mysql_connect('localhost', 'coast2ko_me', 'monners1');
    if (!$dbcnx) {
      exit('<p>Unable to connect to the ' .
          'database server at this time.</p>');
    }
    
    if (!@mysql_select_db('coast2ko_results')) {
      exit('<p>Unable to locate the results ' .
          'database at this time.</p>');
    }
    
    // The basic SELECT statement
    $select = 'SELECT DISTINCT firstname, lastname, gender, time, year, course, position, gender_position, distance_completed';
    $from   = ' FROM entrants, results ' ;
    $where  = ' WHERE results.entrantid = entrants.entrantid ';
    
    $year = $_POST['year'];
    if ($year != '') { // A year is selected
      $where .= " AND year='$year'";
    }
    
    $course = $_POST['course'];
    if ($course != '') { // A course is selected
      $where .= " AND course='$course'";
    }
    
    
    $searchtext = $_POST['searchtext'];
    if ($searchtext != '') { // Some search text was specified
      $where .= " AND lastname LIKE '%$searchtext%'";
    }
    
    $gender = $_POST['gender'];
    if ($gender != '') { // Gender is selected
      $where .= " AND gender='$gender'";
    }
    
    ?>
    

     

     

    And here is the modified code. THe only difference between the two is on the end of line which begins with the $where variable.

     

     

      <?php
    
    $dbcnx = @mysql_connect('localhost', 'myusername', 'mypassword');
    if (!$dbcnx) {
      exit('<p>Unable to connect to the ' .
          'database server at this time.</p>');
    }
    
    if (!@mysql_select_db('coast2ko_results')) {
      exit('<p>Unable to locate the results ' .
          'database at this time.</p>');
    }
    
    // The basic SELECT statement
    $select = 'SELECT DISTINCT firstname, lastname, gender, time, year, course, position, gender_position, distance_completed';
    $from   = ' FROM entrants, results ' ;
    $where  = ' WHERE results.entrantid = entrants.entrantid ORDER BY timeisnull, time ASC ';
    
    $year = $_POST['year'];
    if ($year != '') { // A year is selected
      $where .= " AND year='$year'";
    }
    
    $course = $_POST['course'];
    if ($course != '') { // A course is selected
      $where .= " AND course='$course'";
    }
    
    
    $searchtext = $_POST['searchtext'];
    if ($searchtext != '') { // Some search text was specified
      $where .= " AND lastname LIKE '%$searchtext%'";
    }
    
    $gender = $_POST['gender'];
    if ($gender != '') { // Gender is selected
      $where .= " AND gender='$gender'";
    }
    
    ?>
    

     

     

     

     

     

     

     

     

    T

  12. Hi,

     

    I have developed a website for a few mates who are organising a long distance running race (which is currently in progress).

     

    I've got a search page and a display page, which pulls results from the database (the 'entrants' table and the 'results' table).

     

    It works fine for results that I put in initially (previous years' results).

     

    However, new records that I'm entering are going to the bottom of the results when it's not what I would have thought would happen.

     

    Example - Our winner crossed the line in 26:01:40

     

    If you do a search (and don't select a year), this should be at the top, as it is a race record, but his name (Jo Blake) ends up at the bottom.

     

    htthttp://www.coast2kosci.com/results_sd_search.php

     

     

     

    Any help or advice would be appreciated.

     

    Thanks,

     

    Dave

     

     

     

     

     

     

     

     

     

     

     

  13. Hi there,

     

    I've developed a template to make multiple choice quizzes for the students at my school.

     

    They fill out a form on a html page. Upon submit, feedback is provided.

     

    For example, with question 1 ( $q001 ) as a variable, I've made php code like this:

     

    $q001 = $_POST["q001"];

     

      <?php

    if ($q001=="right")

      echo "Well done";

      ?>

     

    My question is this. How would I go about inserting an image ( tick.gif ) rather than saying "Well done"?

     

    Any help would be much appreciated.

     

    Dave

     

     

  14. Hi everyone,

     

    I'm new here, so I might just introduce myself first. I'm Dave, a teacher in Sydney who teaches new arrivals to Australia to speak English.

     

    I feel I should also disclose that I've also asked this question on another similar forum. ( http://www.phphelpforum.com/index.php ). I apologise if that's not 'the done thing'. I guess I'm just trying to find the best source of help and at this stage I don't know one forum from the other....anyway...to my question:

     

    I have a very simple quiz here ( http://www.tesolclassroom.com/compspelquiz001.html ) which asks students to identify 10 pieces of computer hardware.

     

    I've set up the php code such that each answer is imported directly into a Mysql database (See my code below).

     

    I've got this part working with no problems. Basically each question from 1 to 10 is labelled '$q001' to '$q010', and these correspond with database cells of the same names ( 'q001' to 'q010' ).

     

    However... I also have another cell for each question which is the same name, but with 'score' appended to the end ( ie: 'q001score' to 'q010score' ).

     

    Is it possible to send a value of '1' to each of these score cells if the student spells the piece of hardware correctly, or a value of '0' to each of these score cells if the word is not spelt this way?

     

    Ie: The first answer is a 'mouse'. If the student spells it correctly (case sensitive), I'd like the value '1' sent to cell q001score, and if they spell it any other way (or leave it blank), a '0' would be sent to this cell?  Similarly, the second answer is 'monitor', and I'd like a '1' sent to cell q002score if it is spelt as such, or a '0' sent to this cell if it is spelt any other way.

     

    The second part of my question relates to adding these scores. The final cell in my Mysql database is entitled 'totalscore'. Is it possible to add the numbers from cells '001score' to '010score' to put a total in this final cell?

     

    Thanks for your time,

     

    Dave

     

    
    $query = "INSERT INTO compspelquiz001 (firstname, lastname, class, q001, q002, q003, q004, q005, q006, q007, q008, q009, q010)" . "VALUES ('$firstname', '$lastname', '$class', '$q001', '$q002', '$q003', '$q004', '$q005', '$q006', '$q007', '$q008', '$q009', '$q010')";
    //if($query){echo 'data has been placed'}
    mysql_query($query) or die(mysql_error());
    mysql_close($con);
    
    

     

     

     

     

     

     

     

     

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