Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 27th, 2004, 07:54 PM
shnackattack shnackattack is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 60 shnackattack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Can't delete a row

hi

The code displays data and lets me select a row with a checkbox to delete it.

My problem is that it won't display the first row and won't delete a selected row.

[highlight=php]
<?php
$connection = mysql_connect("localhost", "root", "");

mysql_select_db("whitg22");

function editnames()
{
$result = mysql_query("SELECT * FROM hits");

if (mysql_fetch_array($result) != 0)
{
echo "<table border=0>";

echo "<tr bgcolor=#cccccc>
<td align=center>Title</td>
<td align=center>Artist</td>
<td align=center>Year</td>
<td align=center>Genreid</td>
<td align=center>Chart Position</td>
<td align=center>Type</td>
<td align=center>Price</td>
<td align=center>Quantity</td>
<td align=center>Choose a Hit</td>
</tr>";

while ($row = mysql_fetch_array($result))
{
$title = $row['title'];
$artist = $row['artist'];
$year = $row['year'];
$genreid = $row['genreid'];
$chartposition = $row['chartposition'];
$type = $row['type'];
$price = $row['price'];
$quantity = $row['quantity'];

echo "<form method='post' action='edit.php'>
<tr>
<td align='center'><input type='text' name='title' value='" . $title . "' size='30' maxlength='30'></td>
<td align='center'><input type='text' name='artist' value='" . $artist . "'></td>
<td align='center'><input type='text' name='year' value='" . $year . "' size='4' maxlength='4'></td>
<td align='center'><input type='text' name='genreid' value='" . $genreid . "' size='5' maxlength='5'></td>
<td align='center'><input type='text' name='chartpostion' value='" . $chartposition . "' size='10' maxlength='10'></td>
<td align='center'><input type='text' name='type' value='" . $type . "' size='5' maxlength='5'></td>
<td align='center'><input type='text' name='price' value='" . $price . "' size='4' maxlength='4'></td>
<td align='center'><input type='text' name='quantity' value='" . $quantity . "' size='5' maxlength='5'></td>
<td align='center'><input type='checkbox' name='id' value='" . $title . "'></td></tr>";

}
echo "<tr><td><input type='submit' name='submit' value='Delete'></td></tr></table></form>";


}

else
{
echo "No records found!";
}
}

editnames();

if(isset($submit))
{
mysql_query("DELETE FROM hits WHERE title = $id");
echo $id;
}

?>
[highlight=php]

Reply With Quote
  #2  
Old March 27th, 2004, 08:18 PM
shnackattack shnackattack is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 60 shnackattack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Can't delete a row

i finally made it to delete a row, but still it displays all dta rows apart from the first one, it's as if it does not see it.

Reply With Quote
  #3  
Old March 27th, 2004, 09:35 PM
-vertigo- -vertigo- is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Louth, Lincolnshire
Posts: 314 -vertigo- User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 24 sec
Reputation Power: 2
RE: Can't delete a row

You need to change your 'while' loop to a 'do ... while' loop. The problem is that you fetch the first row in that 'if' statement, then that row gets discarded in the 'while' statement. That while loop displayes the data, but the first row is gone.

Reply With Quote
  #4  
Old March 28th, 2004, 12:20 PM
shnackattack shnackattack is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 60 shnackattack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Can't delete a row

Thanks vertigo, it works now

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Can't delete a row


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT