|
 |
|
 |
 |
|
05-29-2007, 10:43 PM
|
#16 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Delete Records using an Array
SDE,
I mean the second record in the table, as being ID 2.
How do I delete the above record contents? (Name, Sex etc)
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
05-30-2007, 05:13 AM
|
#17 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
DELETE FROM table WHERE id=2
__________________

UT: Ultra-kill... God like!
|
|
|
05-30-2007, 07:44 AM
|
#18 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
this is why i asked earlier if you wrote that code. i don't know why are you even asking when the code you posted already does that.
__________________
testing 1 2 3
|
|
|
05-30-2007, 09:08 AM
|
#19 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Delete Records using an Array
SDE,
Sorry, I probably not explaining what I mean very well!!!!
Instead of using IDs to identify a record, can the code calculate the number of records contained in the table, and depending on which row the record is on, depends on its ID.
For example, if a record is on row 5, and the check box is ticked upon the delete button being clicked, then the code will automatically know that record 5 is required for deletion, as its on the 5th row.
So, basically the row, is the ID.
If the record required for deleting is on the second row, then the code should know you are obviously trying to delete record 2.
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
05-30-2007, 09:12 AM
|
#20 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
yes, but see post #2
the query to select the second record would look like this:
Code:
select * from table limit 2,1
but like i say in post 2, .. not a good idea since the second record could change depending on how many users are using the app.
just use IDs.. there is absolutely no valid reason not to.
__________________
testing 1 2 3
|
|
|
05-30-2007, 01:24 PM
|
#21 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
there's a valid reason: please screw up my database on purpose
Afterall that's the only thing you achieve with not having id's
__________________

UT: Ultra-kill... God like!
|
|
|
06-04-2007, 05:23 AM
|
#22 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Delete Records using an Array
SDE,
Can you explain how the following code works, to display a particular record, e.g. Record 3
Code:
$result = mysql_query("select count(*) from my_table");
$number_of_results = mysql_result($result, 0, 0);
* What do the numbers in BOLD do?
Many Thanks, in advance!!!
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-04-2007, 07:30 AM
|
#23 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
when you have a function name and need to know the details about it, another resource you really should use is PHP: Hypertext Preprocessor. it's very simple. just go there and type in the function name in the search.
check out the 'parameters' section of this page: PHP: mysql_result - Manual
mysql_result is just another way to get data from a result set. you could easily use mysql_fetch_array or something similar as well.
__________________
testing 1 2 3
|
|
|
06-04-2007, 07:51 AM
|
#24 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Delete Record using an Array
SDE,
I have got the following code working, only how do I display all the row's contents, not just one column of data on that one?
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Gallery", $con);
$result = mysql_query("SELECT * FROM Images");
$record = mysql_result($result, 0, 0);
echo $record;
mysql_close($con);
?>
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-04-2007, 08:34 AM
|
#25 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
it would probably be easier and less code for you to use mysql_fetch_assoc()
there's example on that page.
__________________
testing 1 2 3
|
|
|
06-04-2007, 11:18 AM
|
#26 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
SDE,
What need to be changed in order to get this work, i sort understand bits of it, but not all.
Code:
<?php
$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("mydbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT id as userid, fullname, userstatus
FROM sometable
WHERE userstatus = 1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
echo $row["userstatus"];
}
mysql_free_result($result);
?>
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-04-2007, 01:01 PM
|
#27 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
not enough info. i have no idea what you're trying to do, what you expect this to display, and what it's doing that you don't like. put some effort into it.
__________________
testing 1 2 3
|
|
|
06-05-2007, 11:32 AM
|
#28 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Delete Records using an Array
SDE,
At Present, I have a table containing the following fields:
Using a loop, is there anyway of calculating and outputting the 1st and 2nd records contained in the table, whilst adding a delete button to the end of each.
Many Thanks, in advance!!!
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-05-2007, 11:39 AM
|
#29 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
you're doing it in your code you posted above.. printing rows from the database in the while loop.
we've gone over the other part before if i recall... that goes back to the IDs issue.
__________________
testing 1 2 3
|
|
|
06-05-2007, 12:49 PM
|
#30 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Salchester are you realy understanding the replies?
To me it sounds you still can't even write a simple "hello world" or "goodbye universe" program and therefore this topic is over your head.
/me over and out for this topic
__________________

UT: Ultra-kill... God like!
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 04:55 PM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|