Creating new databases

Firstly folks, can i say how helpful people have been so far in getting me to this stage. I’m a total novice and friends on here have been great in helping me understand a little php.
So i have a very general question … I have a huge database of karaoke disc info DiscNo, TrackNo, Artist etc etc

I have so far got to the point where i can display a list of all the disks, then on clicking the disks display more details. What i want to do ultimately is be able to select whichever disks i want from the list and create a new list with all the disk detail on the list. So i am guessing at somestage first i need to create a new list by way of creating a new db or new table and then add my disks to it … is this the best way or is there any options that do not involve creating a db …

Thanks for any help.

You could make a new table or could you not add a new field and add which lists the discs are in ?

It depends how big the database is, the bigger the less stress you want to put on the server.
Also if you have to many fields in the same table is not so good as its having to search a lot of info.

Hmmm … i like the idea of the extra field, no idea at all how to do it but … the database is huge but the thing is there could be hundreds of new lists made … so which do you think would put less strain on the server ?

You would have to look at the structure and see how many fields are in the table then decide what to do.
I cannot make the judgement I have no idea how you database looks or the structure of it.

When you say huge 4 gigs or more ?

There are 5 fields in the table currently. Description, Artist, DiscNo, TrackNo, Title … It’s less than 500MB now but i guess in time it has the potential to increase to around 2Gig …

Thank you again for your help.

I thik you have all the info you need withthe disc details . so a field with the list it is identified in would just be needed.

field = track_list  
track_list_numbers = '1','4','12'

Then call the list 1 and get everything that is in the track_list 1 or in 12 they could be in more than 1 list then.

One further thought…

A database field can hold an array. If you have an array of lists that the disc is in, as Noodles mentioned, you can store that array into one field. To query for a list, you can select the database where the list field “CONTAINS” the list number. This should work for you. Once the contains query is completed, you can parse down thru the records and show all the disc’s it that list.

Did that make sense? Good luck…

Thank you both for your suggestions, but i think maybe i didnt make my self clear or i am missunderstanding what you are saying now …

I want my users to be able to create lists on the fly … and then add whichever discs to the lists and come back and add more discs to their lists as i add new discs to the master database.

Do i make sense ?

Yes, that makes sense! And, no, you did not explain that before…

So… In that case, you must have a table with all of your lists in it. You would have to have something like this for fields: UserName, ListName, DiscsInList … Or something like that. Then, when a user is logged in, they can select a list that they previously made ones or create a new list. Then, with that old or new list selected and displayed, they can select disc’s to add or remove in the list they are currently using. You would have to query the table using their UserName or UserID and that would give you all of their list names. Then, once they selected a previous list or new list, you would requery and pull the list of disc’s in that one list. Not very complicated, but when you get into it, we are here to help…

Yes thats exactly what i need to do … now where to start … I am a complete novice but i will see how far i can get and then post my code here for assistance … thank you again peeps.

Well, since you did not really post much code and you asked where to start, I will give you a quick, off the top of my head, step by step… As you get each section done or if you have problems, then, let us know and one of the members here will help…

So, first item is always the database. You need to make a list on paper, or as on your computer.
Think of everything you want this project to do and then, look at the list and see what actual data you
will need. As in our discussion, you will need a table for members or users. Create that table including
a userid and password system. You will need the table of disc’s that you now have, sounds like that one
is already completed. And, you will need a table of lists that will include the userid, list name and items in
the list. Maybe there is more data that you may want there. (Up to you!)

Next, create some sort of log-in so that the user only see his items or lists. This involves entering a userid
or email address and a password. There are thousands of tutorials on this in Google… Just search with a
phrase like “php code log in page tutorial” and you will find tons!

Then, create a way to allow for the creation of new lists once a user has logged in. This is needed so that
you can start creating a list. Also, if there is zero lists found for a user, it should go directly to the new-list
section. If 1 or more lists are found, they should be loaded into a drop-down (SELECT clause) so that the
user can select one of them or press the new-list button.

Well, there are some more thoughts on how to get started… We will be looking forward to your progress…
Good luck…

Thank you for your direction … it is a great help to know the terminology so i can google and find examples, at the end of the day i want to learn from this, so trying to fight my way through initially is important. But also nice to know that i have such an amazing support network. Gonna get cracking on this tomorrow (UK) … Thanks again … no doubt i will be in touch shortly !

Hi again … apologies for reviving this thread after so long, but it has taken me this long to get stage one out of the way. So now i have my table of disks named CDG and i have my table of members named MEMBERS. I have my members registration and sign up working with all pages in members area appropriately secured.
So now i need to work out how i can enable my members to create a list in the “lists” field in the MEMBERS table … I would greatly appreciate any direction on where to start.

Thanks again

Hi i actually thought about trying to copy the register script as i imagine it would work on a similar basis (remember i am a total novice) so i tried this … but there is a fatal error in it somewhere, saying that i might be totally of the mark aswell :slight_smile:

[php]<?php include 'header.php'; ?>

<? include_once"config.php"; if(isset($_POST['register'])){ $username = $_POST['listname']; if($listanem == NULL){ $final_report.= "Please enter Song List Name! Try again."; }else{ $check_members = mysql_query("SELECT * FROM `members` WHERE `listname` = '$listname'"); if(mysql_num_rows($check_members) != 0){ $final_report.="The listname is already in use! Try again."; }else{ $create_member = mysql_query("INSERT INTO `members` (`listname`) VALUES('','$listname')"); $final_report.='Your list has been created, nowAdd Some Discs.'; }}}}}}} ?>
 
<? if(!isset($_POST['register'])){?> Enter the name of your Song List below. <? }else{ echo "".$final_report."";}?>
Songlist:
 
 
<?php include 'blog.php'; ?>
		</div>
<?php include 'footer.php'; ?> [/php]

You will need to do a while loop or get the memberid or the id of the user some how first maybe from the login part but you want to select only there lists for that user.

below is not tested and wont work but will give you an idea member = $memberid as a where clause

[php]$check_members = mysql_query(“SELECT * FROM members WHERE memberid = ‘$memberid’”); while (mysql_num_rows($check_members)){
if($check_members >=1){[/php]

change your query to this
[php]$create_member = mysql_query(“INSERT INTO members,listname VALUES(’’,’$listname’) WHERE member=’$memberid’”)or dir(mysql_error());[/php]

Ok i am a little bit confused, please remember i am a total novice. So i found an example online of how to insert a value into a table, it consists of 2 files “insert.php” & “insert_ac.php” … it seems to function to an extent in that it inserts a new row into the correct table, although there is no visible content in the row. My problem is that i need it to insert the value into a specific column beside the currently logged in member. so my “members” table has columns id, username, password, email, listname of which the first four are created by the registration script. My insert_ac.php is supposed to then enter a list name into “listname” but it’s actually just creating a new row on the table with a new id … please help … below is some code which may be useful.

insert.php

[code]

Create Song List
Song List :
[/code]

insert_ac.php

[php]<?php

$host=“localhost”; // Host name
$username=“"; // Mysql username
$password="
”; // Mysql password
$db_name=“giftgang_cdg”; // Database name
$tbl_name=“members”; // Table name

// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// Get values from form
$name=$_POST[‘listname’];

// Insert data into mysql
$sql=“INSERT INTO $tbl_name(listname)VALUES(’$listname’)”;
$result=mysql_query($sql);

// if successfully insert data into database, displays message “Successful”.
if($result){
echo “”;
}

else {
echo “ERROR”;
}
?>

<?php // close connection mysql_close(); ?>[/php]

And this is the current code for all members pages, which may be off use for determining the current username

[php]<? ob_start(); session_start();include_once"config.php";

if(!isset($_SESSION[‘username’]) || !isset($_SESSION[‘password’])){
header(“Location: login.php”);
}else{
$user_data = “”.$_SESSION[‘username’]."";
$fetch_users_data = mysql_fetch_object(mysql_query(“SELECT * FROM members WHERE username=’”.$user_data."’"));
}
?>[/php]

Please accept my apologies if i am on the wrong track and have provided duff information. Thanks again for any help.

The query does not tell it where to put it so it just makes a new row if you add a where clause it will find the value of the where clause and insert it there, but if its already has a row you need to update rather than instert.

[php]$sql=“INSERT INTO $tbl_name(listname)VALUES(’$listname’)”;[/php]

[php]

$user_data = “”.$_SESSION[‘username’]."";
$sql="UPDATE $tbl_name SET listname=’$listname’ WHERE username=’$user_data’ ";[/php]

thanks for your reply, but still unsuccessful. I’m not getting any error, everything appears to be fine and the page redirects as it should after submitting. Unfortunately though, the “listname” column in the database is empty. Here is my modified insert_ac.php in it’s entirety.

[php]<? ob_start(); session_start();include_once"config.php";

if(!isset($_SESSION[‘username’]) || !isset($_SESSION[‘password’])){
header(“Location: login.php”);
}else{
$user_data = “”.$_SESSION[‘username’]."";
$fetch_users_data = mysql_fetch_object(mysql_query(“SELECT * FROM members WHERE username=’”.$user_data."’"));
}
?>

<?php $host="localhost"; // Host name $username="*****"; // Mysql username $password="*****"; // Mysql password $db_name="giftgang_cdg"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['listname']; // Insert data into mysql $user_data = "".$_SESSION['username'].""; $sql="UPDATE $tbl_name SET `listname`='$listname' WHERE `username`='$user_data' "; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo ""; } else { echo "ERROR"; } ?> <?php // close connection mysql_close(); ?>[/php]

Obviously i am going wrong somewhere … thank you once again !

move the database connection to the top under the config include

add this to the query & run it again
[php]$result=mysql_query($sql)or die(mysql_error());[/php]

Thanks once again, but unfortunately i have not found any success … Everything appears to function but nothing is actually being added to my table … here is code as it now looks.

[php]<? ob_start(); session_start();include_once"config.php";
$host=“localhost”; // Host name
$username=“giftgang_admin2”; // Mysql username
$password=“tascam424”; // Mysql password
$db_name=“giftgang_cdg”; // Database name
$tbl_name=“members”; // Table name
if(!isset($_SESSION[‘username’]) || !isset($_SESSION[‘password’])){
header(“Location: login.php”);
}else{
$user_data = “”.$_SESSION[‘username’]."";
$fetch_users_data = mysql_fetch_object(mysql_query(“SELECT * FROM members WHERE username=’”.$user_data."’"));
}
?>

<?php // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['listname']; // Insert data into mysql $user_data = "".$_SESSION['username'].""; $sql="UPDATE $tbl_name SET `listname`='$listname' WHERE `username`='$user_data' "; $result=mysql_query($sql)or die(mysql_error()); // if successfully insert data into database, displays message "Successful". if($result){ echo ""; } else { echo "ERROR"; } ?> <?php // close connection mysql_close(); ?>[/php]

I really wish i had learned something at school !

Sponsor our Newsletter | Privacy Policy | Terms of Service