Jump to content

Help and explane please


EKsparky

Recommended Posts

I am still learning php I am currently building a little admin system for my websites

Problem I have at the moment which once I know the answer to will help me with many of my tasks is

Getting information form database so that I can do something with it

I learned about arrays and I think that’s what I need to accomplish this

 

Example if I get a list of users from my database I can echo a list of names to a the page but I want to be able to select one of them to say delete or modify

 

<?php
//select query
$sql = "SELECT user_id FROM tbl_auth_user";
//exec query
$dbname = mysql_query ( $sql );

while ( $row = mysql_fetch_array ( $dbname ) )
{

$users = (  $row["user_id"] );

echo '$users <BR />';
}
?>

 

 

So I guess I need to get user name of ID by selecting it in droop down list or radio buttons

Assign a var to it so I can then delete or modify or what ever

I have looked over other scripts but the ones I find are all very complicated and really any good for a beginner to decipher

And use.

 

Thanks for any help

 

 

Link to comment
https://forums.phpfreaks.com/topic/92904-help-and-explane-please/
Share on other sites

Right now you are only grabbing the user id, so I assume you would want to grab more, like their username as well.

 

Once you get the info, when you display it with your echo command, you also display a hyperlink similiar to something like

 

echo "<a href='mypage.php?deleteid=$userid'>$username</a>";

Then in your page, you use $_GET['deleteid']; and you can check for this, then take appropriate action.  You can do the same thing for a edit command.

that code wont work logically:

 

this is a logical example:

 

<?php
// assuming you have already connected to mysql

//select query
$sql = "SELECT user_id FROM tbl_auth_user";
//exec query
$dbname = mysql_query ( $sql );

while ( $row = mysql_fetch_array ( $dbname ) )
{

// $users will only equal the last "user_id", as it overwrites everytime while loops. notice [] in below example
$users[] = $row["user_id"]; // dont need brackets here.

echo $users.' <BR />'; // concatenated string, notice the dot ( . )
}
?>

 

-------

the code above will get every "user_id" for every row from "tbl_auth_user".

----

 

There are lots of tutorials for manipulating data from a mysql database, to modify or delete rows/tables or single data you would use some other mysql statements, eg:

 

DROP (TABLE | DATABASE) - to delete tables/databases.

CREATE (TABLE | DATABASE) - create tables/databases.

ALTER (TABLE | DATABASE) - Alter a table/database Structure.

 

UPDATE - to modify an existing row data.

DELETE FROM - to delete entire rows.

INSERT - Insert new Rows into a table.

SELECT - Retrieve all/specific data.

---------

obviously this is just a quick rundown, for more information on mysql queries and proper syntax visit:

http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html

 

for a quick tutorial on mysql integration into php visit:

http://www.weberdev.com/ViewArticle/Start-Using-MySQL

 

as i said there a lots of mysql tutorials that are explained in detail.

 

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.