Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-29-2007, 10:43 PM   #16 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 05-30-2007, 05:13 AM   #17 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
DELETE FROM table WHERE id=2
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 05-30-2007, 07:44 AM   #18 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 05-30-2007, 09:08 AM   #19 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 05-30-2007, 09:12 AM   #20 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 05-30-2007, 01:24 PM   #21 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
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!
DJMaze is offline   Reply With Quote
Old 06-04-2007, 05:23 AM   #22 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 06-04-2007, 07:30 AM   #23 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-04-2007, 07:51 AM   #24 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 06-04-2007, 08:34 AM   #25 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-04-2007, 11:18 AM   #26 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 06-04-2007, 01:01 PM   #27 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-05-2007, 11:32 AM   #28 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Delete Records using an Array

SDE,

At Present, I have a table containing the following fields:
  • Name
  • Species
  • Sex

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?
Salchester is offline   Reply With Quote
Old 06-05-2007, 11:39 AM   #29 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-05-2007, 12:49 PM   #30 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
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!
DJMaze is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with array Michael12 Java 3 05-01-2007 11:53 PM
creating 3-dimensional array nesvarbu Platform/API C++ 3 05-09-2006 07:01 AM
Sorting an array of any Comparable objects plague Java 1 03-14-2005 06:24 PM
Simple reverse programm silex Standard C, C++ 3 01-22-2005 08:03 AM
delete parts of an array Apodysophilia Java 4 05-07-2003 12:11 PM


All times are GMT -8. The time now is 04:55 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle