Jump to content


Photo

Hitting a problem with filtering out a delete procedure.


  • Please log in to reply
No replies to this topic

#1 opel

opel
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 15 October 2006 - 06:00 PM

I have been working on an admin system and using links and link categories as the basis for learning PHP and SQL. I've run into a problem with the links category delete pages.

What I want to do is filter out only categories that have no links assosciate with a category. Only these linkless categories can be deleted. The information for the links and categories are in 2 separate tables.

The SQL statement I have at the moment works perfectly for filtering out the categories that have no links assosciate with it. However as the statement is set up it displays a NULL value for the category_id therefor I have no value to pass to the delete confirm page and script.

This is the SQL statement and PHP Script I am working on at the moment. Can anyone tell me how I can get this script to work and pass out the correct category ID's please.


SQL
<?php
mysql_select_db($database_CMconn, $CMconn);
$query_rsLinkCatDelete = "SELECT DISTINCT categories.category_id, categories.category_name, categories.category_desc, tbl_links.category_id FROM categories LEFT JOIN tbl_links ON (categories.category_id = tbl_links.category_id)";
$rsLinkCatDelete = mysql_query($query_rsLinkCatDelete, $CMconn) or die(mysql_error());
$row_rsLinkCatDelete = mysql_fetch_assoc($rsLinkCatDelete);
$totalRows_rsLinkCatDelete = mysql_num_rows($rsLinkCatDelete);
?>

PHP
   <table>
<tr >
<th>Category</th>
<th>Delete </th>
</tr>

<?php do { ?>
  <tr>
    <?php if ($row_rsLinkCatDelete['category_id'] == 0) { // Show if recordset empty ?>
      <td class="item"><?php echo $row_rsLinkCatDelete['category_name']; ?></td>
      <td class="button"><a title="Delete This Item" href="linkCat_delete_detail.php?ID=<?php echo $row_rsLinkCatDelete['category_id']; ?>">Delete</a></td>
      <?php } // Show if recordset empty ?></tr>
  <?php } while ($row_rsLinkCatDelete = mysql_fetch_assoc($rsLinkCatDelete)); ?>

</table>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users