Having Trouble Looping Through Records In A MySQL Table
I'm having some trouble looping through the records of a MySQL table using PEAR DB. Here is my code:
$navigationSql = "SELECT * FROM nav";
$navigation =& $db->query($navigationSql);
while ($navigation->fetchInto($nav)){
define("NAVIGATION", "<a href="$nav[2]" target="$nav[3]" title="$nav[1]">$nav[1]</a><br />"); }
The when I enter:
print NAVIGATION;
into any of my PHP scripts it should loop through the stuff in table named nav, but it is only displaying the first record and so far everything I've tried does not seem to make it loop through all of the records in the table and I can't figure out why not.
View Complete Forum Thread with Replies
Related Forum Messages:
Trouble With Looping Through An Array
I am having some trouble with a booking system. What I want to do it is make booked times display in red. Available times in white. Below is my function. It works for no, or one booking. However if you do a second booking everything comes unstuck, its pretty obvious why but I can't figure out any other way to do this. Code:
View Replies !
Trouble Passing Mysql Table Name To Php Function And Using It!
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result = mysql_query("select * from $tableInfo") ; for ($i = 0; $i < mysql_num_rows($result); $i++) { /* do something */ } } /* Main */ fms_get_info(); But it won't work if I pass a variable table name to the function. <?php function fms_get_info($tableName) { $result = mysql_query("select * from $tableName") ; for ($i = 0; $i < mysql_num_rows($result); $i++) { /* do something */ } }
View Replies !
Transfer Edited Records From One MySQL Table To Another
What I need is for a user to search a certain database table for a purchase order #. The results then need to be displayed in textboxes so they can be edited as needed. Then the edited records need to be inserted into another table, and deleted from the former. I have the first two steps coded, but am having trouble figuring out how to do the third correctly. Here is my code:
View Replies !
Count,sort,diplay Number Of Records In MySQL Table
I am designing a search engine using PHP/MySQL and I am logging all search terms into a MySQL table. I was wondering how I count the number of occurences of a term in the table, and then sort and display the terms in descending order. For example, if the column in my table with search terms looked something like this: clothes casinos clothes homes homes clothes How can I count and order the records so that I can display according to how many times they appear, like so: 1. clothes(3 entries) 2. home(2 entries) 3. casinos (1 entry)
View Replies !
Trouble Counting Records In Db
I'm creating a subscriber report and just want to echo out the total number of subscribers, how many male, how many female etc. I have tried variations on this: $sql = "SELECT COUNT(gender) as totalrows FROM subscribers WHERE gender=Male"; $result = mysql_query($sql, $conn); echo ("There are $result male subscribers.") but nothing is printing. Do I need to do something with "$i" and "++"? If you are selecting a specific record and not the entire row is the result still an array?
View Replies !
Add New Table Row While Looping
I want to display 4 images in a <td> from a database. Once the loop gets to 4 images I want to start the 5th one on a new line. Can someone help me with this. This is what I have so far (obvisously it keeps creating new <td>, but no <tr>... Code:
View Replies !
Looping In Table
i want to get the number of name from user, then i want to put it in rows. my code: echo"<form method='POST' action=''> <table border=1> for($i=0; $i<$NameCount; $i++) <tr><td>$name[$i]</td></tr> </table> </form> ";
View Replies !
Looping Through Lookup Table
I've tried to be clear, but its kind of complex. THE BACKGROUND: This is an event scheduling application. I have a query containing a series of left joins, the second to last of which joins a lookup table with no key. Here's the pseudocode SELECT * FROM table1(schedule dates) LEFT JOIN table2(Events) on table1_events_id = table2_field1(The Event id) LEFT JOIN table3 (a lookup table with no key containing id's for bands that comprise the "event") on table2_field1(The Event id) = table3_field1(The Event id) LEFT JOIN table4(the bands) on table3_field2(the band's id) = table4_id(the band's id) The lookup table (table3) contains 4 fields the id from table 2(The Event id), and the id from table 4(The Band) PLUS an enum column 'Y''N' used to categorize, and an Order column meant to order the results after the 'Y'/'N' flag is identified. It all funnels down to table3, then it can go either "yes" or "no" and continues to table 4.
View Replies !
Wrapping Looping Output In A Table
I want to "wrap" a looping output in a table. In regular html this is how you can wrap text: <table width="100%"> <tr> <td>wrap long line of text here</td> </tr> </table> Can't get this to work in php though. Now I want to embed the php code in this table...here is the code:
View Replies !
Html Table Trouble
I have a database with three columns. One is an atomic number, one is a pic url, and the other is a description. What I'm having trouble doing is putting the url in one table row and the description in another table row right below it like this... <tr<tdsome pic url</td<tdother pic url</td></tr> <tr><tdsome descripts </td<tdother descript </td></tr> whilest limiting the rows to about 10 cells each,,.... any ideas?
View Replies !
Trouble Linking One Table Entry To Another
I very new to PHP but like what I'm getting into. I know this is a simple question with a simple answer, and I know I must be missing something easy. I have a contact table, which naturally lists all of our clients. When they make a purchase, we update the order table and as part of that, we need to tie that order back to their client entry. When I try to pick up and enter the "clientID" in the order table, all I get is a zero(0). Everything else populates correctly. Below are the two scripts involved. The first is the display where the ClientID comes from, and yes, it gets passed over to the second, but does not make it to the SQL statement. Any advice would be appreciated...Sorry for the messy code...
View Replies !
Looping Mysql Selection
I hv got a bunch of email addresses in a mysql table. I need a php script that will loop the results of a SELECT and format them so I can put them in a php mail() function. I ¹m not too swift with php. would this be a simple script to code?
View Replies !
Displaying # Of Records In A Table
Can anyone throw me a link to some prefab code, or a tutorial on how I can get a page to display the number of records that meet a certain criteria. example: I have a page that stores information on audio FX. I'd like to include a feature that would let the users know how many items are in a particular section. Player (10) Items (5) Weapons (0) etc. All help appreciated,
View Replies !
Counting Records In A Table
Ok, I am trying to count the number of records in one of my tables. Seems simple. BUT! its not working. It returns a 2 no matter how many records are in there. Heres the code. <?php $sql = "SELECT count(*) from cam"; $result = mysql_query($sql); ?> I would think this would work. I have also tried mysql_num_rows, and max(), and sum()... a little help would be appreciated, and why is it returning a 2?
View Replies !
Delete Records From A Table
I have a table its called queue. It has a field called id. I want to delete all records in the table apart from the ones with id equals to 74 or 75 or 87. How do i do that?
View Replies !
Displaying Records In Table
I have a table that I want to display some records from my database. I have a specific spec I'd like the table to conform to, 3 cells wide. I can get the data into a cell. But my problem is, I'd like the table to have the 3 cells fill and then have the additional data create a new rows and continue on infinately.
View Replies !
How Do I Get The Total Records From A Table?
It also shows the total submissions. Right now, when you choose to view by a particular topic (for example, select a region - California) the total submissions only shows for those results (which right now is 1). I'd like to show the total results not just for California (which right now is 4). Code:
View Replies !
Delete Records From Table 1
I have a script that doesn't delete records from one database when it should, and now I have to do this myself because database is big and causes problems on the server. What I have is: TABLE 1, field auction TABLE 2, field id so I would like to delete all records from TABLE 1 where the value of the field auction doesn't match the value of the field id in TABLE 2. Can someone help me on this, please? I need to get this database cleaned.
View Replies !
Table Row Records For Editing
I have a repeat region of a table called userid. What i¹m trying to accomplish is being able to edit the record and then update it by clicking a submit button on the same line. I¹m doing it this way so the user can quickly update a number of records one at a time. I know I could do this by passing the userid info to a detail page but really want to do it the way described.
View Replies !
Showing Records In A Table
I am busy with the site of the company I work for. We have a section where al our partners are mentioned. At this moment this is a static part of the website that I want to make dynamically. This is the url of the static page and how it should look like: This is the url of the dynamic page I created but it doesn't work the way that I want: This is the php code I used: Code: <?php $i=0; echo "<tr>"; while (list($id, $vlag, $land, $bedrijf, $website, $email) = mysql_fetch_row($result)){ echo "<td><table>-Content with the data of the records-</table></td>"; if($i % 2 == 0) { echo "</tr><tr>";.
View Replies !
AJAX To Display New Records In A Table
Instead of refreshing the entire page to show the new fields in a table, I was wondering if it would be possible to use AJAX to display the new records in a table. For example: Messages are entered into the DB. I use PHP to create a table that displays the messages. Instead of refreshing the entire page to show the table with new messages, how can I use AJAX to show the new messages in the table without refreshing the entire page?
View Replies !
Counting The Number Of Records In Table
I want to count the number of records which apply to a repeating id field. (the user id remains the same, but their are several records which relate to the user. I want to know how many records in the table exist for a specified user id) Does anyone know a function for doing this?
View Replies !
Linking Multiple Records From Another Table
I'm not sure I'm even thinking about this the right way, but here goes: I have a table of users. Each one of these users may be associated with none, one, or many records in another table I call a todo table. table user = 'id', 'name', 'bla bla bla','todo_list' table todo = 'id','title','other info' Suppose user 'id=1253' has on his todo list items 756,241, and 672. I create a string 756,241,672 and store that string in the user's todo_list field. Then when I want to display the todo items I get the string with a query, bust it up into an array, iterate the array and query the todo table. I have a gut feeling I'm making it way more complicated than need be. But I can't think of any other way to do it
View Replies !
Table Join Count Records.
got my counting records script just the way I want it, now I've read all the posts on Joins, and read the manual and mysql.com.... but can't seem to get the right number to come out. I have two tables: table1 & table 2 table one has a field called ID and field two has a field called relID (this is the link between them) I want to count all of the records in table two where the relID is equal to the table 1 ID field. I thought this would do it, but the number it returns is wrong: PHP Code:
View Replies !
Copy Select Records To New Table
In the table Step I have multiple records for each given id. I want to save the current list of records for an id to a new Step_Old table so I can look back at what I had at a given point in time, since the records for an id in the Step table will change over time. Now the question... does anyone have a slick way to do this, or do I need to Select all the records I want to save and then save them one by one with a while loop into the Step_Old table?
View Replies !
Checking $_POST Against Records In Table
I have a table containg name, description, url which contains many records When I submit a new form, I want it to check the url fields in the table and check it against what I have posted. Therefore something like $check_table = function here to get all urls if($_POST['url'] == $check_table) { return false; } else { return true} However, how do I get all the urls and get it to check each one?
View Replies !
Insert Multiple Records In Table
I want to use a form to insert multiple records into a table. I have an book club where a person would rank a book (3 to 1) next to a particular book read for a particular month. 3 being the most favorite book read that month and 1 being least favorite. Below is the table the records would be inserted into. Key----Month--------Reader---------Rank-------Book 1-------January-------Jim--------------3----------Bible 2-------January---------Jim-------------2----------Koran 3-------January---------Jim-------------1-----------Torah How can I have a form where the reader sees only (and fills in) the rank and book text fields, and the Key, Month, and Reader fields are filled in behind the scenes with the default info when the form is submitted .
View Replies !
Delete Selected Records From Table.
Can anyone see why this connection doesn't work? It's suppose to delete selected records from my table. <?php if (isset($_POST['delete'])) // && isset($_POST['delcus'])) { foreach ($_POST['delcus'] as $val) { echo "$val"; $conn= mysql_connect( "localhost", "user", "password" ); $sql = mysql_select_db( "snow" ); $del = mysql_query("DELETE * FROM request WHERE qid =" .$val); //$rows = mysql_num_rows($del); $rs = mysql_query($conn, $sql, $del); if($rs) .........................
View Replies !
Checking If Any Records Exist In A Table
I've had a few problems with the mysql_fetch_array() string, and have worked out that it's because there are no records in the table. Does anyone know of a way of checking if there are any records, so that I can create an if statement?
View Replies !
How To Paginate Table To 1/2 Records Per Column
I am setting up a scrapbook page and we will be adding images all the time. I have a dynamic table to show the image, link and description but I want to break the columns to automatically show 1/2 the images in the first column, and the other 1/2 (or less if its an odd number of images) in the right column. Code:
View Replies !
Adding Multiple Records To A Table In One Form.
I have one form in a php page. In that form there are several rows, each with several input boxes. These rows represent individual products and their price. You may add as many products as you want by clicking a add product button and it will add another row using javascript. When you are finished adding your products you then click submit. For each product I would like it to insert an individual record in the products table. For example if you add 10 products, when you click submit it will add 10 records in the product table.
View Replies !
Select All The Records In A Table That Were Input Last Month
I am trying to select all the records in a table that were input last month, example:if month today is October select all record with month of September The query I am using is PHP Code: SELECT payments.*, members.* FROM payments, members WHERE payments.coupon_id = 餞C554360' AND payments.member_id = members.member_id AND payments.begin_date < NOW() - INTERVAL(1 MONTH) This display an error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'MONTH)' at line 1 I am not sure if my query is written correctly.
View Replies !
Query Problem: Counting Records From Another Table Without Using A Subquery
I'm working on a rather complex SQL query, which retrieves a list of clients that match certain criteria. One of the criteria I need to test is the number of business days that have elapsed since the client's enrollment. To facilitate this, I've created and populated a table called business_days - containing one record for every business day (non-weekends and non-holidays) for the next ten years. Using this, I can just count the number of business_days between two dates, like this: Code:
View Replies !
Moving Through Records In Table In A Single Record Page
I'm trying to create a updates pages that I can move either to the previous record or the next record within a recordset without having to return to the repeating list of records after each up date. Assuming I have done the recordset correctly, which I have and the update records command as well here is the code I'm trying to use: Code:
View Replies !
Create Dynamic Table With 3 Columns And Unknown Number Of Records?
I'm trying to create a table with only 3 columns, but the problem is I don't know how many records will populate the table so need it to automatically create <tr> and </tr> tags every 3 records. How best can I do this? At present the code below just lists every single record in one continuous row - but as I said, I want to only display 3 records per row. Code:
View Replies !
PHP -> MySQL Connection Trouble
I'm currently running the latest build of PHP4 on server1. However, I am running mySQL on server2. When I goto connect to mysql, I keep getting, "connection failed." I am thinking maybe something isn't setup right. For mySQL I am running mysqld and have it set up to work through port 3306. I've tried my hostname (what linux printed out0 and nothing works). I also have mySQL setup so you don't have to login to use it. PHP Code:
View Replies !
Trouble Installing PHP & MYSQL
I am experiencing problems when installing PHP5/MYSQL. I did ./configure --with-mysql=/usr/local/mysql --disable-libxml --with-zlib-dir=/home/frank/zlib-1.2.2 make make install The build process did not report any errors. Now, I cannot find libphp5.so, which I would like to register with Apache.
View Replies !
Trouble With MySQL Last_insert_id()
I am writting a script that takes data from a dynamically generated form, and posts into MySQL. I have written a function which checks what "type" of form entry it is (text, radio, check, etc.) by taking the POST array key (all of the form objects are numbered 1,2,3,4,n+) and comparing it against a DB table which tells me what type of data it is. IF the data is a name or email address, it gets placed in the visitor table, otherwise it gets placed in the answers table (because name/email are the only two constants, other form items are dynamic). The problem I'm running into is after I put the email/name into visitors, I try to get LAST_INSERT_ID() so then I can use in the 'uid' field in the answers table. (so I can do a table join later on, and as an identifier for who the data belongs to). $temp_array = mysql_fetch_array(mysql_query("select last_insert_id() from visitors")); $my_last_id = $temp_array['last_insert_id()']; //now you can display it, to test it echo $my_last_id; when I echo $my_last_id, I get something like "13132" - but there is only one row in the DB right now. So I am guessing the everything after the "1" is some sort of identifier... (visitors.id is set to Primary and Indexed) How do I get just the first part, so I can insert it into my other table?
View Replies !
Trouble Upadating A MySQL Row.
I can't figure out what I'm doing wrong. Does anyone see what I'm doing wrong with this update inquiry? All of the code works elsewhere except the update inquiry, I think that's where the problem is Code:
View Replies !
|