PHP and MySQL problem - please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
karl1
Forum Newbie
Posts: 2
Joined: Fri Jun 05, 2009 4:46 am

PHP and MySQL problem - please help

Post by karl1 »

Hello all,

I have a problem with the following code. What it is meant to do is query a database table which contains details of various activities and print them to the screen along with a checkbox for the user to tick. Also included in the code is another query to verify whether the user has selected the activity (this information is contained in another table), if so print out the details of the activity with a checked checkbox.

Code: Select all

 
    $sql = "SELECT * FROM `ifile_Activities` 
            ORDER BY `Activity_Name` ASC";
        
    include("../rms/v2/includes/php/connect.php");
        
    while ($row = mysql_fetch_assoc($rst))
    {
        echo "<table border = '1' width = '541' bordercolor = 'black' cellpadding = '0' cellspacing = '0' bgcolor = 'white'>";
            echo "<tr>";
                echo "<td>";
                    echo "<table border = '0' width = '541' bgcolor = 'white'>";
                        echo "<tr>";
                            echo "<td>";
                                echo "<strong><font size = '2'>" . $row['Activity_Name'] . "</font></strong>";
                            echo "</td>";
                            echo "<td align = 'right' width = '10'>";
                            
                                $sql = "SELECT * FROM `ifile_ActivityStudent`
                                        WHERE `AS_IF_PU_UPN` = '" . $pu_upn . "' 
                                        AND `AS_Activity_ID` = '" . $row['Activity_ID'] . "'";
                                        
                                include("../rms/v2/includes/php/connect.php");
                                
                                $num_rows = mysql_num_rows($rst);
        
                                if($num_rows == 0)
                                {       
                                    echo "<input type = 'checkbox' name = 'activities[]' value = '" . $row['Activity_ID'] . "'>";
                                }
                                else
                                {       
                                    echo "<input type = 'checkbox' name = 'activities[]' value = '" . $row['Activity_ID'] . "', checked>";
                                }
                            echo "</td>";
                        echo "</tr>";
                        echo "<tr>";
                            echo "<td>";
                                echo "<font size = '2'>" . $row['Activity_Description'] . "</font>";
                            echo "</td>";
                        echo "</tr>";
                        echo "<tr>";
                            echo "<td>";
                                echo "<strong><font size = '2'>Dates / times: </strong>" . $row['Activity_Date'] . "</font>";
                            echo "</td>";
                        echo "</tr>";
                    echo "</table>";
                    echo "<table border = '0' width = '541' bgcolor = 'white'>";
                        echo "<tr>";
                            echo "<td align = 'left'>";
                                echo "<strong><font size = '2'>Staff involved: </strong>" . $row['Activity_Staff'] . "</font>";
                            echo "</td>";
                            echo "<td align = 'right'>";
                                echo "<strong><font size = '2'>Location: </strong>" . $row['Activity_Location'] . "</font>";
                            echo "</td>";
                        echo "</tr>";
                    echo "</table>";
                echo "</td>";
            echo "</tr>";
        echo "</table>";
        echo "<br />";
    }               
   
At the moment only the first activity is printed out. This code did work before I included the second query which searches the `ifile_ActivityStudent` table.

Any help with this problem would be greatly appreciated.

Regards.
Last edited by Benjamin on Fri Jun 05, 2009 11:26 am, edited 1 time in total.
Reason: Changed code type from text to php.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: PHP and MySQL problem - please help

Post by mattpointblank »

Might be because both your queries are called $sql so it confuses the parser about which one it's looping through. Rename the second one and all its associated variables so there's no overlap.
karl1
Forum Newbie
Posts: 2
Joined: Fri Jun 05, 2009 4:46 am

Re: PHP and MySQL problem - please help

Post by karl1 »

That works great thanks!!!
Post Reply