Simple Query viewer

Simple Query viewer

am 06.02.2006 20:16:36 von UKuser

Hi Guys,

Does anybody know where I can get a very basic view/add/edit script for
a single table/query? I need to view all the rows at the same time and
be able to edit from that point.

I have 4 fields called id, lowerval, upperval, result. Table is called
fig_lookup. I am very new indeed to mysql, so if you know of any basic
code which would suffice, or could post some that would be brill.

I am not after an advanced browser, as I want to be able to give users
the options to edit specific fields which I decide rather than complete
database control.

Thanks

Re: Simple Query viewer

am 06.02.2006 20:18:41 von xclarky

Have you looked into phpMyAdmin? It's a very popular script for
maintaining databases through a web interface.

Re: Simple Query viewer

am 06.02.2006 20:22:25 von UKuser

Yes thanks. Its good for Administrators, but I want to give users
access to just one table in a nice easy to edit format. For example
they can tick a box to edit a specific row, but with very basic
scripting which I can actually edit. I'm talking the grass roots of
MySQL so I can learn from it. I have played with PHPmyadmin but I need
something more customisable and less code.

Thanks

Re: Simple Query viewer

am 06.02.2006 20:45:01 von UKuser

For a further example, I have some example code in a book (part of the
full code):

if (isset($left))
{
query = "SELECT id, name, email FROM addressbook WHERE id < $id " .
"ORDER BY id DESC";
$result = mysql_query($query);
check_mysql();
$row = mysql_fetch_row($result);
check_mysql();
if ($row[0] > 0)
{
$id = $row[0];
$name = $row[1];
$email = $row[2];
}
}

Problem is, this code means you have to scroll through each record.
What I would like is for all the results to be displayed and editable.
Therefore you rather than just having value="\php bits $name"> it would display lots of rows depending on the
query results.

Thanks

Re: Simple Query viewer

am 07.02.2006 10:14:09 von pjSoni

Hi,

There are 2 ways 2 do this.

First of all make listing scrren which display all records in page than
do 1 of the following

1. If you need all the records editable at same time.
Make edit button or link when you click on that it should display all
there records with text boxes and bottom of the page save button
displayed when you click all the records will be updated.

2. If you need only 1 records editable.
Make edit link in each row when you click on single records edit link
it should reload and only clicked recod should hold textboxes in only
single row not for all records.
When click on link after updating than it should updated in db.

As per my understanding about you requirement above are good solutions.

Regards,
Jatin

Re: Simple Query viewer

am 07.02.2006 13:01:11 von ohaldi

In article <1139253396.597888.183740@g14g2000cwa.googlegroups.com>,
UKuser wrote:
> Does anybody know where I can get a very basic view/add/edit script for
> a single table/query? I need to view all the rows at the same time and
> be able to edit from that point.
>
I'm new in PHP but perhaps that can help you.
Have a look at http://www.haldi.ch/her/ at the third icon!

You have to clean those scripts!

If it's OK here the script:
SCRIPT LIST
***********
require_once('config.php');
require_once('fonctions.php');

// Appelle l'affichage de la toolbar
require("toolbar.php");

// Affiche un message en dessous du toolbar
Mes('Famille','','400');

// Configure le script en suisse
setlocale (LC_ALL, 'nl_CH');

// Connection à la base de données
$db_link = openDatabase($db_hostname, $db_username, $db_password,
$db_name);

// Tri seleon la colonne
if ($sf == 2) {
$requete = "select ID, Date_Format(DATE_ENR,'%d.%m.%Y') AS DATE_ENR,
FAMILLE from famille order by date_enr";
} elseif ($sf == 3) {
$requete = "select ID, Date_Format(DATE_ENR,'%d.%m.%Y') AS DATE_ENR,
FAMILLE from famille order by famille";
} else {
// On lance la requête SQL standard
$requete = "select ID, Date_Format(DATE_ENR,'%d.%m.%Y') AS DATE_ENR,
FAMILLE from famille";
}

$resulta = mysql_query($requete) or die (mysql_error());

// Définition de la page pour l'affichage
echo '

style="border-collapse: collapse" bordercolor="#ECE9D8" width="100%">';

// Icone en début de ligne pour l'édition de la fiche
$edit = " alt='Affiche la fiche'>";

TopBox('400','#F0F0F0');
echo "
";
echo "";
echo "";
echo "";
echo "";

// on boucle pour afficher les lignes du tableau resulta
$cline = 1;
$fline = 1;
while ($ligne = mysql_fetch_array($resulta, MYSQL_ASSOC))
{
// Couleur d'affichage pour la première ligne
$ID = $ligne["ID"];

if ($fline == 1)
{
$fline = 0;
$clinec = "";
// Affichage en début de ligne le link pour la visualisation ou
l'édition
echo ("\n");

// Affichage des champs sur une ligne
echo $clinec.$ligne["ID"]."";
echo $clinec.$ligne["DATE_ENR"]."";
echo $clinec.$ligne["FAMILLE"]."";
}
echo "";
echo "
IDDateFamille ";
}

// ping pong pour afficher les lignes d'une couleur différentes
if ($cline == 1)
{
$cline = 0;
$clinec = "
";
}
else
{
$cline = 1;
$clinec = "
";
}

echo "
HREF=\"famille_edit.php?id=$ID\">$edit
";
BottomBox();
?>


SCRIPT EDIT:
************
require('config.php');
require('fonctions.php');
require("toolbar.php");

// Connection à la base de données
$db_link = openDatabase($db_hostname, $db_username, $db_password,
$db_name);

$mes = "Mode de modification!";

// Exécute la condition si le script est rechargé par le bouton ajouter
un enregistrement!
if($mode == "new")
{
$mes = "Nouvel enregistrement!";
$dtm = strftime("%Y-%m-%d %H:%M:00");
$query = "INSERT INTO famille (DATE_ENR, FAMILLE) VALUES ('$dtm', ''
)";
$req = mysql_query($query);
$id = mysql_insert_id();
}

if($mode == "Enregistrer")
{
$mode = "";
$mes = "Fiche modifiée et enregistrée!";
$id = $last_id;

// on regroupe la date avant l'update
$date_enr = "$aa-$mm-$jj 00:00:00";

// Enregistrement des modifications
$query = "UPDATE famille SET ID='$id', DATE_ENR ='$date_enr', FAMILLE
='$famille' WHERE ID=$id";
$req = mysql_query($query);

if (!$req)
{
echo "Error ".mysql_errno()." : ".mysql_error()."";
exit;
}
$aff_rows = mysql_affected_rows();
}

if($mode == "Effacer")
{
$mode = "";
$id = DeleteEnr($last_id, $famille);

// Efface l'enregistrement
$query = "DELETE FROM famille WHERE ID=$id";
$req = mysql_query($query);

if (!$req)
{
echo "Error ".mysql_errno()." : ".mysql_error()."";
exit;
}
}

// Contrôle si le paramètre (id de la fiche) est bien passé
if ($ID && !$id){$id = $ID;}
// Si la valeur de l'id n'est pas définie alors on charge la ficher No. 1
// if (!$id){$id=1;}

// Query sur l'enregistrement selon l'ID
$query = "SELECT DATE_ENR, FAMILLE FROM famille WHERE ID=$id";
$req = mysql_query($query);
$res = mysql_num_rows($req);

if ($res == 0)
{ exit(); }
else
{
$row = mysql_fetch_array($req);
extract($row);

// on découpe la date pour l'affichage
$jj = substr($DATE_ENR,8,2);
$mm = substr($DATE_ENR,5,2);
$aa = substr($DATE_ENR,0,4);

// Formulaire pour la mutations des données
?>
'>

// Affiche la partie supérieur d'un cadre avec ombre
TopBox('400','#F0F0F0');
?>

bgcolor='#ECE9D8' style='border-collapse: collapse'
bordercolor='#111111'>















FICHIER:
Famille, ID:

Date: size='2'>
size='2'>
size='4'>
Famille:

  ?>



// Affiche la partie inférieur d'un cadre avec ombre
BottomBox('400','#F0F0F0');
?>







}
?>

Re: Simple Query viewer

am 07.02.2006 23:06:21 von UKuser

That is superb. Its just what I'm looking for.

Are you the author? I have sent the author an email asking about
Copyrights, as I'd like to use the code in a commercial environment
(not selling the script, just to access one of our databases).

I was also thinking that with some adapting, the code could be
converted into a spreadsheet, which creates code automatically
dependent on what fields you want. It would make MySQL alot easier to
use, and quite a handy little tool.

Re: Simple Query viewer

am 08.02.2006 12:49:52 von ohaldi

> That is superb. Its just what I'm looking for.
>
Thanks

> Are you the author?
>
Yes

> I have sent the author an email asking about
> Copyrights, as I'd like to use the code in a commercial environment
> (not selling the script, just to access one of our databases).
>
You can have the source, but I'm a beginner in programming, I did this
program only for myself and to learn PHP / HTML.

Re: Simple Query viewer

am 23.02.2006 12:23:30 von Jim Michaels

"pjSoni" wrote in message
news:1139303648.965260.196100@o13g2000cwo.googlegroups.com.. .
> Hi,
>
> There are 2 ways 2 do this.
>
> First of all make listing scrren which display all records in page than
> do 1 of the following
>
> 1. If you need all the records editable at same time.
> Make edit button or link when you click on that it should display all
> there records with text boxes and bottom of the page save button
> displayed when you click all the records will be updated.
>

I implemented mine so each row has its own form with its own delete/change
button. There was also an Add form at the top. I did this because with so
many users, you can't guarantee that all those records you displayed will
stay the same or still be there - can you? are you going to do a mass
insert/update? I wouldn't. And at least this way your fields will be a
little more up-to-date on the next page refresh.



> 2. If you need only 1 records editable.
> Make edit link in each row when you click on single records edit link
> it should reload and only clicked recod should hold textboxes in only
> single row not for all records.
> When click on link after updating than it should updated in db.
>
> As per my understanding about you requirement above are good solutions.
>
> Regards,
> Jatin
>