Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Location
    Plymouth, NH
    Posts
    1

    Exclamation Unanswered: Processing Multiple Instances of a Variable

    I've tried to find a way to do this but I couldn't find anything on Google or the PHP/MySQL documentation sites of much help (I'm just starting to learn PHP). What I'm trying to do is process multiple instances of a variable. Currently, this code only calls 1 record and not the rest... is there a way to modify this code so the URL displays all records? Any help would be much appreciated.

    Code:
    <?php
    
    $PAGE_NAME = "test.php";
    
    include ("common_vars.php");
    
    /* Connecting, selecting database */
    
    $link = mysql_connect($DB_HOSTNAME1,$DB_USERNAME1,$DB_PASSWORD1);
    mysql_select_db("database_table");
    
    /* Performing SQL query */
    
    $query = "SELECT DATE_FORMAT(date,'%m/%d'), sport, opponent FROM athletics_test
    	WHERE (date >= (CURRENT_DATE + 0) && date <= (CURRENT_DATE + 10))
    	ORDER BY date, sport, opponent ASC";
    
    $result = mysql_query($query);
    
    /* Print results */
    
    if ($query)
    {
    	$col_value = mysql_fetch_array($result, MYSQL_ASSOC);
    
    	$date = $col_value["DATE_FORMAT(date,'%m/%d')"];
    	$sport = $col_value["sport"];
    	$opponent = $col_value["opponent"];
    }
    
    echo "<a href=\"$BASE_URL/test.php?date=$date&sport=$sport&opponent=$opponent\">Test Link</a>";
    
    mysql_free_result($result);
    
    mysql_close($link);
    
    ?>
    Last edited by Curtis782; 06-23-03 at 15:14.

  2. #2
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    You are not looping through the results, just reading the first record. You need to modify your code to something like this, so that it loops through the whole dataset:

    Code:
    if ($query)
    {
    	$col_value = mysql_fetch_array($result, MYSQL_ASSOC);
    
    	$date = $col_value["DATE_FORMAT(date,'%m/%d')"];
    	$sport = $col_value["sport"];
    	$opponent = $col_value["opponent"];
    }
    
    echo "<a href=\"$BASE_URL/test.php?date=$date&sport=$sport&opponent=$opponent\">Test Link</a>";
    should be...
    Code:
    while ($col_value = mysql_fetch_array($result, MYSQL_ASSOC)){
        $date = $col_value["DATE_FORMAT(date,'%m/%d')"];
        $sport = $col_value["sport"];
        $opponent = $col_value["opponent"];
        echo "<a href=\"$BASE_URL/test.php?date=$date&sport=$sport&opponent=$opponent\">Test Link</a>";
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •