Search the Community
Showing results for tags 'loop'.
-
I am creating a Child Security Application called Shield Child Security. I ran into a roadblock, and I had to ask myself, "How will they take attendance?" So I want to take a mass status change. If you look at the picture you will see what I mean. <body> <div align="center"> <div style="width:460px; background-color:#000000; padding:11px;" align="left" class="shadow"> Children: <div style="background-color:#3399FF; padding:11px;" align="left" class="shadow"> <form action="" method="POST"> <table> <?php $query = mysql_query("SELECT * FROM Children WHERE classroom='$class'") or die("ERROR"); $numrows = mysql_num_rows($query); if ($numrows!=0){ while ($row = mysql_fetch_assoc($query)){ $cid = $row['id']; $fname = $row['firstname']; $lname= $row['lastname']; $status = $row['status']; $classroom = $row['classroom']; echo '<tr style="background-color:gray;"><td><input type="checkbox"></td><td align="center" width="150" name="'.$cid.'">[<a href="child.php?id='.$cid.'">'.$fname.' '.$lname.'</a>]</td>'; if ($classroom != 'none'){ if ($status == 1) { echo '<td align="center" width="200"><font color="red">Not Present</font>'; } else if ($status == 2){ echo '<td align="center" width="200"><font color="lightgreen">Present</font>';} } else { echo '<td align="center" vertical-align="middle"><br><form action="changeclass.php" method="POST"><select>Balls</select><input type="submit" value="+""></form></td>'; } echo '</td><td align="center"><a href="delete.php?id='.$cid.'&type=child">[ - ]</a></td></tr>'; } } else {echo "No Students";} ?> <tr> </tr> </table> <table> <td> <input type = "submit" value="Switch Status"> </td> </table </div> <br> <a href="classroom.php">Go Back</a> </div> </div> I'm sure its vulnerable to SQL Injection, but remember this is just a rough draft. A draft to get my ideas out in code. Peace! And Thank You!
-
Im having a bit of trouble with my script. I wrote the script originaly to run from one variable which i changed manualy, but now im trying to put the whole script inside a loop. The script is now running all the way through fine on the first loop, starting starting the second but getting stuck at the part with my implode. This is my script that is around the implode area. Bear in mind that this code snippet is from a very large script. $t=1; while ($t <= $bm) { $mn=${'m'.$t}; $mn2[$t]="$mn"; $t++; } // The is where the script runs to, and the error comes from the next few lines and the script stops running $implode=implode(',', $mn2); print $implode; $query2="SELECT * FROM artists WHERE id IN(".implode(',', $mn2).")"; $result2=mysql_query($query2) or die(mysql_error()); $i=0; $bm2=$bm-1; while ($i <= $bm2) { $id3=mysql_result($result2,$i,"id"); ${"id3$i"} = $id3; $s1=mysql_result($result2,$i,"s1"); ${"s1$i"} = $s1; $s2=mysql_result($result2,$i,"s2"); ${"s2$i"} = $s2; $sl1=mysql_result($result2,$i,"sl1"); ${"sl1$i"} = $sl1; $sl2=mysql_result($result2,$i,"sl2"); ${"sl2$i"} = $sl2; $i++; } And this is the error that im getting ,,,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 help or point in the right direction would be amazing right no. Thanks Eric
-
Hi everyone I would like to know if anyone has ever successfully been able to display a TinyMCE editor in a while loop? It only displays the first loop, and not the second while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo '<form method="post" style="margin-top:20px;"><table> <tr> <td>Content Name</td> <td><input type="hidden" name="idwidget" value="'.$row["id"].'" /><input type="text" name="name" value="'.$row["content_name"].'" /></td> </tr> <tr> <td>Content</td> <td><textarea id="mcecontent" class="mcecontent" name="mcecontent" rows="15" cols="80">'.$row["content"].'</textarea></td> </tr> <tr> <td>Active</td> <td>'; if($row["active"] == "1"){ echo '<input type="checkbox" name="active" checked="checked" />'; } else { echo '<input type="checkbox" name="active" />'; } echo '</td> </tr> </table>'; } It is suppose to display for mcecontent textarea.
-
I posted something similar to this recently but the variable isn't defined, as it was in the last one. I have two tables. The 'user' table contains the id, first name, and last name of the individual. The 'uinfo' table contains other pertinent info about the user. I want the code to look at the 'uinfo' table where reviewed = 0 and gather all of the ID's (uid) of those members. Then, based off of those ID's I want it to gather their names from the other table and list them so I can click on them. I'm just not quite sure how to do that. :-\ $sql="SELECT uid FROM uinfo WHERE reviewed='0'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)) { $uid = $row['uid']; $sql="SELECT FirstName, LastName FROM users WHERE id='$uid'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)) { $admin = $row['admin']; $FirstName = $row['FirstName']; $LastName = $row['LastName']; echo "<br><a href='blah.php?id=" . $uid . "'>" . $FirstName . " " . $LastName; } }
-
Hello everyone. i'm new on this site and also new on PHP coding. I want to make a loop using the values of an object (name of the object is test). my object has categoryid,parentid and i want to make something like this forearch(categoryid){ foreach(parentid){ if (parentid == categoryid){ do something } } } Can anyone help me to do this loop? Thank you
-
What I need to do is query a table based on a date. Then, if the query returns a "W" or an "H", I need to add one day to the date, then run the query again, until it doesn't return either a "W" or an "H". My code works fine when the initial query doesn't return a W or H, but when it does, it times out, seemingly in and endless loop. So clearly, something I'm doing with the loop isn't correct. Can someone help with my logic? Thanks very much from this first time visitor to PHP Freaks! Here's the code: <? $testdate = date("Y-m-d", strtotime("2012/09/30")); include("includes/databasedateretrieval.inc"); $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; // Check for dating errors while ($dfresult == "W" || $dfresult == "H"){ //convert the date to time $todaydate = strtotime($testdate); //add 1 day to the date $todaydate = $todaydate + (24*60*60); //convert the date back to a format compatible with the table data $testdate = date("Y-m-d", $todaydate); //here I'm querying the table again to see if the new date returns a W or H $dateverify = mysql_result($date_result,0,"1_day"); $dfresult = $dateverify; } ?> <? echo $testdate; ?>
-
Hi everyone, I am facing a problem with the following code snippet which invovles inserting data from a csv file into a mysql table. <?php if(isset($_POST['submit'])) { $file = $_POST['filepath']; $handle = fopen($file,"r"); $fileop = fgetcsv($handle,2000,","); //read only headers (first row) // build qry to select data from assessment,assessmenttype tables $qry = "SELECT assessmenttype.AssessType_Code, Assess_Num FROM assessment, assessmenttype WHERE assessmenttype.AssessType_Code = assessment.AssessType_Code AND Offer_ID = '$offerId';"; // execute query $result = mysql_query($qry) or die('Query failed: ' . mysql_error()); $c = 1; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $index = $_POST["lstAssess$c"]; $assessNum = $row['Assess_Num']; $assessCode = $row['AssessType_Code']; echo $assessCode." ".$assessNum." ".$fileop[$index]; $i = 1; while((${"fileop$i"} = fgetcsv($handle,10000,",")) !== false) { echo ${"fileop$i"}[$index]; /* $Stud_Lname = $fileop[0]; $Stud_Fname = $fileop[1]; $Stud_Id = $fileop[2]; $mark = $fileop[$index]; $qry = mysql_query("INSERT INTO gradebook (Stud_ID,Offer_ID,Assess_Num,AssessType_Code,GB_Mark) VALUES ('$Stud_Id','$offerId','$assessNum','$assessCode','$mark')")or die('Query failed: ' . mysql_error());*/ echo "<br>"; $i = $i + 1; } //echo $fileop[$index]; $c = $c + 1; } }else { echo "Error!"; } //close database connection mysql_close($conn); ?> As expected, each outer loop run should generate every inner loop run. This is not the case here. Only the first loop is successful and gets inserted into the DB. Can anyone point me to directions where I can tackle this issue?? Thanks in advance.
-
Hello I need to find a way to close loop outside if condition like below example if(escape($_POST['jobCategory']) != "all-categories" && escape($_POST['countryId']) == "all-countries"): $query = mysqli_query($dbConnection,"SELECT jobs.id, jobs.job_title, jobs.salary, jobs.employer_id, employers.employer_name, employers.employer_logo FROM jobs LEFT JOIN employers ON jobs.employer_id = employers.employer_id WHERE job_status = '".mysqli_real_escape_string($dbConnection,'Active')."' AND id IN (".mysqli_real_escape_string($dbConnection,$job_id_imploded).") "); while($row = mysqli_fetch_assoc($query)){ // Start Loop $job_id = $row['id']; $job_title = $row['job_title']; endif; <div class="job-title"> <a href="job_post.php?job_id=<?php echo htmlspecialchars($job_id) ?>" class="job-title-link"><?php echo htmlspecialchars($job_title); ?></a> </div> } // End Of Loop Gives me error HTTP ERROR 500