...

View Full Version : Array Manipulation



Salchester
06-28-2007, 07:07 PM
Hiya Everyone,

Using the following code, how do I load all information from the database into an array ($records), and display each record on screen with it's own delete button.

Then when a delete button is clicked, all records NOT including the record that had the button clicked should get copied into a separate array ($temp).

Then all record from the $temp array should get copied into the database, overwriting everything that was there previously.


<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("WB", $con);

$result = mysql_query("SELECT * FROM Birds");

if(mysql_error() != 0 || mysql_num_rows($result) == 0)
{
die("No database, or no data");
}

$records = array();
while($row = mysql_fetch_object($result))
{
array_push($records, $row);
}

// Loop the following code

echo $records[0]->Name;
echo $records[0]->Species;
echo $records[0]->Sex;
?> How can this be done?

Is there anyway of using a loop and a counter variable to display all the records, instead of manual declaring the "Numeric Array Store" value etc.

Many Thanks,

zenriot
06-28-2007, 09:31 PM
Why don't you just delete the record that you pressed the button to delete in the first place?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum