How Do You Add Values In Rows Together
I am using the following code to take records out of a Mysql database and display them on an HTML form. $myrow[8] is a number. At the bottom of the table, I want to display the sum of all the $myrow[8] values added together. Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Count Values Rather Then Rows
I trying to count how many times a tutorial has been viewed in total for all tutorials. I can count how many tutorial views they've been from the rows but as my tutorial views increment each time the tutorial is viewed its not accurate. What I need is to be able to count the values from the table from each row and add them together. Code:
Looped Rows In Table Add & Remember Values
I'm trying to get this app to work. It's supossed to: 1. create rows dynamically through a loop (done) 2. remember the user-entered-values while the form posts to itself 3. provide a total (addition) of all 4 rows. (kinda tricky since the rows are looped). PHP Code:
Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have: $db = array(); //main array $db['main'] = array(); //table `main` $db['main'][] = array('id'=>0, 'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin'); //row $db['main'][] = array('id'=>1, 'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user'); //row function trim_value(&$value){ $value = strtolower(trim($value)); } function fdb_select($fields = "*", $table, $where = false, $limit = false){ global $db; $retv = $db[$table]; //LIMIT RESULTS TO FIELDS if(strrpos($fields, ",") === false){$field=array($fields);}else{$field = explode(",", $fields);}; array_walk($field, "trim_value"); $all_fields = array_keys($retv[0]); if($fields == '*'|| is_null($fields)){$field = $all_fields;}; $field = array_uintersect($all_fields, $field, "strcasecmp"); $retvi = array(); foreach($retv as $num =$row){ foreach($row as $fname =$fvalue){ $fname1 = strtolower($fname); if(in_array($fname1, $field)){ $retvi[$num][$fname]=$fvalue; }; }; }; //DONE LIMITING TO FIELDS if($where != false){ //UP TO HERE IT WORKS FINE //LIMIT TO WHERE CLAUSE $retvj = array(); foreach($retvi as $num =$row){ //IN THE ROW foreach($where as $k =$v){ //IF ROW MEETS ALL REQUIREMENTS if($row[$k] == $v){ $retvj[] = $retvi[$num]; //Keep that row }; }; }; //DONE LIMITING TO WHERE CLAUSE }; $retvi = (isset($retvj)) ? $retvj:$retvi; //SEND A FINAL ASSOCIATIVE ARRAY return $retvi; }; print_r(fdb_select("*", "main", array('id'=>"1", "username"=>"joshfrench"))); the previous code outputs this: Array ( [0] =Array ( [id] =0 [username] =joshfrench [userpass] =password [userlevel] =admin ) [1] =Array ( [id] =1 [username] =bob_smith [userpass] =psswrd [userlevel] =user ) )
Adding New Values To An Array That Already Contains Values..
is it possible to append new values to an array that already has values in it?? say, i have my existing array; existing array; $array = array([66314] => 66314 , [66315] => 66315) ; then , when i check my checkbox on my next page, the ids should be appended to the $array: array that needs to be added to the $array; $array = array([66316] => 66316,[66317] => 66317,[66318] => 66318); how should it be done??
Assigning Values With Other Values
Say one has an array like such: array("lang=english", "nomusic=true", "name=Fred", "menu=false"); Is there a function in which I input the array and it makes all the things into variables with the other things as the content like: $lang="english"; $nomusic="true"; $name="fred"; $menu="false";
Counting Rows
I need to get the number of rows in a table. This is the query I'm using at the moment: $query = "SELECT COUNT(*) from mytable"; $result = mysql_query($query) or die ...; What php function may I use to get the number and in which way? I tried with $num = mysql_num_rows($result); but nothing.
Grouping Rows
I've gotten a few rows, that I want to sort based on the date that it's scheduled. This means that I've gotten different rows, and I want to create something like this: Monday 99 Januari: Row1 Row3 Tuesday 99 Februari: Row2 Row4 This way the system sorts the rows by date and groups them. Only I still haven't found any way how to do this. Any ideas?
How Many Rows In A Table
I am sure there must be an easy way to determine the number of rows in a table, but I can't find it.
Get Number Of Rows?
Is there a way to get the number of rows returned from a query? (database used: MySQL)
Missing Rows
I've been trying to retrive a limited numbers of rows ordered by a date and it keeps on returning 1 row less than I've wanted. code:
Counting Rows
I have an admin system (Add/Modify/Delete) for two types of records in the database. They have a Parent - Child relationship My problem is that I want to display on the "parent" record whether the child exists or not . The records are found in two different tables, but have the same Primary Key.
Say I Have 48 Rows, How Would I Seperate Every 12?
I have to create an html page that will be printed and it has to be THE SAME as the old page made in Excel. I'm right now because for each query (could have 1 to 65 or any number of rows) I have to seperate the results into groups of 12. PHP Code:
New Table Rows
I retrieve 20 items from a MySQL database. I want to display the output in a table. How can I display 5 items on a table row and then begin an new row?
Getting SQL Rows For A Week
I have a database that uses two date fields for tracking information. The first field is for the addition of the record and the second is for the expiration. I have a small section that I want to list records that will expire in the current week (or for that matter in the next 7 or 14 days). What is the syntax that I would use to call mySQL with to get that info.
Autentication Rows
when i try and log in, the script bellow keep throwing an error back on the last 2 lines i have commented over $numrows and $rows. can anyone point me in the right direction. I am not looking for someone to fix the code, but I need guidence. Code:
Returning All Rows Instead Of Row By ID
When I try to call data for only one person using the below code, it displays everyone in the database. What am I forgeting to do? Im refering them to this from options.php?id=<? echo $row->id; ?> PHP Code:
Rows Affected?
I am executing an update-query. Is there a way I would get a result if there is a row affected, because if the row isn't affected (product may not exist) I have to execute a insert-query. This way I could use 1 query (in the update-case). Else I would always have to execute 2 query's (1 count-query and 1 insert or update query).
Trying To Delete Rows.
I am trying to use php to delete rows for a mysql database table, i am using the following code with $journeyIDToUse being a number that represents a automaticly incrementing primary key. $toDelete = "DELETE FROM journeyData WHERE journeyID='$journeyIDToUse'"; mysql_query($toDelete); This fails to delete the row. I have tried changing $journeyIDToUse to a number and that worked so i thought that the variable might be at fault but the following query works so that rules that out $searchString = "SELECT * FROM journeyData WHERE journeyID='$journeyIDToUse'"; $result = mysql_query($searchString); $row = mysql_fetch_array($result);
Ordering Rows By Value
Is it possible to display rows in order of a value within the rows? I need to do this without saying 'order by' in the 'select from' statement. The reason is because i'm using values from my select from statement to work out totals. Once i've worked out the totals i'm displaying the rows as per the code below. This works fine but I want to display the row containing the smallest $TOTAL_REDUCED value first, with the next highest next, and so on. Code:
Need Rows With Certain Dates
I have rows in a db stored with dates in the form of: 2007-07-07 00:00:00 (type is text). I need to get all dates between now and 14 days from now. Can I get some help on how I should do this? Since the type is text, do I have to use strlen? Or can I do this all in the query somehow?
Max Rows Cannot Add More To My Database
I need to add more rows to this table, and I cannot.....? I'm not sure if this is a SQL problem, though when I look at the setup of the table all TYPES are set to (int)11. I'm a newby so i'm not sure if the PHP is scripted to limit database input. I am at 2249 on my attribute rows. Code:
Selecting 10 Rows Together
I have this script that displays verses out of the bible. The problem is that it is only displaying one verse. I would like for it to display about 10 verses in a row. Random selections though. $result = mysql_query("SELECT * FROM bible ORDER BY RAND() LIMIT 1 "); // WHERE catid <> 'TBP' while($myrow = mysql_fetch_array($result)) { $title = $myrow['book'].' '.$myrow['chapter'].' : '.$myrow['verse'].'<br /> '.$myrow['text']; echo $title; echo "<br />"; echo "<br />"; }
Breaking Rows
I am using a while statement to pull results from my database. Now if I have like 40 results how would I make it break into rows. So instead of; result result result result result result result result result result result result result result result result result result I want; result result result result result result result result result result result result result result result result result result result result
Displaying 10 Rows (Newbie)
I need help....I want to display 10 hits from my sql database..... A function that wil select the first 10 rows of my database and then also provides me with a link to the script itself to diplay the next 10 hits (Or less, if there is no more).
Inserting Multiple Rows Via The Web
I would like to have a form that can have multiple rows inserted on the same page and then submitted to the database in one click. How would I go about doing this with, say, three text fields that are named "name", "email", and "URL"?
PHP/mySQL Counting Rows In My Db
I'm building a little news board and I need to count the total number of rows in my db ... simple, I know... but I can't get a result. here is the code...
Updating Multiple Rows
I am trying to create a form to update multiple entries in a mysql databse. This code below is rough, but it is working to the point wher it pulls the data, displays it in the text areas (but it does not go past the first white space in displaying, that needs to be fixed), and then I can alter the text fields, check a box, and hit submit, and it will update the fields, but the new value is size=20. I also can't update more than one record at a time, which defeats the purpose. Any ideas?
Deleting Rows In Mysql
Is there a way in php that I can mark a row in my mysql database and then later so delete these rows that have been marked?
Displaying Entries In Rows Instead Of On Top Of Each Other
I'm altering a voting script for our dog rescue so that we can hold an online photo contest. I'm very new to php & mysql..kinda just muddling my way about with this. I want to display the entries in a row across about 4 or 5 photos and then keep it going that way, but I haven't a clue as to how to do this....
Warning: Mysql Num Rows():
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/signup.php on line 159 source code:
Updating Multiple Rows
I have a databse with a list of employees, I also have in that database a field that shows their status 1- Out, 0 - In. What I would like to do is make a page that will list all of the employees with their current status in radio buttons that I could then make changes and submit that will then update the database with the changes for all of the employees. Here is the code I have for the first page: PHP Code:
Deleting Mutiple Rows
I have this Code: echo "<td>"; echo "<input type='checkbox' name='id' value='"; echo $row["id"]; echo "'></td>"; etc etc etc ect.... The above code works for 1 record at a time. I can't change the name of the form field to del[] cause I need that id in there.
Eliminate Gap Between Table Rows?
I made my first PHP page that uses includes. http://php.didah.com/main.php But I can't get rid of a gap (about 5 pixels) between the table rows. The content of each include file is one line like this: <img src="images/nav.gif" width="100" height="600" hspace="0" vspace="0" border="0"> No head or body tags. Just a 100 x 600 gif image. Here's the code for the main.php page: <html> <head> <title>First Include Page</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="600px" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><?php include 'header.php' ?> </td> </tr> <tr> <td><?php include 'nav.php' ?></td> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>This is the content area.</td> </tr> </table></td> </tr> <tr> <td colspan="2"><?php include 'footer.php' ?></td> </tr> </table> </body> </html> If you look at the main page in IE there is a vertical gap between the header, nav, and footer image. Does anyone know how to get rid of this?
Processing Dyn. Form When I Don't Know How Many Rows
I build a form dynamically from a mysql database, and then name each record to build a form. How do I "display" it once it is submitted if I don't know beforehand hand many rows, and therefore, how many IDs there are going to be? Code:
Number Of Rows Loop
I am having a user validation which will dictate how many rows of information they will be prompted to enter, but i'm having problems with the loop. Right now, i'm passing the number of rows as $row, and want to repeat the following code in a form for $row times. Code:
Selecting Rows From Db Table
In a project mentioned in another thread, I'm trying to get some dynamic data to work. In this discography, you can click on an album name, and the title of the album and its tracks will appear on the left. I have the beginnings worked out, like so: *** <h3><?php echo $row_rsindiv['Album']; ?></h3> <ol> <?php do { ?> <li><?php echo $row_rsindiv['Song']; ?> (<?php echo $row_rsindiv ['Time']; ?>)</li> <?php } while ($row_rsindiv = mysql_fetch_assoc($rsindiv)); ?> </ol> *** A sample of the database: *** Electronic Meditation 3 Cold Smoke 10:48 Electronic Meditation 4 Ashes to Ashes 3:58 Electronic Meditation 5 Resurrection 3:21 Alpha Centauri 6 Sunrise in the Third System 4:20 Alpha Centauri 7 Fly and Collision of Comas Sola 13:23 Alpha Centauri 8 Alpha Centauri 22:04 Zeit 9 Birth of Liquid Plejades 19:52 Zeit 10 Nebulous Dawn 17:47 *** I want to tell PHP to write the album name and list the tracks in an <li></li> based on whatever album title is clicked in the main table. The main table looks like: *** <?php do { ?> <?php $class = ($class == 'odd') ? 'even' : 'odd' ?> <tr class="<?php echo $class ?>"> <td><?php echo $row_rstdream['Album']; ?></td> <td><?php echo $row_rstdream['Year']; ?></td> <td><?php echo $row_rstdream['Era']; ?></td> <td><?php echo $row_rstdream['Type']; ?></td> </tr> <?php } while ($row_rstdream = mysql_fetch_assoc($rstdream)); ?> *** I thought maybe of changing the first <td></td> to: <td><a href="#" onclick="<?php $album = $row_rstdream['Album'] ?>"> <?php echo $row_rstdream['Album']; ?></td> But that's as far as I can get with my limited knowledge. Does anyone have any ideas on how to display only the rows in the second database that correspond to the name of the album clicked on? Sorry the examples are so long,
Thumbnails In Rows Of 4 Across The Page
how I can position thumbnails in rows of 4 across the page? I've tried so many code combinations my head's swimming. Most of them produced a vertical display.
Number Of Rows--displayed
Is there a way to call a function that would display the number of rows in a table? I'd like to have a count on the page that allows people to query the database to demonstrate that the database is growing and constantly changing.
Insert Multiple Rows At Once
i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d', '$e')"; I want to insert 5 rows at a time in the database, but it only inserts every 5th record. For example: 1. AA 2. AB 3. AC 4. AD 5. AE I only find 5. AE back in the mysql with id 1. How can I insert multiple rows at once ?
Exact Duplicate Rows
I find many different exact duplicate rows in the table. I would like to remove all the duplicates and keep just one copy of each. Can I do this with mysql or PHP?
Getting Number Or Rows In Recordset
I've been checking some examples and several have shown ODBC_NUM_ROWS() to get the number or rows in the recordset. Yet, even if i get rows, it still returns -1 each time PHP Code:
Database Blank Rows
i made the following script and all the conditions and structure is right, i do no get errors either. but when you enter a category name andm press enter it says it added it but the database only has an extra blank row in it rather than what you entered? PHP Code:
Inserting Multiple Rows Into Db At Once
i have a text file with a BUNCH of different words, each on its own line, curious if there is a way for me to import them into a simple table (with an id column and name column) along with an id based on time(). im not very good with loops, but im assuming this is the best way to do it. For instance, have it loop thru each word and give each word a unique id based on time(). any simple methods out there?
Drop Down Not Displaying All Rows
I am having an issue with the drop down box. If there is only one row in the table the drop down box will display nothing. once the table has two or more rows the drop down displays the row but always one shy of the total. here is the script i am using: $query = "SELECT SEC_TITLE FROM section WHERE SEC_TITLE != ''"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<form action='#'> <select name=section> "; while ($line = mysql_fetch_array($result, MYSQL_NUM)) { $section = $line[0]; echo " <option value=$section>$section "; } }
Copying Rows To Another Table
After I select a row whose ID is 10 or some other number, I need to copy the entire row into another table. Is there a way to copy rows between tables using PHP? Could someone please point me to an example..
|