Jump to content

Hitting a problem with filtering out a delete procedure.


opel

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]
[code]<?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);
?>[/code]

[b]PHP[/b]
[code]  <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>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.