[PHP-DB] array manipulation with foreach
I am trying to make a bit of code that takes values from 2 arrays, one array has a list of all the date's of this week starting from sunday, $arraydate[$n] = "the date" where $n is an integer between 0+6 the other is a multidimensional array composition as such; $rota[$staffid][$x] = "date staff member is working" where staffid is a unique id number for each staff member. $x is just a number to denote the second array that stores all the days that staff are working. The output created by the code is as follows, it is not displaying all the days that every staff member is working... it should have staff member 1 working sunday and tuesday, and staff member 2 working monday and wednesday. == Sunday Monday Tuesday Wednesday Thursday Friday Saturday Bar 2 == here is the code i used ( i know it isn't right, but i just don't know how to fix it) == $weekbeginning = weekbeginningYmd(); $arraydate = createdatearray($weekbeginning); $rota = getrotafromdb($date); ?> Sunday Monday Tuesday Wednesday Thursday Friday Saturday Bar foreach($rota as $staffid => $variable){ ?> foreach($arraydate as $key => $date){ ?> foreach($variable as $key2 => $workdate){ if($date == $workdate){ ?> } } ?> } } ?> _ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] date to Y-M-D
a function to convert any date to ymd... function datetoymd($date){ $dateymd = date('Y-m-d',$date); return $dateymd; } this function when output gives me the date 1970-01-01 (date of the unix timestamp start) so, ehm, why!? cheers, dave _ Stay in touch with absent friends - get MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] creating a date array
trying to make an array with every date (in -MM-DD format) of the current week in it... the below code ain't working, any ideas?! cheers, dave function createdatearray($sunday){ $date = date('Ymd',strtotime($date)); for($x=0; $x<=7; $x++){ $y = $x + 1; $date[$y] = mktime(0,0,0,date('m'),date('d')-date('w')+$x ,date('Y')); } return $date; } _ Stay in touch with absent friends - get MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] finding out the date of the first day of the current week
I am trying to make a small function that will me the date in Y-m-d of the start of the current week (the sunday) I have only the idea of doing it by making a long drawn out script with if, elseif clauses for every day of the week... and then doing something like if ( date('D') = "mon" ) { $sunday = mktime (0,0,0,date("m") ,date("d")-1,date("Y")); } does anyone know a simple way to do this _ Overloaded with spam? With MSN 8, you can filter it out http://join.msn.com/?page=features/junkmail&pgmarket=en-gb&XAPID=32&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] adding to an array variable using a loop...?
I want to create an array from results returned from a mysql query. I want it to go through each row in the returned result, and if the variable in the array staff exists add 1 to the total, if it doesnt exist, set it as one and carry on. But when i run this and do var_dump, it just returns "1" in the array for every date. I don't think my logic for this is correct, please help. Cheers, Dave. == $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) "; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ $x = 1; $date = $row['Date']; if ( isset($staff[$date] ) ){ $staff[$date] = $staff[$date] + $x ; } else{ $staff[$date] = $x ; } } _ It's fast, it's easy and it's free. Get MSN Messenger today! http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fwd: Re: [PHP-DB] need help with foreach()
Here is the complete function I am using. I returned, for testing i commented out the foreach loop and returned $staff, then $tips both arrays returned NULL when i did a var_dump(pointvalue($startdate)); can anyone see how this could be solved? Cheers, dave == function pointvalue($start){ $query = "SELECT * FROM Tips WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) "; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $date = $row[Date]; $tips[$date] = $row[TotalTips]; } $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) "; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ $date = $row[Date]; if (isset($staff[$date])){ $staff[$date] = $staff[$date] + 1; } else{ $staff[$date] = 1; } } return $staff; } _ Use MSN Messenger to send music and pics to your friends http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] need help with foreach()
Hey thank's for the ideas but neither of them work, doh... Okay fredrik I know your idea won't work cos list only works with numericaly indexed arrays, both the arrays that i am using are indexed by date. (it produces a parse error when run) = while(list($d, $t) = each($tips)){ $res = $t / $staff[$d]; // Do what you need with $res ... } = Janet your idea i would have thought would work but i can't get it to, for some reason whenever I run the script it just gives me... "Warning: Invalid argument supplied for foreach() in /home/filterseveuk/public_html/project/tips.php on line 56" Not sure as to what it is talking abotu here as far as I know, this should work. = foreach($tips as $key => $value){ $pointvalue[$key] = $value / $staff[$key] ; } == Does anyone else have a solution!? Cheers, Dave In a message dated 3/9/2003 2:07:26 PM Pacific Standard Time, [EMAIL PROTECTED] writes: Okay, i have two arrays, $tips and $staff $tips has a key "date" (which is the date of the first day of the week, the second result in the array has the key of the second day of the week etc... ) and the value is a floating point decimal. $staff also has a key "date" and the value is an integer, the number of staff working in one day. To find out the ammount of tips every staff member is to get we have to divide the value of $tips by the value of $staff (when the dates are the same) what i was trying to get this to work is below, any help would be great, cheers dave = foreach($tips as $key => $value){ $pointvalue[$key] = $value / current($staff) ; next($staff); } _ It's fast, it's easy and it's free. Get MSN Messenger today! http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] need help with foreach()
Okay, i have two arrays, $tips and $staff $tips has a key "date" (which is the date of the first day of the week, the second result in the array has the key of the second day of the week etc... ) and the value is a floating point decimal. $staff also has a key "date" and the value is an integer, the number of staff working in one day. To find out the ammount of tips every staff member is to get we have to divide the value of $tips by the value of $staff (when the dates are the same) what i was trying to get this to work is below, any help would be great, cheers dave = foreach($tips as $key => $value){ $pointvalue[$key] = $value / current($staff) ; next($staff); } _ Express yourself with cool emoticons http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Multidimensional arrays / Dynamic variables
Okay the problem is adding another result to the multi-dimensional array When i perform var_dump on the returned varialbe $tips i get array(1) { [2]=> array(1) { [0]=> string(10) "2003-03-07" } } I know that there are 2 results missing here for when the key of the array is 1 ($staffid = 1) the results are such that the array should look like this array(1) { [1]=> array(2) { [0]=> string(10) "2003-03-06" [1]=> string(10) "2003-03-07" } [2]=> array(1) { [0]=> string(10) "2003-03-07" } } now I just need some help getting my code to produce the second output. = function tips($weekstart){ $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; $result = mysql_query($query); _ Overloaded with spam? With MSN 8, you can filter it out http://join.msn.com/?page=features/junkmail&pgmarket=en-gb&XAPID=32&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Dynamic Variable names
Just a quick question about dynamic variables would like to end up with a variable called $tips_1 $tips_2 ... $tips_n where "n" is the value of the variable $sid i have tried $tips . '$sid'; and other variants, but i can't get one that doesn't return a parse error or T_VARIABLE error. _ Worried what your kids see online? Protect them better with MSN 8 http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: subtracting times (solution)
It took me about 30 mins but after 2 attempts i came up with a function that subtracts 2 times to give an answer in hours, to two decimal places. thanks for your help the two people who responded when i posted the question, your suggestions were a bit out on a tangent from what i wanted. But they got me kinda thinkin about it. the purpose of this is to calculate staffs payroll, by gettin their shift total of hours, this script assumes that a person will be starting work on one day, and finishing before 4am the next day. here's the code if your interested = $time1array = split(":",$time1); $time2array = split(":",$time2); $hours1 = ( ( $time1array[0] ) * 60 ); $minutes1 = $time1array[1]; $hours2 = ( ( $time2array[0] ) * 60 ); $minutes2 = $time2array[1]; $subtotal1 = ($hours1 + $minutes1); $subtotal2 = ($hours2 + $minutes2); if ( ("0" <= $subtotal2) && ( $subtotal2 <= "300") ){ $subtotal1 = ( 1440 - ( $subtotal1 ) ); $total = ( round ( ( ($subtotal1 + $subtotal2) / 60 ) , 2 ) ); } else{ $subtotal = ( ( ( $hours2 - $hours1 ) ) + ( $minutes2 - $minutes1 ) ); $total = ( round ( ( ($subtotal) / 60 ) , 2 ) ) ; } return $total; } _ MSN Messenger - fast, easy and FREE! http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] subtracting times
I know I asked this before buy no-one gave me an answer i was looking for, I want to subtract two times and the ammount of hours worked to 2decimal places (3.41 hours) cheers, dave _ Use MSN Messenger to send music and pics to your friends http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Subtraction of two units of time.
I want to take away two times stored in the format "00:00:00" in a mysql database, i retrieve the times and take them away by using the following $total = $time1 - $time2 ; when i echo the total it is a whole number of the hours.. and does not take the minutes into account, anyone have an idea of how to get an exact answer to 2decimal places of the subtraction of the two times? cheers, dave _ Chat online in real time with MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions (generates parse error)
Sorry, I forgot to add the part at the bottom where I am calling the function = $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ( isset ( $tips ) ){ if (isset ( $tips[$row[staffid]] ) ){ $hours = $row[finish] - $row[start]; $tips[$row[staffid]] = $tips[$row[staffid]] + $hours; } else{ $tips[$row[staffid]] = $row[finish] - $row[start]; } } else{ $tips = array('$row[staffid]' =>( $row[finish] - $row[start] ) ); } } return $tips; } function dbconnect(){ mysql_connect("localhost", "filterseveuk", "godisadj"); mysql_select_db("filterseveuk"); } dbconnect(); $date = "2003-03-02"; var_dump(tips($date)); ?> _ Express yourself with cool emoticons http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions (generates parse error)
Here is the whole code of my function Whenever i run it, it say's there is a parse error on line 6, can't see what is the problem the format of $weekstart (as it is stored in the Database) is -MM-DD = $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ( isset ( $tips ) ){ if (isset ( $tips[$row[staffid]] ) ){ $hours = $row[finish] - $row[start]; $tips[$row[staffid]] = $tips[$row[staffid]] + $hours; } else{ $tips[$row[staffid]] = $row[finish] - $row[start]; } } else{ $tips = array('$row[staffid]' =>( $row[finish] - $row[start] ) ); } } return $tips; } _ Stay in touch with absent friends - get MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] date functions
I want to use it in this function that i am creating (it's for a resteraunt automated tips system, to work out how much tips each staff member is entitled to. function tips($weekstart){ /* JUST BELOW HERE IS WHERE I NEED TO GET THE DATE OF 6 DAYS AFTER THE SPECIFIED DATE OF THE START OF THE WEEK */ $weekend = date($weekstart +6); $query = "SELECT * FROM Rota WHERE date => $weekstart AND date <= $weekend ORDER BY staffid"; etc... _ Surf together with new Shared Browsing http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] date functions
I am looking for a way to take a date stored in a mysql database... and find out the date seven days later. how would i do this?! cheers, dave _ Chat online in real time with MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] need help with fetching a result using a function
You haven't thorougly read my message, about 4/5 lines down i have said "(yes it is included in a script that connects to the database i am using)" :) i have another script that calls this function script, and at the top of it, it calls a script that contains my connection information. I have tested it with other queries that work... and there is no problem, i am definately connected to the database From: Koleszár Tibor <[EMAIL PROTECTED]> To: "David Rice" <[EMAIL PROTECTED]> Subject: Re: [PHP-DB] need help with fetching a result using a function Date: Sun, 2 Mar 2003 16:54:25 +0100 Hello, You have forgotten to connect :) This error occurs when the $result variable is false and it is not a resource (database query) id. Tibor PS: for any db: $conn_id = connect(...); $result_id = query($conn_id, ); $row = fetch($result_id); ... - Original Message - From: "David Rice" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, March 02, 2003 4:49 PM Subject: [PHP-DB] need help with fetching a result using a function > > I am trying to write a few functions for a project i need to do for school, > this function should return all the inactive, or active users (1 or 0 > staffstatusid) as an array for creating a drop down menu. > > Now when i perform the following code (yes it is included in a script that > connects to the database i am using) it returns the following error. > > "Warning: Supplied argument is not a valid MySQL result resource in > /home/filterseveuk/public_html/project/getusers.php on line 7" > > and underneath the error it prints the value of var_dump($data) > which is " NULL" > > any ideas how to fix this? > > > = > > function getusers($status){ > > $query = "SELECT FROM Staff WHERE Staffstatusid = '$status'"; > $result = mysql_query($query); > $row = mysql_fetch_array($result); > $users[$status] = $row ; > return $users[$status] ; > } > $status = 0 ; > $data = getusers($status); > var_dump($data); > > echo $data; > ?> > > _ > Use MSN Messenger to send music and pics to your friends > http://messenger.msn.co.uk > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > _ Overloaded with spam? With MSN 8, you can filter it out http://join.msn.com/?page=features/junkmail&pgmarket=en-gb&XAPID=32&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] need help with fetching a result using a function
I am trying to write a few functions for a project i need to do for school, this function should return all the inactive, or active users (1 or 0 staffstatusid) as an array for creating a drop down menu. Now when i perform the following code (yes it is included in a script that connects to the databas i am using) it returns the following error. "Warning: Supplied argument is not a valid MySQL result resource in /home/filterseveuk/public_html/project/getusers.php on line 7" and underneath the error it prints the value of var_dump($data) which is " NULL" any ideas how to fix this? = $query = "SELECT FROM Staff WHERE Staffstatusid = '$status'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $users[$status] = $row ; return $users[$status] ; } $status = 0 ; $data = getusers($status); var_dump($data); echo $data; ?> _ Use MSN Messenger to send music and pics to your friends http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Session troubles, could this be my isp's fault?
I Have made two pages, "sess2.php" and "sess3.php" trying to create a session variable then access it in the other page. now when i try and call the session in the second page i get no value, and i have tried var_dump, and it gives me "NULL" anyone know if there is a reason for this?! page 1 is like this = Session Test next _ Surf together with new Shared Browsing http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SESSIONS
Here's something i can't get working it won't go to the last clause of this page i don't think it can set the session variable anyone see what im doing wrong? i need more caffeine to get my brain fired up today lol.. === next _ Stay in touch with absent friends - get MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP session problems
I have been having trouble with PHP sessions, the session variables are not able to be called through the script. If have commented the area at the bottome where the session variable is NULL when var dump is called to check it (about 20 lines from the bottom... depending on if the text is wrapping or not) here is the actual code == include "library/include/header.php" ; include "library/include/database.php" ; /* Include a header file and a database connections/functions file */ if ( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( !isset ( $proceed ) ) && ( !isset ( $submit ) ) ) { /* The Cookie is not set, so load the page as if it is the first time */ ?> While( $row = mysql_fetch_array($result) ) { ?> "> } ?> } elseif( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( !isset ( $submit ) ) && ( isset ( $proceed ) ) ) { /* The User is now attempting to register */ ?> session_register('valid_user'); $_SESSION["valid_user"] = $staffid; $_SESSION['name'] = $row["1"]; ?> Welcome What is your National Insurance Number Choose a password Enter it again } elseif( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( isset ( $submit ) ) ) { /* information for registration has been entered, lets check if it is valid */ $_SESSION['valid_user'] = $staffid ; $ni = $HTTP_POST_VARS["ni1"] . $HTTP_POST_VARS["ni2"] . $HTTP_POST_VARS["ni3"] . $HTTP_POST_VARS["ni4"] . $HTTP_POST_VARS["ni5"] ; $query = " SELECT * FROM Staff WHERE StaffId = '$staffid'"; $result = mysql_query($query) or die( mysql_error () ); $row = mysql_fetch_array($result); /* HERE THE SESSION VARIABLE HAS NO VALUE... WHEN I CALL VARDUMP IT IS NULL */ var_dump($_SESSION["valid_user"]); echo $ni ; echo $staffid; if( $ni == $row["4"]){ echo "ni check successful"; if( $pass1 != $pass2 ){ echo "Your Passwords are not the same" ; } else{ $query = "INSERT INTO Staff WHERE StaffId = '$staffid' password values ('$pass1')"; if($result=mysql_query($query)){ echo "your password has been set, Continue to the site"; } } } } include "library/include/footer.php" ; ?> _ Stay in touch with MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] need help spotting this php parse error
It Does have a closing Brace, just check my second email it contains the FULL code.. i missed the last few lines copying it the first time somehow. From: "Andreas Sheriff" <[EMAIL PROTECTED]> To: "David Rice" <[EMAIL PROTECTED]> Subject: RE: [PHP-DB] need help spotting this php parse error Date: Thu, 23 Jan 2003 12:09:15 -0800 The if statement does not have a closing brace. > -Original Message- > From: David Rice [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 23, 2003 11:53 AM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] need help spotting this php parse error > > > When i run this script it tells me that I have a parse error on > line 34? I > really can't see it anyhelp (please!) would be much appreciated > Cheers, Dave > > > session_start(); > > if(!$HTTP_COOKIE_VARS["username"]) { > > /* The Cookie is not set, so load the page as if it > is the first time > */ > > include("library/include/header.php"); > include("library/include/database.php"); > > /* Include a header file and a database > connections/functions file > */ > > ?> > > > > > > $query = "SELECT * FROM Staff WHERE > ResterauntId = 1"; > $result = mysql_query($query) or die( > mysql_error () ); > > While( $row = mysql_fetch_array($result) ) { > >?> > ?>"> $row["2"]; ?> > } > ?> > > > > _ > Stay in touch with MSN Messenger http://messenger.msn.co.uk > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > _ Use MSN Messenger to send music and pics to your friends http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re. Need help spotting PHP parse error
"Parse error: parse error in /home/filterseveuk/public_html/project/login.php on line 34" That is the exact error message, Cheers, Dave session_start(); if(!$HTTP_COOKIE_VARS["username"]) { /* The Cookie is not set, so load the page as if it is the first time */ require("library/include/header.php"); require("library/include/database.php"); /* Include a header file and a database connections/functions file */ ?> $query = "SELECT * FROM Staff WHERE ResterauntId = 1"; $result = mysql_query($query) or die( mysql_error () ); While( $row = mysql_fetch_array($result) ) { ?> > } ?> _ Worried what your kids see online? Protect them better with MSN 8 http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] need help spotting this php parse error
When i run this script it tells me that I have a parse error on line 34? I really can't see it anyhelp (please!) would be much appreciated Cheers, Dave session_start(); if(!$HTTP_COOKIE_VARS["username"]) { /* The Cookie is not set, so load the page as if it is the first time */ include("library/include/header.php"); include("library/include/database.php"); /* Include a header file and a database connections/functions file */ ?> $query = "SELECT * FROM Staff WHERE ResterauntId = 1"; $result = mysql_query($query) or die( mysql_error () ); While( $row = mysql_fetch_array($result) ) { ?> "> } ?> _ Stay in touch with MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] build menu with mysql data
Rite marc, this is what your gonna have to do, in a new table like this lets say we call it "MAINSUB" MAINMENU ID SUBMENU ID it only contains those 2 fields to show that there is a link between the two okay? now to the actual menu < for($x=2, $x < 4, $x++ < SELECT * FROM MAINSUB WHERE MAINMENU ID = '$x' < I've not explained it FULLY cos it's always better to work the most part of a problem out yourself... if ya have any more questions email me Dave From: "Marc Bleuler" <[EMAIL PROTECTED]> To: [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: [PHP-DB] build menu with mysql data Date: Tue, 21 Jan 2003 18:31:15 +0100 Hi, I would like to bild a tree menu with mySQL data. where I have the collapsed main menue and when I click the link the specific submenue expands (as follow). (collapsed Main Menu) + Home + Downloads + About me + Search and for example if I click the "Download" section it will look as follow (expanded Main-Sub Menu) + Home + Downloads - Music - Programm + About me + Search and the SQL Tables... MAINMENUE_TABLE IDNAME - |1|Home| |2|Downloads| |3|About me | |4|Search | and SUBMENUE_TABLE IDMAIN_ID NAMEURL --- |1|2|Music| ./somefile.php?action=music |2|2|Programm | ./somefile.php?action=programm |3|3|Pictures | ./somefile.php?action=pictures |4|3|Address| ./somefile.php?action=address |5|4|My Page | ./somefile.php?action=mypage |6|4|The Web | ./somefile.php?action=theweb |7|4|Google | ./somefile.php?action=google If I'm using a while loop it won't work, so I realy don't have and more ideas... Please consider in your explanations I'm a PHP beginner... :-) thanks Marc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] MySql DB, help, sql error and i don't know why
SQL-query : CREATE TABLE `staff` ( `StaffId` INT( 4 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `Name` VARCHAR( 30 ) NOT NULL , `Surname` VARCHAR( 30 ) NOT NULL , `Address` TEXT( 225 ) NOT NULL , `JobId` SMALLINT( 2 ) NOT NULL , `PermissionId` SMALLINT( 2 ) NOT NULL , `HomePhone` INT( 11 ) NOT NULL , `MobilePhone` INT( 11 ) NOT NULL , `TipsPoints` INT( 1 ) NOT NULL , `DOB` DATE NOT NULL , `Password` VARCHAR( 20 ) NOT NULL , `ResterauntId` INT( 1 ) NOT NULL , `DateStarted` DATE NOT NULL , `StaffStatusId` TINYINT( 1 ) NOT NULL ) MySQL said: You have an error in your SQL syntax near '(225) NOT NULL, `JobId` SMALLINT(2) NOT NULL, `PermissionId` SMALLINT(2) NOT NUL' at line 1 _ MSN 8: advanced junk mail protection and 2 months FREE*. http://join.msn.com/?page=features/junkmail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] php -> excel
Just a question, is it possible to dynamically create an excel spreadsheet from data in a mysql database the excel sheet does not have to be displayed, just to be sent to print, to give better print quality than a webpage tables equivalent. Or is there another way of doing this? _ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] MySql Update.
Making an update query that adapts to the number of fields that are to be updated Is there anyway to do like a for loop to create the values part of the query then combine it with the first part of the string. something like what i have below... although something that works correctly as this doesn't. == $table is the table name $num_headers is the number of headers (fieldnames) for that table $table_headers is an array with the names of the headers $values is an array with the names of the input boxes on the previous page == $query1 = "UPDATE ".$table." SET " ; $query2 = ( for ($x=0; $x <=$num_headers; $x++){ ". $table_headers[$x] . "=" . $values[$x] . " , " }) ; $query = $query1.$query2 ; $result = mysql_query ($query) ; etc... _ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Dynamic MySql Update Query
Okay this is a tough one. I want to make a dynamic mysql update query that takes results entered into a series of text boxes (changes from page to page) and then updates that record in my Mysql table. the name of the form fields are $value[$x] where 1 <= $x <= Total number of fields === $query = "UPDATE ".$table." WHERE ".$table_headers[0]." = ".$id." VALUES === I have gotten this far, but don't know where to go next. check out www.filterseven.co.uk/admin/index.php and if you check a table, and choose an edit query on one of the records to see what i am trying to do. thank's for your time! cheers, David Rice _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] retrieving data from mysql table
okay thank's for the help on my previous question. I've got it to retrieve a list of column headers now, i want it to retrieve all the records from the table and print them underneath. the code i have is ** /* get a list of the column headers from the table */ mysql_select_db("filterseveuk") or die(mysql_error()); $query = "SHOW COLUMNS FROM " .$table. ""; $result = mysql_query ( $query ) or die( mysql_error () ); ?> $x = 0 ; while ($row = mysql_fetch_assoc ($result)){ ?> /* before printing the table header, we put it in the array "table_headers" */ $table_headers[$x] = $row['Field'] ; echo $row['Field']; $x++ ; ?> } ?> /* Select all the records from the table */ $query = "SELECT * FROM " .$table. "" ; $result = mysql_query ( $query ) or die( mysql_error () ); $x = 0 ; while ( $row = mysql_fetch_assoc ($result)) { ?> echo $row[$table_headers[$x]] ; ?> $x++ ; } ?> ** this outputs ** http://www.filterseven.co.uk/admin/index.php?table=user&action=edit any ideas? _ STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Extracting column names from a db
I need to write a script that will extract the names of the columns in my database eg. "user_id, username" can anyone help as to how to do this! I have tried ** *** mysql_select_db("filterseveuk") or die(mysql_error()); $query = "SHOW COLUMNS FROM " .$table. ""; $result = mysql_query ( $query ) or die( mysql_error () ); $numrows = mysql_num_rows ($result); $row = mysql_fetch_array ($result); for($x=0; $x <= $numrows; $x++){ echo $row[$x] ; } ** *** this doesn't work the way i want it to and gives me the output ** *** user_idint(11)PRIauto_increment Warning: Undefined offset: 6 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 7 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 8 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 9 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 10 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 11 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 12 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 13 in /home/filterseveuk/public_html/admin/index.php on line 30 Warning: Undefined offset: 14 in /home/filterseveuk/public_html/admin/index.php on line 30 _ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] need help with SHOW COLUMNS
I am tryin to create a DBMS, the part of my code that is currently causing a problem is mysql_select_db("filterseveuk") or die(mysql_error()); $query = "SHOW COLUMNS FROM " .$table. ""; $result = mysql_query ( $query ) or die( mysql_error () ); $numrows = mysql_num_rows ($result); $row = mysql_fetch_array ($result); for($x=0; $x <= $numrows; $x++){ echo $row[$x] ; } It produces the error user_idint(11)PRIauto_increment The output i want to obtain from this query is that php prints out a list of the field names. I don't know why this is not working How do i get it to only display the column names!? _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] need help with "SHOW Colums"
mysql_select_db("filterseveuk"); $query = ( " SHOW COLUMNS FROM user "); $result = mysql_query ( $query ) or die( mysql_error () ); while ( $row = mysql_fetch_array ($result) ){ $x = 0 ; echo $row[$x] ; $x++ ; } I would like to replace the table name "user" with a variable $table, that wil automatically take the value of the selected table. I have tried many times but cannot get the correct sql syntax, it keeps saying "you have an error in your sql syntax near 'user' line 1" when i try it with $table. any ideas?? thank's, dave rice ([EMAIL PROTECTED]) _ Choose an Internet access plan right for you -- try MSN! http://resourcecenter.msn.com/access/plans/default.asp -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php