Jump to content


This topic is now archived and is closed to further replies.


Hitting a problem with filtering out a delete procedure.

Recommended Posts

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.

[b]SQL [/b]
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);

[code]  <table>
<tr >
<th>Delete </th>

<?php do { ?>
    <?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)); ?>


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.