PHP - Delete Loop Not Working
I am trying to delete records across 3 tables but my code does not work.
Code: [Select] $query = ("SELECT `propertyref` FROM `feed_property` WHERE `status` = 'Sold' ")or die(mysql_error()); $result = mysql_query($query); if (isset($result)) { while ($row = mysql_fetch_array($result)): $ref1 = mysql_real_escape_string($row['propertyref']); $query1 = ("DELETE FROM `feed_property`, `feed_images`, `feed_characteristics`\n" . "USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics`\n" . "WHERE feed_property.propertyref = '$ref1'\n" . " AND feed_images.propertyref = feed_property.propertyref\n" . " AND feed_characteristics.propertyref = feed_property.propertyref; ")or die(mysql_error()); echo $query1; endwhile; if(!mysql_query($query1)){ echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>'; } else { echo '<h1 style="color: red;">Properties have been removed from the database</h1>'; } } Query1 echos as: Code: [Select] DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc1' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc2' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; The query completes without errors but does not delete the entries in the DB. If I run the query singly in PHP My Admin it functions correctly. thanks for your help Similar Tutorials <body> <?php include 'sql.php'; $query = "SELECT * FROM validation"; $result = mysqli_query($con , $query); $rows = mysqli_fetch_assoc($result) ; $totals = mysqli_num_rows($result) ; ?> <div id="css"> <form > <table width="80%" border="0" cellpadding="2" cellspacing="2" > <caption><h2>Personal Details of Customers</h2></caption> <tr class="white"> <td bgcolor="#330033"> </td> <td bgcolor="#330033"> Id Number </td> <td bgcolor="#330033"> Full Name </td> <td bgcolor="#330033"> Email Address </td> <td bgcolor="#330033"> Website </td> <td bgcolor="#330033"> Comment </td> <td bgcolor="#330033"> Time </td> </tr> <?php while($rows=mysqli_fetch_assoc($result) { <tr> <input type="raido" name="ID" value="<?php echo $rows['ID']; ?>" /> <td bgcolor="#FFFFCC"><?php echo $rows['ID'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Name'];?> </td> <td bgcolor="#FFFFCC"><?php echo $rows['Email'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Website'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Comment'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Time'];?></td> <td> </td> <td> <a href="delete.php? ID= "$rows[ID]" /"> <input type="submit" name="del" value="Delete" /> </a> <input type="button" name= "edit" value="Edit" /> </td> </tr> }?> </table> </form> </div> </body> i have a while loop that builds up a table of records, each row has a button that needs to have an action to delete that specific record. I can think of the obvious way around this and add a form around each row and set the button to type="submit". However there is a problem i have the entire table of records wrapped within in a form object for other functionalities. Does anyone have a solution for this problem? I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners Hi I am struggling with my last page for a project it is a delete page that retrieves data from a list, asks the user if he wants to delete that record if 'yes' delete it otherwise redirect to another page. My page looks like it should, but the function is not working. my code is: Code: [Select] <?php //check to see if user is logged on session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != "")) { header ("Location:login.php"); } include('connect.php'); //connection details to database in a connect.php page //if form was submitted if (isset($_REQUEST['yes'])){ $product_id = $_GET['product_id']; $productname = $_POST['pname']; $range = $_POST['prange']; $price1 = $_POST['pprice']; $price = (int)$price1; $query = "DELETE FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); print "<br> $productname from range $range with a price of R$price has been deleted!</br>"; } } if (isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = "SELECT * FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); echo "<form method = \"post\" action = \"delete.php\">"; while($row = mysql_fetch_array($result)){ echo "<table>"; echo "<tr>"; echo "<td><input name = 'product_id' type = 'hidden' value ='{$row['product_id']}'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Do you really want to delete {$row['product_name']} from range {$row['product_range']} with a price of R{$row['product_price']} from the database?</td>"; echo "</tr>"; echo "<tr>"; echo "<td<input type = 'submit' name = 'yes' value = 'Yes'><input type = 'submit' name = 'no' value = 'NO'></td>"; echo "</tr>"; echo "</table>"; } echo "</form>"; } ?> Any help please? Hi all, this is probably the easiest thing and I may have just been staring at the screen for too long but one of my DELETE FROM queries isn't working. I created a cart and in the admin area when an admin deletes the product it is supposed to delete it from the 'Products' table and also all the sizes from the 'Sizes_List' table. Right now it is only being deleted from the Products table and not the Sizes_List table.. here is the snippet.. any help would be greatly appreciated. Code: [Select] if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $deletefrom_sizes = mysql_query("DELETE FROM Sizes_List WHERE product_id = '$id_to_delete'"); $sql = mysql_query("DELETE FROM Products WHERE product_id='$id_to_delete' LIMIT 1"); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../user/rent/inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: addproduct.php"); exit(); } I'm working on an existing project, it's a mess but for the moment I just have to get the delete function working, but keep getting an error and I'm not sure what I'm missing. The query string is a mess, but that's a headache for another day. The target shouldn't ge part of the query string, but that's how someone else had set it up so for now I'm stuck trying to work with it as it is currently and just have to get some basic CRUD functionality going. The other minor snag is inconsistencies with the name of the primary key between tables. It's not consistently called 'ID" so I need to get both the key and value for the where part of the DELETE statement. The query that I currently have is not working. Error 500, can't even get a simple var_dump to work.
Query string as it is in its present state: Quotesomewbsite.com/endpoints/delete.php?target=TABLENAME&primaryKey=7 <?php include('includes/config.php'); $table = $_GET['target']; parse_str($_SERVER['QUERY_STRING'], $data); array_shift($data); $cols = array_keys($data); $vals = array_values($data); $idType = $cols[0]; $id = $vals[0]; $stmt = $pdo->prepare("DELETE FROM SOME_DATABASE.$table WHERE $idType = '$id';"); $status = $stmt->execute(); if($status) { echo "Success"; } else { echo "Fail"; } ?>
<?php $db = new PDO('mysql:host=localhost;dbname=wordpress', 'root',''); //---------prepare $delete3 = $db->prepare("DELETE FROM wp_term_relationships WHERE object_id=:id"); $delete2 = $db->prepare("DELETE FROM wp_posts WHERE ID=:id"); $delete = $db->prepare("DELETE FROM wp_postmeta WHERE post_id=:id"); $select = $db->prepare("SELECT post_id FROM reference WHERE x_id=?"); $delete->bindValue(':id', $id, PDO::PARAM_STR); $delete2->bindValue(':id', $id, PDO::PARAM_STR); $delete3->bindValue(':id', $id, PDO::PARAM_STR); //---------- echo 'conected-----'; { $delfeed = '';} $array = explode(',',$delfeed); foreach($array as $deadman){ $select->execute(array($deadman)); $row = $select->Fetch(PDO::FETCH_ASSOC); $id = $row['post_id']; if ($id == null){} else { echo "$id"."\n"; $delete->execute(); $delete2->execute(); $delete3->execute(); } $id++; } echo 'done!'; ?>its a simple delete script but it doesnt delete, it does print the right $id's witch means is working till there but delete goes bananas,double checked table names ,colums... tryied working with question mark place holders insted of bind parameter but nothing connection is fine .. can read records .. but can't delete ... any ideas.. Code: [Select] <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Mod edit: [code] . . . [/code] tags added. I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. Okay I am trying to do a for loop within a while loop and its so far not working. Here is what I currently have. It echo's nothing out. Also If I remove the Code that generates information from the for loop It echo's out perfectly so It has something to do with the for loop. PHP Code so Far: Code: [Select] <?php if(isset($_POST['system'])){ $system = $_GET['system']; }else{ $system = 1; } $q = "SELECT * FROM `planets` WHERE `system` = '$system' ORDER BY `id` ASC LIMIT 9"; $res = mysql_query($q) or die("Error:<br />".mysql_error()); $couny = mysql_num_rows($res); while($row = mysql_fetch_array($res)){ for($i=1; $i>=$couny; $i++){ ?> <li> <span <?php if($i=1){echo "id='mercury'";} if($i=2){echo "id='venus'";} else if($i=3){echo "id='earth'";} else if($i=4){echo "id='mars'";} else if($i=5){echo "id='jupiter'";} else if($i=6){echo "id='saturn'";} else if($i=7){echo "id='uranus'";} else if($i=8){echo "id='neptune'";} else if($i=9){echo "id='pluto'";}?>id="mercury"><?php echo $row['name']; ?></span> <p><?php if($colony['building11'] >= $row['building11']){?> This Colony Currently Has the Following:<br /> Hydrogen: <?php echo num($row['recource1']); ?><br /> Gold: <?php echo num($row['recource1']); ?><br /> Platinum: <?php echo num($row['recource1']); ?><br /> Silver: <?php echo num($row['recource1']); ?><br /> Bio-Waiste: <?php echo num($row['recource1']); ?><br /> Plasma: <?php echo num($row['recource1']); ?><br /> Metal: <?php echo num($row['recource1']); ?><br /> <?php }else{?> <font color="red">Insufficiant Observatory Level!</font><br /> Hydrogen: ???????????????<br /> Gold: ???????????????<br /> Platinum: ???????????????<br /> Silver: ???????????????<br /> Bio-Waiste: ???????????????<br /> Plasma: ???????????????<br /> Metal: ???????????????<br /> <?php } ?></p> </li> <?php } } ?> Thanks Brian. PS. The Attached Image is what it looks on my end the for and while loops displays the planets in the system right under the red Solar System Star Text. Thank you again for any help. It's only displaying the first result and not the others. What am I doing wrong? I'm selecting the items the user occupies. Then I'm selecting the name and image of that item from the item table. Code: [Select] echo "<table cellspacing=\"0\" class=\"news\" align=\"center\">"; echo "<tr>"; $sql = "SELECT * FROM useritems WHERE userid='".$_SESSION['userid']."' LIMIT $offset, $rowsperpage"; //selects all the users items to whoever is logged in $result = mysqli_query($cxn,$sql) or die(mysqli_erro($cxn)); $imagecount = 0; while ($row = mysqli_fetch_assoc($result)) //while there are still results { extract($row); $quantity = $row['quantity']; $itemid = $row['itemid']; $sql = "SELECT * FROM items WHERE itemid='".$itemid."'"; //selecting the name and image of the item that is displaying $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $row = mysqli_fetch_assoc($result); $name = $row['name']; $image = $row['image']; if ($imagecount%5 == 0) //after 5 items have been listed, start a new line { echo "</tr>"; echo "<tr>"; } } echo "<td width=\"120px\" align=\"center\">"; echo "<img src=\"http://www.elvonica.com/".$image."\"><br>"; echo $name." (".$quantity.")"; echo "</td>"; $imagecount++; //after one item has been displayed, redo the loop if there are still results } echo "</table>"; Can anyone help me with why this code would only send 1 email when the query returns 8 rows?
I am pretty sure it will be simple but I can't find the problem!
$sql = "SELECT email, supplier_id FROM tbl_suppliers"; $stmt = $db->prepare($sql); $stmt->execute(); foreach($db->query($sql) as $row){ $supp_id = $row['supplier_id']; $emailCSV->setEmailMessage("some generic text message"); $email = $row['email']; $emailCSV->sendEmail("me@me.com",$email,"Quote Request"); } Hello everyone! I am trying to pull from mysql a row of first names in a while loop but I keep getting the error message Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in line 52 The code is; <?php $first_name = $_POST['firstname']; $last_name = $_POST['lastname']; $full_name = $_POST['firstname'] . ' ' . $_POST['lastname']; require_once ('swdb_connect.php'); $query = "INSERT INTO description(firstname, lastname) VALUES ('$first_name', '$last_name')"; $result = @mysql_query ($query); while($row = mysqli_fetch_array($result)) { echo $row['firstame'] . '<br />'; ?> I don't understand why I get the error message, I have over 20 names in mysql If anyone can help that would be great Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. I am a noob at php, looking to become great. My php loop only seems to draw 1 row from the database when listing it out. Here is the loop <?php require('header.php'); mysql_select_db('center'); $sql = "select username, password from users"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $user = $row['username']; $pass = $row['password']; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>$user</td>"; echo "<td>$pass</td>"; echo "</tr>"; } echo "</table>"; ?> Hello all, I am having trouble with a piece of code. I have used the same piece of code on a different server and I had no problems. Suddenly I do. - I use this code to load info into a Flash website to browse through all rows in a table; - Inside the table currently there is one record; - NumLow is being passed through the url; - echo "&aantalEvenementen=".$aantalEvenementen; shows 1 record just fine; - the record doesn't get printed though... the error is somewhere in the while loop. Hope someone can point me in the right direction! Cheers, Code: [Select] // Connect to mySQL Server $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error bij het verbinden met de MYSQL server: " . mysql_error()); // Select mySQL Database mysql_select_db($DBName, $DBConn) or die("Error bij het verbinden met de MYSQL database: " . mysql_error()); //amount of rows that are shown at once $numComments = 1; //select the right table $sql = "SELECT * FROM $table"; //loading events $nieuweEvenementen = mysql_query($sql, $DBConn) or die("Error bij het ophalen van de concerten: " . mysql_error()); //amount of rows $aantalEvenementen = mysql_num_rows($nieuweEvenementen); //order rows $sql .= ' ORDER BY `concertDatum` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments; //loaded row $geladenEvenement = mysql_query($sql, $DBConn) or die("Error bij het laden van het concert: " . mysql_error()); //echo amount of rows echo "&aantalEvenementen=".$aantalEvenementen; //if no records, display message, otherwise print row if($aantalEvenementen == 0) { echo "&concertOmschrijving=Er zijn geen concerten. U kunt nieuwe concerten aanmaken via de concertenkalender."; } else { while ($array = mysql_fetch_array($geladenEvenement)) { $concertNaam = mysql_result($geladenEvenement, $i, 'concertNaam'); $concertArtiest = mysql_result($geladenEvenement, $i, 'concertArtiest'); $concertDatum = mysql_result($geladenEvenement, $i, 'concertDatum'); $concertTijd = mysql_result($geladenEvenement, $i, 'concertTijd'); $concertOpen = mysql_result($geladenEvenement, $i, 'concertOpen'); $concertOmschrijving = mysql_result($geladenEvenement, $i, 'concertOmschrijving'); echo "&concertNaam=".$concertNaam; echo "&concertArtiest=".$concertArtiest; echo "&concertDatum=".$concertDatum; echo "&concertTijd=".$concertTijd; echo "&concertOpen=".$concertOpen; echo "&concertOmschrijving=".$concertOmschrijving; $i++; } } // if there are no more records (all are loaded), show message if($_GET['NumLow'] > $aantalEvenementen) { echo "$eventOmschrijving=Alle concerten zijn reeds geladen."; } } hello.. In this script. if part is working properly. but elseif part not working i expect. it display only 1 category and its subjects. Anybody can tell me what the mistake that I have did... Here is my script Code: [Select] } elseif ( isset($_POST['category']) && ( sizeof( $_POST['category']) == 2 || sizeof( $_POST['category']) == 3 )) { $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { foreach( $category as $value ) { if ( $value == $row['category_id']) { echo '<input type="radio" name="category[]" value="' . $row['category_id'] . '" class="radio" />'; echo '<label for="" class="radio"> ' . $row['category_name'] . ' <strong>: Mark this category as my "Main Category"</strong></label><br />'; $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$row['category_id']}"; $r = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($info = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $info['subject_id'] . '" /> ' . $info['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } I have never used cURL before but I need to use it for developing a facebook application. What I am trying to do is create a status update scheduler. There are two tables in my database. One table has generic updates for each day of the week an the other had special events. My script checks the day, checks to see if there is a special event in the future on that day, and if there is reminds guests of the upcoming event. If there is no event it posts the generic status. Code: [Select] <?php include('config.php'); $result2 = mysql_query("select facebook_id,facebook_access_token from admin where username='users'"); $row = mysql_fetch_array($result2); $facebook_id = $row['facebook_id']; $facebook_access_token = $row['facebook_access_token']; $day = date('N'); $result2 = mysql_query("select * from events where date > CURDATE() order by date ASC") or die(mysql_error()); $num_rows = mysql_num_rows($result2); if($num_rows == 0) { $result2 = mysql_query("select * FROM alerts WHERE id='$day'") or die(mysql_error()); $row1 = mysql_fetch_array($result2); echo 'There are no events just alerts'; } else { while($row = mysql_fetch_array($result2)){ if(date('N',strtotime($row[date])) == $day) { $id = $row['id']; $result1 = mysql_query("SELECT * FROM events WHERE id = $id") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } else { $result1 = mysql_query("SELECT * FROM alerts WHERE id = $day") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } } } $params = array('access_token' => $facebook_access_token, 'message' => $row1[alert_message], 'name'=> $row1[alert_name], 'caption' => $row1[alert_caption], 'link' => $row1[alert_link], 'description' => $row1[alert_description], 'picture' => $row1[alert_picture] ); $url = "https://graph.facebook.com/$facebook_id/feed"; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => true )); $result = curl_exec($ch); ?> The problem seems to be occurring when the While loop is accessed. I have used 'echo' to follow the variables through the script and it all seems to be working. However if I try and execute the cURL and the While Loop has run then it does not seem to work. I know the cURL part works becuase if the variables cause the first IF statement default to ELSE then it runs fine. Any help would be GREATLY appreciated. This is a code pinch from a webpage of my project. Here I want to display user selected categories and then want to display its subjects that belong to category. There, users could have more than 1 category and It no problem I can print all those category in my first while loop... but problem is when Im try to print subjects it has only one row as a result.. there are more subjects in each category. can anybody tell me what has happens? this is my code.... Note: both queries are working properly.. I tried those user mysql client program. Code: [Select] <?php require_once ('../../includes/config.inc.php'); require_once( MYSQL1 ); $q = "SELECT institute_category.category_id, category_name FROM institute_category INNER JOIN category ON institute_category.category_id = category.category_id WHERE institute_category.institute_id = $instituteId"; $r = mysqli_query( $dbc, $q); while ( $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC) ) { $categoryId = $row['category_id']; $category = $row['category_name']; echo '<fieldset class="alt"> <legend><span>Category : <em style="color: red;">' . $category . '</em></span></legend>'; $qy = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = $categoryId"; $result = mysqli_query( $dbc, $qy); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($row = mysqli_fetch_array( $result, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="subject[]" value="' . $row['category_id'] . ":" . $category . ":" . $row['subject_id'] . ":". $row['subjects'] . '" /> ' . $row['subjects'] . '</td>' . "\n"; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } echo '</fieldset>'; ?> any comments are greatly appreciated.. thank you I have a while loop nested inside of another while loop to populate a drop-down select box for each result from the parent while loop. The inner loop only gets run once though... any ideas on how to fix this without it being extremely data heavy? |